File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can useful files or other JARs appear in JAR? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can useful files or other JARs appear in JAR?" Watch "Can useful files or other JARs appear in JAR?" New topic
Author

Can useful files or other JARs appear in JAR?

William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
Hi ranchers,
When i wanna use another file or jar, can i put them all in my jar, and can run the jar alone with nothing else?

Thank you.


Java is better and better, yet bitter and bitter.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Why do you want to do it?
You can do it by unzip it and drop classes into yours. Then re-jar them into one jar file.

can run the jar alone with nothing else?

may be or may be not. If the third party classes in the jar depends on other jar files, then you still need other jar files to run.
[ October 31, 2006: Message edited by: wise owen ]
William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
And what about a file,
when i wirte a class that uses another file, say a .txt file, and put all the manifest, .txt, .class all in a jar. But i cannot use it. Must the .txt be put outside the jar?

Thank you
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18707
    
  40

Originally posted by William Yan:
And what about a file,
when i wirte a class that uses another file, say a .txt file, and put all the manifest, .txt, .class all in a jar. But i cannot use it. Must the .txt be put outside the jar?

Thank you


Yes, you may place other types of files in a jar file. However, if you do, you will need the classloader to get the file since the File class only deal with files in the filesystem.

See the getResourceAsStream() method of the java.lang.Class class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can useful files or other JARs appear in JAR?