Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How Include Imported Classes in JAR?  RSS feed

 
Kevin Brennan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize if this is a simple question, but I cannot find an answer that I understand. Breifly, I have a program with a single class that imports 6 other libraries. When I make complie it and then make .jar file, it does not include those imports. How do I ensure that all dependencies are compiled and include in thr archive?

Thank you.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What other libraries (actually "packages" is the correct terminology in Java) are you importing? If they are in the java.* or javax.* hierarchy, you do not need to package them in your JAR file. These packages come with the Java Runtime Environment (JRE) that the user will need to download in order to run your program anyway.

If your program depends on other, third-party libraries, the typical solution is to include the library's JAR file in the CLASSPATH when your own JAR file is installed rather than packaging the library's classes in your JAR file directly. However, I won't go into this in further detail until you answer my original question. If I need to, I'll explain more later.

Layne
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Eclipse, you can get a plugin called FatJar (I think it's called that) that will do all that for you. Try that, and examine the jar file it produces. Then you can do it by hand, or use Ant if you want.
[ July 14, 2005: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you might find help.
 
Kevin Brennan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Layne,
Thanks for your reply -- I think that my question wes based on my misinterpreting an error message that I received when trying to run an applet that I wrote. I have since figured it out, and of course, you are right about these being in the JRE.

Barry,
Thank you for your note about the eclipse utility and the JAR docs -- they cleared up my question even more thoroughly.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!