Problem
Anyone know why this command works perfectly in Windows but throws a ClassNotFoundException on Linux? ui. Main
java -cp ".;lib/*" game.ui.Main -Xms64m -Xmx128m
My folder structure is as follows: game/ – Class files lib/ – Jars lib/ – Jars lib/ – Jars lib/ – Jar
Java 6 is the most recent version.
Asked by sproketboy
Solution #1
The classpath syntax varies depending on the operating system. According to Wikipedia:
Answered by peter.murray.rust
Solution #2
Replace the semi-colon with a colon.
Platform-dependent, the CLASSPATH separator is the same as the character given by java.io.File.pathSeparatorChar.
Answered by Mikel
Solution #3
Windows:
java -cp file.jar;dir/* my.app.ClassName;java -cp file.jar;java -cp file.jar;java -cp file.
Linux:
file.jar:dir/* my.app.ClassName java -cp
Remind:
Answered by Wender
Solution #4
When employing classpaths in scripts that are intended to execute on both Windows (i.e. cygwin) and Linux, paths are also significant. When I do this, I include a classpath function like this. With the ‘-w’ option, the ‘cygpath’ tool transforms routes to Windows-style paths. As an example, “/home/user/lib/this.jar” would be transformed to “C:Cygwinhomeuserlibthis.jar” in this case.
#!/bin/bash
function add_java_classpath() {
local LOCAL1=$1
if [ "$OSTYPE" == cygwin ]; then
LOCAL1="$(cygpath -C ANSI -w $LOCAL1)"
fi
if [ -z "$JAVA_CLASSPATH" ]; then
JAVA_CLASSPATH="$LOCAL1"
elif [ "$OSTYPE" != cygwin ]; then
JAVA_CLASSPATH="${JAVA_CLASSPATH}:$LOCAL1"
else
JAVA_CLASSPATH="${JAVA_CLASSPATH};$LOCAL1"
fi
}
add_java_classpath /home/user/lib/this.jar
add_java_classpath /usr/local/lib/that/that.jar
java -cp "${JAVA_CLASSPATH}" package.Main $@
Answered by pinkston00
Post is based on https://stackoverflow.com/questions/4528438/classpath-does-not-work-under-linux