I've been trying to compile and run this example for javafx https://openjfx.io/openjfx-docs/#maven using Cygwin on Windows 10. It took awhile to get past the compile because my javafx is stored in C:\Program Files\javafx-sdk-13.0.1, the trouble being the space in the folder name. After trying lots of different things I finally found How to cd into a directory with space in the name?, which in a nutshell tells you to put quotes around your environment variable, "PATH_TO_FX".
Then I tried to run the example
$ java --module-path "PATH_TO_FX":mods -m hellofx/hellofx.HelloFX
Error occurred during initialization of boot layerjava.nio.file.InvalidPathException: Illegal char <:> at index 10: PATH_TO_FX:mods
So I thought the PATH_TO_FX was the problem but it turns out it is not.
$ java --module-path src:mods -m hellofx/hellofx.HelloFX
Error occurred during initialization of boot layerjava.nio.file.InvalidPathException: Illegal char <:> at index 3: src:mods
src is a valid directory and I still get the same problem. I think it is related to java being stored in a directory with spaces in it but I'm not sure.
#Ray_Write
isn't ; for Windows? Cygwin uses bash
This has nothing to do with the shell. The parsing of --module-path is handled entirely by the java interpreter, and according to the docs uses ; on Windows instead of :, presumably for congruence with Windows PATH separators.
Since this Java installation is a native Windows application and not one built for Cygwin, one should still use ;. So in effect, this has nothing to do with Cygwin.
For passing file paths to java you may also need to use cygpath to convert the path to its native Windows path.
You're right #Iguananaut, I do need a semi colon, to get my example to work I had to escape it.
java --module-path "$PATH_TO_FX"\;mods -m hellofx/hellofx.HelloFX
where PATH_TO_FX is in .bash_profile as
PATH_TO_FX="C:/Program Files/javafx-sdk-13.0.1/lib"
Related
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:\path\to\project\folder"
del ".\Confrontation\*" ".\Defines\*" ".\WorldBasics\*"
javac -d . ".\sources\Defines\*.java" ".\sources\WorldBasics\*.java" ".\sources\Confrontation\*.java"
pause
I tried running packageUpdater.bat from the Powershell terminal but then ran into this error:
C:\path\to\project\folder>javac -d . ".\sources\Confrontation*.java"
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <*> at index 18: .\sources\Defines*.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?
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 . ".\sources\Defines\*.java", ".\sources\WorldBasics\*.java", ".\sources\Confrontation\*.java"
This is my exact batch file. I have tried to convert it doing some research online and get an error
"Failed to execute child process "/home/pi/Desktop/TeachVal/TeachValLinuxShell" (No such file or directory)
echo off
cls
echo Running TeachVAL II...
set path=%path%;/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin
java -classpath comm.jar;Robot.jar;TeachVAL TeachVAL
cls
exit
This one is my attempt at translating.
#!/bin/bash
set +v
clear
echo "Running TeachVAL II..."
java -cp ".dir1;dir2;path/home/pi/Desktop/TeachVAL/comm.jar;
path/home/pi/Desktop/TeachVAL/Robot.jar;/home/pi/Desktop/TeachVAL/TeachVAL"
clear
exit
Welcome to Linux--life is good here, but there are a few things that work slightly differently, when compared to Windows.
One difference is that Windows uses semicolon (;) to separate entries in a list of paths, but Linux uses colons (:) for that purpose.
So, the Windows command:
java -classpath comm.jar;Robot.jar;TeachVAL TeachVAL
would correspond to this on Linux:
java -classpath comm.jar:Robot.jar:TeachVAL TeachVAL
In general, on Linux, semicolons are used to put multiple command lines into a single line. Once you've learned that, I think you can then understand why:
java -cp .dir1;/home/pi/Desktop/TeachVAL/TeachVAL
would be the same as:
java -cp .dir1
/home/pi/Desktop/TeachVAL/TeachVAL
That would run java (with no class to be executed) and then try to run "/home/pi/Desktop/TeachVAL/TeachVAL" which can't be found.
There are many more differences to learn; here's a page that will help you get started: http://tldp.org/LDP/abs/html/dosbatch.html
I made a java program. I used eclipse and it's a maven project. Now when i run the program from windows command prompt, then it's run fine. Here How i am running it from windows command prompt
D:\Personal Work\eclipse 32 Bit\workspace\....\target\classes>
java -cp ".;..\dependency-jars\*" com/softech/ls360/integration/BatchImport vintners
It is working fine. My dependency jar folder contains these jar files
Now when i run the same program from linux. Here how i am runnign it
root#Basit:/home/test/script/classes# java -cp .;../dependency-jars/*; com.s
oftech.ls360.integration.BatchImport vintners
Then i am getting the errors that
....
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
../dependency-jars/commons-collections-3.2.1.jar: line 1: PK??: command not found
../dependency-jars/commons-collections-3.2.1.jar: line 2:
../dependency-jars/commons-collections-3.2.1.jar: line 2: ?8: command not found
../dependency-jars/commons-collections-3.2.1.jar: line 3: syntax error near unex
pected token `)'
../dependency-jars/commons-collections-3.2.1.jar: line 3: ? ¶META-INF/MANIFE
ST.MF?VKo
_¦?z? ?%+v?N??!ö!P#
(
_?o.5?$
com.softech.ls360.integration.BatchImport: command not found
Why i am getting these errors. How can i run it on linux? Please help
Thanks
You need to use : instead of ; in classpath on linux envrionment. Assuming you have jars placed properly, then simply changing this:
java -cp .;../dependency-jars/*; com.s
oftech.ls360.integration.BatchImport vintners
to
java -cp .:../dependency-jars/*: com.s
oftech.ls360.integration.BatchImport vintners
should work
Learn more about setting classpath here: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
The semicolon is making Bash invoke the java command with no classpath, then tries to execute each jar directly, seeking a shebang where none exists. This leads to JAR headers being printed as part of the error.
Use : to separate jars instead of semicolons on Linux.
You need to make two changes:
First, the classpath separator is ':' rather than ';' on Linux
Second, you'll need to escape the wildcard character with a backslash ('\'), or the shell will expand it and mess things up. You want Java to see the '*' character and expand it itself. The Windows shell doesn't expand wildcards on command lines, so this isn't a problem there.
So, all together, you'll want to use something like
java -cp .:../dependency-jars/\*: com.softech.ls360.integration.BatchImport vintners
You should use : instead of ; as a sperator of the class path files.
I'm trying to write a BASH script to get my Java program to run(common issue, right?). I just can't quite get it to work. After many edits, here's how I am trying to set the classpath and then execute the program:
java -classpath 'cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar:/cygdrive
/c/Projects/common/lib/jdom-1.0.jar:/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar:
/cygdrive/c/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar:/cygdrive/c/Projects
/Freereader/bin/"' com.free.syndication.SQLfeeder
Sorry the the jumble, I'm just trying to do everything at once. It tells me that the main class of my program cannot be found!((
Any ideas?
Java classpath uses semicolon as the token separator.
Use backticks instead of single quotes
Try:
java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar;/cygdrive
/c/Projects/common/lib/jdom-1.0.jar;/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar;
/cygdrive/c/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar;/cygdrive/c/Projects
/Freereader/bin/"` com.free.syndication.SQLfeeder
In bash, the syntax $(command) is clearer than the backticks `command`
cygpath has a -p option to convert PATH-like values (as opposed to single path names) between Windows and Unix, i.e.
cygpath -pu 'C:\Users\me\bin;C:\Users\me\project\bin' will give /cygdrive/c/Users/me/bin:/cygdrive/c/Users/me/project/bin
cygpath -pw will do the same in the opposite direction
Note that cygpath -u "/cygdrive/c" (as in your question) will not change anything, since the directory name is already in the desired (Unix) syntax. You could omit it just as well.
So, the command becomes:
CP="C:/Projects/common/lib/rome-1.0.jar;C:/Projects/common/lib/jdom-1.0.jar;C:/Projects/common/lib/jsoup-1.6.1.jar;
C:/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar;C:/Projects
/Freereader/bin"
# for a Windows Java binary:
java -classpath "$(cygpath -pw "$CP")" com.free.syndication.SQLfeeder
# for a Unix Java binary:
java -classpath "$(cygpath -pu "$CP")" com.free.syndication.SQLfeeder
Alternatively, you can start with a Unix-style class path, but the commands stay the same. In either case, you can of course omit the call to cygpath if the class path is already in the desired syntax.
Don't you need backticks?
java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar:/cygdrive
/c/Projects/common/lib/jdom-1.0.jar:/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar:
/cygdrive/c/Projects/common/lib/mysql-connector-java-5.1.18-bin.jar:/cygdrive/c/Projects
/Freereader/bin/"` com.free.syndication.SQLfeeder
You must use backticks ( '`' symbol ) or $(cmd) bash sytax to substitute cmd output
java do not understand unix- (cygwin-) style paths, only windows-style.
And at last first link in google answers you question
The main cause of the issue is NOT the backtic but instead the issue of colon versus semi-colon. Since in cygwin, the java running there is for DOS/Windows environment it is expecting ';' as the path separator.
While backtic does help, the main root cause of the issue must be emphasize the difference between ':' and ';' when Java is in Unix or in Windows environment.
I'm complete Linux newbie, but still want to provide a simple way for Linux users to start my Java program.
Therefore I want to create a shellscript.
I can't test my script so I'll have to ask here if this is working correctly:
#!/bin/bash
java -cp "bin";"extres/junit.jar" data.ProgramOne
exit 0
Your mistake is in path delimiter. It is ; on Windows and : on Linux.
Moreover you should not wrap each classpath fragment with "". On unix you can escape spaces and other forbidden characters using \. So, I'd re-write the java execution line as:
java -cp bin:extres/junit.jar data.ProgramOne
This will run when you are executing script from your app directory where you have subdirectory bin and extres.
try this:
java -cp "bin:extres/junit.jar" data.ProgramOne
Java under Unixes uses : as the separator in the classpath, so you'd need (the quotes are not necessary):
#!/bin/bash
java -cp bin:extres/junit.jar data.ProgramOne