Pretty straightforward question. Can it be done without the use of Ants or Maven? (And by that, I mean the command line tool specifically)
Please notice that I don't want to create an uberjar, I just want the archived unit to "know" where its external dependencies are.
You can make it through META-INF/MANIFEST.MF
. You can add other jars to the classpath like this:
Manifest-Version: 1.0
Main-Class: org.domain.MyMainClass
Class-Path: lib/slf4j-log4j12-1.5.8.jar lib/slf4j-api-1.5.8.jar
I believe, that it works only if you define Main-Class
and start your application like this:
java -jar my-app.jar
Also notice, that classpath paths are relative to the main jar. So in my example directory structure should look like this:
Presuming you're talking about a command line invocation of javac
, what you're talking about is "can I provide libraries as arguments to javac to fulfill requirements during compilation".
Top entry for man javac
says
-classpath classpath Sets the user class path, overriding the user class path in the CLASSPATH environment variable. If neither CLASSPATH or -class- path is specified, the user class path consists of the current directory. See Setting the Class Path for more details.
Effectively I suspect you just need to say
javac -classpath path/to/library1.jar Main.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With