Requirements:
- Command-line only, i.e. no IDE’s
- Do not want to use
classpathargument - OS: OS X v10.6.8
Steps:
- Setup CLASSPATH environment variable:
export CLASSPATH="/path-jar-files-are-at/*" - Compile my java app:
javac MyApp.java - Launch my java app:
java MyApp
After launching, the following error appears:
Exception in thread "main" java.lang.NoClassDefFoundError: MyApp
Caused by: java.lang.ClassNotFoundException: MyApp
Using classpath argument doesn’t have this problem
- Compile my java app:
javac -classpath /path-jar-files-are-at/* MyApp.java - Launch my java app:
java -classpath /path-jar-files-are-at/* MyApp
Any ideas?
The CLASSPATH should not contain the trailing “/*” – that is not going to give you a valid classpath. The shell is expanding the /* and separating the list with whitespace/newlines – rather than the “:” character.
If you still really want it to work this (dynamic) way, try something like this: