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,
posted 13 years ago
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.:
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.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
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.
posted 13 years ago
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"?
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database