• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to build a project referencing jars in other folders?

 
Greenhorn
Posts: 10
Eclipse IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author & internet detective
Posts: 42165
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic