• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can useful files or other JARs appear in JAR?

 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic