Resolve CLASSPATH with two JARs - java

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

Related

Wildcard in Jar name

I am running one jdk command in window batch file as:
javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -jar C:\Users\sampleJAR\myProj-1.0.0.jar
But, every 2 weeks we will have new version coming up and old jar will be replaced by new jar automatically so I was thinking to use wildcard with something like:
javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -jar C:\Users\sampleJAR\myProj-*.jar
I referred lots of articles online which suggested to use *, surround jar name with "" when using *,... None of them worked.
I believe that the articles you are looking at are in reference to the classpath option wildcard expansion.
The -jar option doesn't do this wildcard expansion and expects a filename without any wildcards.
You could try specifying the classpath with the wildcard and then putting the class name that you want to run at the end of the command. Hopefully like:
javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -cp "C:\Users\sampleJAR\*" com.my.classname

set Java classpath in a cross platform way

After reading this answer
Setting multiple jars in java classpath
I'm still puzzled. Is there an only way to specify a classpath so it would run in Linux and Windows?
For example, I'm running these 2 commands and after '*' wildcard in Linux, i need to put ':', but in Windows - ';'.
java -mx1300m -cp "*;" edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat "wordsAndTags,typedDependencies,penn" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz %1
java -mx500m -cp "$scriptdir/*:" edu.stanford.nlp.parser.lexparser.LexicalizedParser \
-outputFormat "typedDependencies" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz $*
Thanks.
There isn't such a thing. You should make a separate ".sh" and ".bat" file, or you could put all program dependencies inside your ".jar" file and turn it into an executable file. You would only need the jar file in any OS as you have a compliant jvm.

Java multiple classepath with :classes directive

Should be kind of trivial but say I have two jar files in libA.jar and libB.jar in directory ./lib
java -cp ./lib/*:classes com.whatever.Start config.file
Runs smooth.
Now say those files are in distinct directories
/home/lib/libA.jar
./lib/libB.jar
I cannot start it with:
// this doesn't work
java -cp /home/lib/libA.jar;./lib/libB.jar:classes com.whatever.Start config.file
What am I missing?
Thank you.
Under Linux you should use a ':' as path seperator, not semicolon:
java -cp /home/lib/libA.jar:./lib/libB.jar:classes com.whatever.Start config.file
Try this:
java -classpath /home/lib/libA.jar:./lib/libB.jar:classes com.whatever.Start config.file

Convert Windows Java Commands to Linux Java Commands?

I have the following text in a BAT files so I java program in windows. I was wondering how you can do this in linux.
File 1:
"C:\Program Files (x86)\Java\jdk1.6.0_23\bin\javac.exe" -sourcepath src -classpath bin;deps\jml-1.0b3-full.jar;deps\mail.jar -d bin src/*.java
File 2:
"C:\Program Files (x86)\Java\jdk1.6.0_23\bin\java.exe" -Xmx1536m -classpath bin;deps\jml-1.0b3-full.jar;deps\mail.jar HelloWorld
Id really appreciate it if someone would convert those to linux commands.
Thanks :D
get rid of the quotations - spaces in linux are not a usual practice, so the quotes are not needed
change ; to : as classpath separator
change slashes to /
make the file .sh
that should be it.
The options to java and javac are the same on all platforms. The only things that will change are the file path, for eg. deps\mail.jar might become deps/mail.jar; and the classpath separator, : (colon) instead of ; (semicolon).
check if java SDK (java-1.6.0-openjdk-devel or Sun) exists and in the PATH
which javac
Next put the same options
javac -sourcepath ..

Passing arguments to java vm from NSIS script

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.

Categories

Resources