• Post Reply Bookmark Topic Watch Topic
  • New Topic

run jarfile  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�m trying to use a batch file to run man java application. I have a jarfile that includes other jarfiles.
It works fine to run the main method but when I try to connect to a class in another jarfile I get java.lang.NoClassDefFoundError.
This works when I run it on my application server.
What have I missed?
Do you have to declare all jarfiles in the classpath?
This is my bat-file:
set classpath = =%classpath%;C:\workspace\MicroPatent\microPatent.jar;C:\workspace\MicroPatent\bns.jar;
cd C:\workspace\MicroPatent
java micropatent.obj.MicroPatent

Pleas help�
/Jenny
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jenny,
Im pretty certain that you cannot include Jar files within a Jar file. You either have to unzip the Jars you wish to include and zip them as part of your own or setup your classpath to reference the Jars elsewhere. This does seem like a pain in the ass but there are a number of good reasons for this - none of which I think of off the top of my head. I suggest you do a search on the Java Developer Connection as there are a number of posts on this topic already.
Im guessing that your application works correctly when you run it on your application server because the application server includes in its classpath references to the Jar files you wrapped within your application JAR.
Hope this helps somewhat,
John
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im pretty certain that you cannot include Jar files within a Jar file.
That is, it's certainly possible to create jar files with other jar files nested inside them, but the JVM won't be able to access anything from the inner jars as part of the classpath. You might be able to make a custom classloader which can access them, but that seems like a lot more work than I'd want to do for this. Your main options are:
  • Unjar the outer jar and list each inner jar in the classpath
  • Unjar the outer jar and put each inner jar in jre/lib/ext
  • Unjar the outer jar, unjar each inner jar, then jar all the contents into a single jar, and put that one jar in the classpath.

  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!