wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to build a project referencing jars in other folders? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to build a project referencing jars in other folders?" Watch "How to build a project referencing jars in other folders?" New topic
Author

How to build a project referencing jars in other folders?

Igor Santos
Greenhorn

Joined: Apr 02, 2012
Posts: 10

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

Joined: May 26, 2003
Posts: 30586
    
154



There's no classpath set when you call java. Which means Java doesn't know where to look for the jars.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Igor Santos
Greenhorn

Joined: Apr 02, 2012
Posts: 10

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

Joined: May 14, 2008
Posts: 5836
    
    7

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.


JBoss In Action
 
GeeCON Prague 2014
 
subject: How to build a project referencing jars in other folders?