Wednesday, August 3, 2011

java, external jars and classpath

1 comment:

  1. java, external jars and classpath


    Very 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

    ReplyDelete