I'm developing my first java application using Eclipse. I've recently needed to adjust the amount of memory allocated by passing -Xmx256M to the JVM. The application is currently package up as a runnable jar and installed using the NSIS.
I'm having a problem passing arguments to the jar file once its installed. What is the common practice for doing this? Here is what I'm currently doing in my nsi file:
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" "$SYSDIR\javaw.exe" "-Xmx256M -jar $INSTDIR\Foo.jar"
This results in the following being created as the shortcut Target on windows:
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar C:\Program Files\Foo\Foo.jar
Unfortunately this does not work due to the space in C:\Program Files, If I change the link created manually to include quotes all is well:
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\Program Files\Foo\Foo.jar"
UPDATE: Ordering of -jar and -Xmx256M swapped. The issue remains the same however. The spaces in the path to the jar file are causing an issue. I think I either need to find a way of adding quotes into the command, as shown when I manually change the target, or change my approach completely!
NSIS strings can be quoted with single quotes, double quotes, or the backward single quote. You can also escape with $\ ($\" etc)
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" '"$SYSDIR\javaw.exe"' '-Xmx256M -jar "$INSTDIR\Foo.jar"'
Have you tried keeping the quotes in but escaping the path separators?
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\\Program Files\\Foo\\Foo.jar"
Pretty sure you should put quotes around "C:\WINDOWS\system32\javaw.exe" even though there are no spaces.
Related
I installed JDK on windows 10, 64bit, followed the documentation instructions.. CMD does not recognize javadoc command. What I tried:
-copied the path of the "bin" folder from Java and in cmd I wrote the command:
set path = "full_path_to_java_sdk_bin_folder"
I saw this on youtube and it worked for the guy, my cmd still did not recognize javadoc command -I set the PATH in system variables from control panel->system->advanced->environment variables and made sure that there are is no other bin folder...
Didn't find any other tips online...
The usual approach for Java development is to set a JAVA_HOME environment variable, and use that to update the PATH (for one thing, it makes it much easier to support multiple versions of Java). Also of note is that Windows puts the quotes oddly on the command line (oddly compared to every other platform that is) and if your path contains spaces you need to quote it correctly. Like,
set "JAVA_HOME=<full_path_to_jdk>"
set "PATH=%JAVA_HOME%\bin;%PATH%"
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"
I was able to successfully create a .exe file from an executable jar. From Launch4j I can test the wrapper, and the output on the log is what I expect. However if I try to run the exe from the command line or from Windows Explorer, nothing happens. No error, no output to the console as expected. The program is also supposed to edit a text file which does happen when I run the jar using a batch file, but not when I run the exe. This is all on the same computer so I doubt it is a problem with the JRE. I have searched StackOverflow extensively but found nothing that helps with this situation. I did find this post with a similar problem: Launch4J executable not executing as expected but nobody actually answered the question. Thank you in advance for helping
I found the issue. Under Header, I had to switch the Header type from GUI to Console. After that I was able to run the exe.
You may be accepting something as a command line argument which may be throwing an error like in my case .
For my case, it was the tick on "Signle Instance" tab: Allow only a single instance of the application.
Although I had killed the process, for some unknown reason the exe had been recognized as alive. Thus, a reboot of the PC is recommended.
These are the things I had to do for it to work on Windows 10:
First, make sure the executable JAR you created actually executes. I could never got the JAR to execute by double-clicking. Instead, I created a .bat file where I added the java -jar command-line instruction to execute the jar, including the VM arguments. For example, to execute foo.jar, the .bat file should contain java -jar --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml foo.jar. Once you get the JAR to execute without errors (pay attention to the command prompt window), then your JAR is ready. Then, do the following from the Launch4J app:
Create FX_HOME environment variable. Make sure it points to the lib folder of the downloaded Java FX distribution is located.*
Set JAVA_HOME environment variable.*
Make sure JAVA_HOME is the first entry on the Path variable. Verify by opening a command prompt and typing where java and hitting the ENTER key.
Under Header, make sure "GUI" is selected.
Under JRE, set Bundled JRE paths to %JAVA_HOME%.
Under VM Option, enter --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml
*If any of the paths contain spaces, make sure they are in quotes when you create the environment variable. For example: C:\Program Files\Java 17\bin, should be in quotes. This is because the command-line parameters are space-delimited and "Program Files" contains a space, fooling the command-line interpreter to think Program is the end of one parameter and Files is the beginning of another. By putting in quotes, the interpreter now knows the space is part of that single parameter that represents the path.
I have a java app that needs two jar files to run. craftbukkit.jar is the one that holds the main function, and commons-dbcp-1.4.jar is what I need to allow mysql pooling. I am having issues getting the CLASSPATH to behave properly.
Can someone help point out what I am doing wrong here?
java -Xincgc -Xmx1G -cp "craftbukkit.jar;commons-dbcp-1.4.jar" org.bukkit.craftbukkit.Main nogui
Can't seem to find the Main when i do this, and without the commonds-dbcp-1.4.jar it fails to load properly.
Use java -Xincgc -Xmx1G -cp craftbukkit.jar:commons-dbcp-1.4.jar org.bukkit.craftbukkit.Main nogui
No quotes, and use :, not ;.
Add the line
Class-Path: commons-dbcp-1.4.jar
to Manifest.mf and make sure you leave an empty line at the end of the file assuming that commons-dbcp-1.4.jar is in the same directory.
Check your "path separator". Wich OS you are running on?
For Windows, path separator is ";". On Linux you should use ":"
Windows:
java -Xincgc -Xmx1G -cp "craftbukkit.jar;commons-dbcp-1.4.jar" org.bukkit.craftbukkit.Main nogui
Linux:
java -Xincgc -Xmx1G -cp "craftbukkit.jar:commons-dbcp-1.4.jar" org.bukkit.craftbukkit.Main nogui
Ok, so this is actually quite a long story, but i'll try and keep it pretty short. So I'm trying to get the WebOS SDK working on Windows using Cygwin. Well, it wasn't working. It kept complaining that i was using a 32 bit version of java instead of 64 bit. the explenation for that problem is pretty easy to figure out. my PATH variable was set wrong and was pointing to my 32 bit installation of Java. Simple solution YOU'D THINK. apparantly not. for some reason, despite my best efforts, i cannot get the 64 bit version of java written into the PATH variable. The problem:
Cygwin doesn't like spaces in the Path variable, even though the path variable is littered with spaces, it won't accept it when i add my own space. After a lot of googling, i've found multiple accurances of this problem, and multiple solutions. but none of them seem to work. i always get exactly the same error:
bash: /usr/local/bin:/usr/bin:/cygdrive/c/Program: No such file or directory
The error is pretty self explanetary, basically its not reading anything past the first space, and i have no such directory as C:/Program so it spits out an error, my question is how do i get it to except a space, because changing the name of the directory is not an option, too many things depend on it. heres what i've tried so far:
$PATH=$PATH:C:\PROGRA~1\Java\jre6
$PATH=$PATH:"'pwd'" (while in java directory)
$PATH=$PATH:/cygdrive/c/Program Files/Java/jre6/bin (hay, i had to try)
$PATH=$PATH:/cygdrive/c/"Program Files"/Java/jre6/bin
$PATH=$PATH:/cygdrive/c/Program\ Files/Java/jre6/bin (escape character was rumored to work
$PATH=$PATH:'/cygdrive/c/Program Files/Java/jre6/bin'
$PATH=$PATH:"`/cygdrive/c/Program Files/Java/jre6/bin`"
and i think that was it, if anyone knows how to actually do it properly (or improperly but working for all i care) it would be greatly appreciated
Thanks
--
Chris
You also have the option of using the cygpath tool to help. Cygpath can be used to convert from a Window's path to a Unix path, but that doesn't directly handle spaces, so you need to do a two step process, first eliminate the spaces by converting to a DOS (short) path name, then convert to a Unix style path:
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files\Java\jre6\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\PDK\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\SDK\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\SDK\bin\novacom")):${PATH}
The end result will be something like (short names may differ slightly):
/cygdrive/c/PROGRA~3/HPWEBO~1/SDK/bin/novacom:/cygdrive/c/PROGRA~3/HPWEBO~1/SDK/bin:/cygdrive/c/PROGRA~3/HPWEBO~1/PDK/bin:/cygdrive/c/PROGRA~1/Java/jre6/bin:....other path elements....
One thing to keep in mind when using this, cygpath generates an error if the provided path actually does not exist because it can not create the short path for a non-existent path.
What is nice about this approach is that if you set Windows environment variables (like for example JAVA_HOME) then you can use that environment variable in the convert operation inside the .bash_profile, since all Windows environment variables are visible when the profile is being loaded. So if you had in the Windows environment
JAVA_HOME=C:\Program Files\Java\jre
then the cygpath command can be
$(cygpath -u $(cygpath -m -s "${JAVA_HOME}\bin"))
which means you only ever need to update via the Windows settings if the java install changes.
In .bash_profile:
PATH=/cygdrive/c/Program\ Files/Java/jre6/bin/:${PATH}
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/PDK/bin
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/SDK/bin
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/SDK/bin/novacom
Adds the paths to your .bash_profile and both java and the webOS SDK tools should be available.