Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

include jar in an executable jar

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a small program that does some FTP work with the help of Apache's commons-net-1.2.2.jar file and so every time I execute the Java program, I have to use the classpath flag to reference that JAR file. I would like to package up my Java program into an executable JAR file, and if possible, I'd like to include the Commons Net JAR file inside of my "main" JAR file so that there would be only one simple thing to call to run it (because I would like to hand this off to less-savvy colleagues who need to use it to automate some tasks). Is there any way to do this? If so, how do you make sure that the classes in the JAR file know how to find the classes in the other JAR file? Thanks...
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html#download

As far as I can tell, that doesn't work for "nested" jar files, though, sorry...
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could unpack the contents of the JAR you want to include, and then just add them to your JAR.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we had the debate some weeks ago:
jar-in-jar talk
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the replies. I'm trying to just JAR up my program and include the classpath to the other JAR file in the manifest so that all someone has to do is drop both of them into the same directory. However, I'm running into this problem:

C:\code\uploadsdownloads>java -jar UploadsDownloads.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPConnectionClosedException

The commons-net-1.2.2.jar containing all that FTP code is in the same directory as the JAR I'm trying to run, and the manifest looks like this:

Manifest-Version: 1.0
Main-Class: UploadsDownloads
Class-Path: ./commons-net-1.2.2.jar

What am I doing wrong? I also tried it with this:

Class-Path: commons-net-1.2.2.jar


 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, guess what...I got it!

It was a problem in my manifest.

The Class-Path line needed to have a newline after it--the last line in the manifest has to have a newline marker at the end. :roll:

Oh well, at least it works!

 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic