Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.jar file won't run without external library

 
Joe Niksa
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a program that parses HTML files to read some text within the files and then creates new files with filenames containing the new string information extracted from each. Anyway, after cleaning and building the project the .jar program won't run without being in a folder which includes the lib folder containing the jsoup library (jsoup is the library that parses HTML). Is there a way I can somehow include it the main .jar file so it will be more of a standalone program? I want to be able to deploy just one file.

Any help is appreciated.
Thanks
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The standard class loader won't load class files from an embedded jar but there are class loaders out there that will and I believe IDE's like Eclipse provide a class loader which supports embedded jars.
 
Joe Niksa
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, thanks. I wrote it in Netbeans because that's what I've used since I started school but I hear Eclipse is great too. I will have to check it out.
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 2 ways of doing this
1) You can include the name of the jars that your jar depends on in the Manifest file. Those jars should be in the folder specified in the Manifest.

2) Unpack your jar, and all the dependent jars. Merge them together into one jar. This is called an Uber jar.. and uber is calling it mildly. It does create a huge jar


If you are using maven, you can use the Maven assembly plugin to do the first way, and Maven shade plugin to do it the second way
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote it in Netbeans because that's what I've used since I started school but I hear Eclipse is great too. I will have to check it out.

I did a quick search and it looks like Netbeans can create a monolithic Uber jar for you. Check out this article http://capturevision.wordpress.com/2008/06/28/how-to-include-the-processing-jars-in-your-netbeans-jar/
 
Joe Niksa
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After adding the following code to the build.xml file... It works! I just changed "MyJarName" to the title of my class file. Yes, it does make the final JAR bigger; I went from 20KB to almost 1MB, but this is definitely what I was looking for. Thanks everyone for your input and help!



Found it here:
Source
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic