java, external jars and classpathVery simple mini howto compile and run a “jarred” Java application that uses an external “jarred” library.Fact: you have a program program.java that uses an external library extlibrary.jarFirst: compile it with -cp (that is classpath) and the full path of the external library:$ javac -cp /full/path/extlibrary.jar program.javaCreate a manifest file manifest.mf with this content:Manifest-Version: 1.0Created-By: youMain-Class: programClass-path: /full/path/extlibrary.jarCreate the jar file with:$ jar cmf manifest.mf pogram.jar program.classRun it:$ java -jar program.jar
java, external jars and classpath
ReplyDeleteVery simple mini howto compile and run a “jarred” Java application that uses an external “jarred” library.
Fact: you have a program program.java that uses an external library extlibrary.jar
First: compile it with -cp (that is classpath) and the full path of the external library:
$ javac -cp /full/path/extlibrary.jar program.java
Create a manifest file manifest.mf with this content:
Manifest-Version: 1.0
Created-By: you
Main-Class: program
Class-path: /full/path/extlibrary.jar
Create the jar file with:
$ jar cmf manifest.mf pogram.jar program.class
Run it:
$ java -jar program.jar