Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to build a project referencing jars in other folders?

 
Igor Santos
Greenhorn
Posts: 10
Eclipse IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the situation: I got 10 projects that need 2 libs to run: Jsoup (A html parser API), and Utils (Framework developed by me).
I want to update that Utils project from time to time, and not have to re-compile 10 projects everytime that happens..
So I started using Ant, and after a great amount of time figured this much out:



Problem is... When I try to run it, I get the following error:



RoboBean is a class inside the referenced package, and when I open the jar, I can see that it's in its right place.
I tried exporting the Runnable Jar with Eclipse specifying "Copy required libraries into a sub-folder next to the generated JAR",
thought it'll build 10 folders for 10 projects, which is not what I'm aiming for here...

After doing it, I compared both MANIFEST.MF's... To my surprise, here's what differs:


This is the one generated by Eclipse


And this is the one generated by my build.xml


I already searched all over JavaRanch and StackOverflow and found nothing that could explain / clarify anything...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


There's no classpath set when you call java. Which means Java doesn't know where to look for the jars.
 
Igor Santos
Greenhorn
Posts: 10
Eclipse IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that was the problem, than I'd have no hard time to execute the jar manually via command line, which I do. I think it's something related to the path where the jars are placed, but I still can't make it work
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you ask Eclipse to create an runnable JAR, it places all dependent JARs into a lib folder within the JAR and adds classes to the JAR that implement a classloader so that the embedded JARS can be found and their classes loaded. That is why the one from Eclipse runs correctly.

The JAR built by Ant uses relative paths to access the JARs file on the hard drive - if you are not running the app from the correct location, the relative paths will be wrong. It looks like the paths are relative to your project's base directory, which will be fine as long as the JAR is in that same directory. But it looks like the JAR is placed elsewhere, so you need to either use absolute directories, or change the relative directories, or relocate the files.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic