2

I am writing a plugin which will be loaded by another application of course, and I want to use JSoup for some web pulling. However, when I bundle the jar and run the application, I get: NoClassDefFoundError: org/jsoup/Jsoup I have jsoup in my classpath just as all my other dependencies are. Jsoup however, will not be on the hosts machine. I have also tried bundling the project jar with jsoup in a lib folder within the jar itself and referencing it from there, and I still had no luck. How can I get Jsoup loaded on the JVM in my project? Edit: I can run Jsoup fine in eclipse, just not when it is bundled in a jar

Edit2: Why is it that I can have some dependencies work without having it loaded on the hosts machine such as google's gag project? why is it that I need jsoup loaded on the hosts machine? I know I have a misunderstanding of how the JVM works :/

0

1 Answer 1

1

Jsoup should be on the host machine if your code is going to use it. Why not place it with your own jar file, and set your jar's manifest so that it knows where to find the Jsoup jars? This question has nothing to do with Jsoup per se and all to do with using external libraries contained in jar files, but as it happens I use Jsoup in several of my final projects, and they work just great when used as most jar files should be used, as libraries contained on the host machine.


Edit You state:

That's what I tried to do. I have decompiled the jar and Jsoup is bundled within in jar format. However, I have never messed with the manifest before. How would I set the manifest to look for it in the projects jar?

If the Jsoup jar file is in the same directory as your jar file, simply refer to it directly in the manifest's class-path:

Manifest-Version: 1.0 Class-Path: jsoup-1.6.1.jar Main-Class: mvc.main.SimpleImgScraperMain 

The details on use of the Class-Path property within manifest files can be found here: Adding Classes to the JAR File's Classpath

Sign up to request clarification or add additional context in comments.

3 Comments

That's what I tried to do. I have decompiled the jar and Jsoup is bundled within in jar format. However, I have never messed with the manifest before. How would I set the manifest to look for it in the projects jar?
Well I don't want to have to force the plugin users to get Jsoup just so that coding will be easier for me. I was hoping that I could use Jsoup's functionality without having it on the hosts machine and rather having it in my projects jar instead. Is this possible? I am sorry for my lack of understanding of how the JVM loads sources.
@Weasel: why not? They have to obtain copies of your program, so might as well bundle all together. I don't think that it matters so much with Jsoup, but some libraries will require that their jar files be unaltered and used as is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.