Reputation: 11
Okay, so I've got the following file tree:
<appfolder>
- MyApp.jar
- lib/
- log.jar
- someother.jar
- someother.jar
- someother2.jar
- config.properties
- otherfiles.extension
I've tried dozens of way to launch this application. MyApp contains the following
MANIFEST.MF:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.7.0_06-b24 (Oracle Corporation)
Main-Class: myapp.Main
Class-Path: MyApp.jar lib/*
If I invoke java -jar MyApp.jar it always says none of the classes in lib/log.jar could be loaded.
Here is a part of the combinations I've tried:
- *.jar lib/*
- *.jar lib/*.jar
- *.jar ./lib/*.jar
- ./*.jar lib/*.jar
- *.jar ./lib/*.jar
- tbc
NOTHING worked. Java always tells me that it could not find the classes inside the lib/log.jar
My next attempt was to specify the classpath via the command line.
java -cp "MyApp.jar:lib/*" myapp.Main
But even that doesn't work. In this case Java says it could not find the myapp.Main class.
I guess I'm doing something completely wrong since nothing of the methods I've found worked. If I put the classes from lib/log.jar into myApp.jar and start it it'll work. But that can't be the solution.
Any ideas?
Edit: I don't want to name every single lib jar. I just want the ClassLoader to search the ClassPath for the needed classes. I've seen this so many times.
Upvotes: 1
Views: 2491
Reputation: 11
I had the same problem.
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, then you must include a dot (.) in the new settings.
Upvotes: 1
Reputation: 121759
For Linux, you should be able to do something like this:
java -cp MyApp.jar:lib:someotherjar.jar myapp.Main
You can (optionally!) use "-jar" for a .jar that contains your "main", or you can add any combination of paths and jar files (.jar file with qualified path names) to your classpath.
Here's the Java documentation
And here's a somewhat better explanation
Upvotes: 2
Reputation: 8881
add lib directory to your classpath via system variables , or via
SET CLASSPATH=%CLASSPATH%;MYAPP/LIB;.
and then do a java -jar MyApp.jar
Upvotes: 0