Search code examples
javajavac

javac *.java Windows command line error : * as illegal chacter


So i tried to compile my java project (9 classes 3 files), and feeling no need for complicated work i tried the standard 'javac *.java' from the folder above the root of project. (and alter from the root itself). Javac throws and parsing error on command line claiming Illegal char < * > at index 0: *.java. options chosen don't seem to matter since 1) i tried a few, 2) it crashes on parsing line of file.

While i do know a work around by just writing down all file paths to all of my .java files, i find this annoying, and potentially problematic in the future. Also i found nothing on the issue what so ever so it may either something very weird or very stupid on my side.

C:\Users\MarcinS\IdeaProjects\Beta2\WynikiZawodow\src\com>javac *.java
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char < * > at index 0: *.java
        at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
        at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
        at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
        at java.base/java.nio.file.Paths.get(Paths.java:84)
        at jdk.compiler/com.sun.tools.javac.main.Option$37.process(Option.java:700)
        at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1098)
        at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:401)
        at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:367)
        at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:193)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:222)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:162)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

Solution

  • As you said in your answer to my question in the comments, your classes are in its own package. In order to compile this, your shell's current directory must be the directory where your packages (i.e. subdirectories) start. This has the effect that you start your compiler with no java files in it, so the shell can't resolve *.java into the list of java files in that directory, *.java will be passed to the Java compiler that in turn tries to make sense out of that filename.

    It's not javac's fault because filename resolving is the shell's job. Since you already have a workaround in place you can continue using that or switch to an IDE which comes with additional features that will make your life easier (at least in termns of programming Java ;-)