GeeCON Prague 2014*
The moose likes IDEs, Version Control and other tools and the fly likes eclipse: libraries used in project are not found in the exported jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "eclipse: libraries used in project are not found in the exported jar" Watch "eclipse: libraries used in project are not found in the exported jar" New topic
Author

eclipse: libraries used in project are not found in the exported jar

Simone Cittadini
Greenhorn

Joined: Apr 28, 2006
Posts: 13
I have such an eclipse project :

- the project

- my common libraries
-- lib

lib is a directory with 3 jars in it (mysql-db, jfig and log4j)
these jars are added to "my common libraries" with 'Java Build Path'->Libraries->Add Jars

in "the project" 'Java Build Path'->Projects->'Required Projects on the build path' I've added "my common libraries", with no access rules

The project works when run from the IDE, but if I try to export a jar :

simone@newbrand:~> java -jar hcc2mag06.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/igfay/jfig/JFigException
at it.retireti.hcc.linee.FacadeLinee.<init>(FacadeLinee.java:35)
at it.retireti.hcc.gui.HPanelTerminazioni.<init>(HPanelTerminazioni.java:45)
at it.retireti.hcc.gui.HControlCenterFrame.init(HControlCenterFrame.java:40)
at it.retireti.hcc.gui.HControlCenterFrame.<init>(HControlCenterFrame.java:29)
at it.retireti.hcc.gui.HControlCenterGUI.<init>(HControlCenterGUI.java:13)
at it.retireti.hcc.gui.HControlCenterGUI.main(HControlCenterGUI.java:34)


SDENG ! quite frustrating ... what I'm missing ? what's the correct way to add libraries / export jars ?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
When you export a jar in Eclipse, only the compiled class files are included. In fact, Java doesn't have a standard mechanism to have a jar inside a jar be referenced by a classloader.

So the common thing to do is to manually add the jar dependencies to the classpath when starting the program outside of eclipse.

Or you could use http://one-jar.sourceforge.net/


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Simone Cittadini
Greenhorn

Joined: Apr 28, 2006
Posts: 13
I've also found http://fjep.sourceforge.net/ which integrates with eclipse
 
GeeCON Prague 2014
 
subject: eclipse: libraries used in project are not found in the exported jar