File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes .jar file won't run without external library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ".jar file won Watch ".jar file won New topic
Author

.jar file won't run without external library

Joe Niksa
Greenhorn

Joined: Feb 24, 2012
Posts: 12
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

Joined: Aug 07, 2007
Posts: 2173
    
  47
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

Joined: Feb 24, 2012
Posts: 12
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
Bartender

Joined: Jan 17, 2008
Posts: 2273
    
  28

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

Joined: Aug 07, 2007
Posts: 2173
    
  47
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

Joined: Feb 24, 2012
Posts: 12
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
 
subject: .jar file won't run without external library
 
Similar Threads
packing java file into JAr file
Changing the JAR file contents in my lib folder
Copying files
Accessing text files outside eclipse
Putting un-jarred config files on the manifest classpath