• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAR File Class Loader Blues

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok the subject doesn't really tell my problem exactly:

I am creating a program under JBuilder/Windows XP that I wish to run under Java 1.3. It uses a couple of EJB's from JBoss and Jakarta POI.

The ejb's are in a jar file nmmg.jar. In my classpath are:
nmmg.jar (contains the EJB's)
jbossall-client.jar
poixxx.jar
log4j.jar (seems jboss needs it)

If I compile the code (only 3 java files) using the 1.3 jdk under linux without making a jar file, it runs just fine:

$ java com/nmmg/eft/Program
<nice happy program output here>

If I create an Application Jar in JBuilder and try to run it, I get NoClassDefFoundError: javax/ejb/FinderException. This class is in my path (jar -tf jbossall-client.jar finds javax/ejb/FinderException). The manifest has nothing except version and Main-Class properly pointing to my class.

$ java -jar Program.jar
<NoClassDefFoundError>

If I create HelloWorld.jar, containing no dependencies, it runs just fine.

I've added everything but the kitchen sink to classpath. I've tried reordering classpath (dunno why - that's how desparate I was).

I've about run out of ideas.

Thanks for any ideas,

Mark
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After wasting a full day, wouldn't you know I'd find the answer *after* I got desparate enough to post a question. And that on my first post in about a year.

The answer is that, when you run from java -jar, all class paths other than the jar are ignored. So, I either need to add those dependencies to the manifest (bad, since they may vary from machine to machine) or run it w/o -jar but with the jar file added to the classpath, e.g.:

$ java -cp myfile.jar ther.jar com.xyz.MyApp

Mark
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not common to have dependencies that vary from machine to machine, but if you do, consider creating a ClassLoader that reads all the jar files in a specific directory or directories (ones that you can set in a .properties file)

That way, you can place the dependent jars in the specified directory.
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never had a problem putting dependancies in the manifest file. Other than getting them to work. For the classpath in the manifest file the lines cannot be to long, they must end in a \n, each line after the first line must start with a space, and there must a an empty line at the end.
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies. I'm at a new place that has quite a bit of web ejb stuff and asked for some utility apps and nobody else has ever deployed a standalone java app . I had always bundled needed .class files in my jars so as to not have any dependencies, but this time the jar ended up being huge. Combine that with getting used to doing everything in a container and a few things that never quite settled in your brain.

Since we already have properties around for stuff, that idea makes sense for us, so thanks. A good excuse to learn how to roll a classloader, even though it "works" now by running with the -cp from a shell script.

Did I say "thanks"?

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic