Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

powershell - Getting a java.nio.file.InvalidPathException: Illegal char <*> while trying to compile java files

I am a beginner in Java. I started a tentative OOP project for which I am creating a bunch of different packages. Since my project is git tracked, I am trying to recompile everything before syncing. To simplify the process of compiling through my VS Code Powershell, I created a small windows batch script called packageUpdater.bat that deletes all previously compiled java packages and then should recompile all indexed java sources:

cd "C:pathoprojectfolder"
del ".Confrontation*" ".Defines*" ".WorldBasics*"
javac -d . ".sourcesDefines*.java" ".sourcesWorldBasics*.java" ".sourcesConfrontation*.java"
pause

I tried running packageUpdater.bat from the Powershell terminal but then ran into this error:

C:pathoprojectfolder>javac -d . ".sourcesConfrontation*.java"

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <*> at index 18: .sourcesDefines*.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.Path.of(Path.java:147) at java.base/java.nio.file.Paths.get(Paths.java:69) at jdk.compiler/com.sun.tools.javac.main.Option$37.process(Option.java:693) at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1088) at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:381) 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:229) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170) at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57) at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

The deletion part executes properly and I get to validate each delete ops. And I know the paths to the files are correct because when I run that same javac command in the Powershell directly, it runs without any issue. I am new to using batch files as well so I am wondering if I am doing something wrong. Can anyone help?

question from:https://stackoverflow.com/questions/65560125/getting-a-java-nio-file-invalidpathexception-illegal-char-while-trying-to-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to the comments I received on the question it appears that the issue comes from the cmd not preprocessing my command to provide all the files that match the wildcard name, as I expected it would. Thus java crashed because it does not support wildcard references.

A couple solutions were suggested but I went with replacing the batch script packageUpdater.bat by the Powershell script packageUpdater.ps1. I also altered the script to remove the change directory operation because now I can run it directly from the project directory in vs code powershell terminal. I also replaced the UNIX command aliases from my previous script by the correct Powershell commands:

Remove-Item ".Confrontation*",".Defines*",".WorldBasics*"
javac -d . ".sourcesDefines*.java", ".sourcesWorldBasics*.java", ".sourcesConfrontation*.java"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...