Wednesday, November 23, 2016

combine two jar files

There are two jar files in current directory:

  • jetty-all-uber.jar
  • hello-world-0.1-SNAPSHOT.jar


1. make a temp directory
mkdir tmp
2. cd tmp
    jar -xf ../hello-world-0.1-SNAPSHOT.jar
    jar -xf ../jetty-all-uber.jar
3. cd ..
    jar -cvf my.jar -C tmp .

The above commands create a combined jar file my.jar in current directory.


Test HelloWorld with:
fos@ubuntu:~/dev/jetty-demo$ java -cp my.jar org.example.HelloWorld

If you want to make your jar file as an application, please refer to:
Running JAR-Packaged Software

with which you can run the HelloWorld with:
fos@ubuntu:~/dev/jetty-demo$ java -jar my.jar

No comments: