Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  listing resources in jar files...  (Read 2582 times)
0 Members and 1 Guest are viewing this topic.
Offline Aramaz

Junior Member




Java Games Rock!


« Posted 2005-09-16 06:17:34 »

I'm seeing blah talking about putting games on webstart everywhere. As of now I've put all images and soundfiles  in their own directories...

My noobish question is, how do I get a list of the things that are in a jar file... so I can use the list to go grab resources...

I could  probably find this on my own... but as I have very limited time, I want to focus on developing the game... so I thought there must be a lot of users having done this, that can point me in the right direction without having to look anything up... :-)...

thanx for your time!

Play XSW: www.xsw.se
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2005-09-16 20:04:32 »

jar -tvf my_jar_file_here

or just rename the file to have a .ZIP extension and use your favorite archiving tool.

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2005-09-16 22:15:05 »

or, if you're trying to do it programmatically, have a look at the ClassPath code on JGF:

http://javagamesfactory.org/views/view-sourcesnippet?id=1

...which finds all the classes in a JAR, amongst other things. IIRC the bits that read from a JAR file and find out whats in it are fairly obvious. They use standard API's - you could just search the javadocs instead.

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2005-09-18 05:53:18 »

jar -tvf my_jar_file_here

or just rename the file to have a .ZIP extension and use your favorite archiving tool.

or if you use winrar, just add the .jar to the lsit of extensions it knwos for zip files Smiley

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #4 - Posted 2005-09-19 00:16:54 »

or if you use winrar, just add the .jar to the lsit of extensions it knwos for zip files Smiley

Do you really want to encourage people to break the concept of the executable .JAR file, on purpose?  Smiley

I would suggest not changing the extension association... enough archiving programs break that on their own.  Just open your archiving utility and drag and drop the JAR file on to it.  That should do the trick.  On windows you might also be able to right-click and choose "Open with..."

A double-click on an executable JAR file should launch the Java program it contains.

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2005-09-19 07:04:04 »

On windows you might also be able to right-click and choose "Open with..."

A double-click on an executable JAR file should launch the Java program it contains.

Exactly what I do all the time. XP "remembers" your open-with history, and makes a custom sub-menu automatically offering you the previously used open-withs for that particular filetype as a shortcut.

No problem.

malloc will be first against the wall when the revolution comes...
Offline Aramaz

Junior Member




Java Games Rock!


« Reply #6 - Posted 2005-09-19 07:07:25 »

Well... I was looking at doing it programatically... so I'll take a look at blah's link... thanx!

Actually... I might just produce a listing from the stuff unpacked... and put the listing in the jar file as well. Might be the easiest way to go... (admittedly not very flexible... but it'll suit my needs...)

thanx for suggestion's tho... Smiley


...good idea though with open with... I'll start using that myself too Smiley

Play XSW: www.xsw.se
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #7 - Posted 2005-09-27 07:52:31 »

or, if you're trying to do it programmatically, have a look at the ClassPath code on JGF:

http://javagamesfactory.org/views/view-sourcesnippet?id=1

...which finds all the classes in a JAR, amongst other things. IIRC the bits that read from a JAR file and find out whats in it are fairly obvious. They use standard API's - you could just search the javadocs instead.

Shouldnt that be ClassLocator.java instead of ClassLocater.java? Smiley

弾幕 ☆ @mahonnaiseblog
Offline Mr EEK

Senior Newbie





« Reply #8 - Posted 2005-09-27 10:22:56 »

Aramaz,

The java.util.zip package can help you with this. Here's a very simple example:


        ZipFile zipFile = new ZipFile(new File("c:/myjar.jar"));
        Enumeration entries = zipFile.entries();
        while (entries.hasMoreElements())
        {
            System.err.println(entries.nextElement().toString());
        }


Hope this helps.
Offline Aramaz

Junior Member




Java Games Rock!


« Reply #9 - Posted 2005-09-28 18:12:39 »

Oh, thanx Mr EEK... that was exactly what I was after!

Play XSW: www.xsw.se
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Tomas

Junior Member




Agency9


« Reply #10 - Posted 2005-10-06 09:43:16 »

Is it possible to get a list of files in a directory inside a .jar ?

Let say that I have the following in a .jar:
/shaders/phong.cg
/shaders/bump.cg

To load a specific shader I do:
getClass().getResourceAsStream("/shaders/phong.cg");


But If I want to know the avilable resources in lets say "/shader/".

If I try get ClassLoader.getResources("shaders")
I just get the url to the different .jars containg a shader folder and not
a list of the files in the folder

If I do a System.getProperty( "java.class.path" ) I get jars assigned to the classpath.
In the best of worls my problmes would end here.... but the .jars assigned in
a webstart .jnlp file doesn't seem to be on the path.

In the .jnlp I do:

<resources>
<jar href="data.jar"/>
</resources>


How to solve the problem ?
// Tomas  Huh




CTO Agency9
Offline Mr EEK

Senior Newbie





« Reply #11 - Posted 2005-10-06 12:38:42 »

Tomas, it's not a nice solution but you could include a file in your JAR that contains the list of shaders.

Then:

getClass().getResourceAsStream("/shaders/list.txt");

and go through the file reading the listed shader file names, and read each using another getResourceAsStream call.

Not too elegant, but it would work (as long as you keep the list file up-to-date  Wink)
Offline Tomas

Junior Member




Agency9


« Reply #12 - Posted 2005-10-13 14:17:34 »

Seems like a horrible work around Wink  There must be a better way ....

// Tomas

CTO Agency9
Offline Tomas

Junior Member




Agency9


« Reply #13 - Posted 2005-10-17 10:18:57 »

By the complete silence on this topic I guess that there is no solution...  Sad

CTO Agency9
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #14 - Posted 2005-10-17 11:45:28 »

Could you not convert the URL to a File, then use the File's abilities to list stuff?

Pseudocode:
1  
2  
3  
4  
5  
6  
7  
URL t = getClass().getResource("/shaders");
File f = new File(t.getAbsolutePath());
if (f.isDirectory()) {
  for (int i = 0; i < f.numberOfChildren;i++) {
    Sysout(f.getChild(i);
  }
}

?

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #15 - Posted 2005-10-17 11:51:56 »

That'd probably only work if the URL actually was a physical file reference. The URL type id dependent on the classloader in place.

Kev

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #16 - Posted 2005-10-17 11:55:13 »

Seems like a horrible work around Wink  There must be a better way ....

// Tomas

I thought the programmatic way(s) had already been referenced above and there was no need to comment further?

malloc will be first against the wall when the revolution comes...
Offline Tomas

Junior Member




Agency9


« Reply #17 - Posted 2005-10-17 12:42:15 »

Yes but  this problem still remains, how do I get my hands on the .jars when using webstart.

See my earlier post:
Quote
If I do a System.getProperty( "java.class.path" ) I get jars assigned to the classpath.
In the best of worls my problmes would end here.... but the .jars assigned in
a webstart .jnlp file doesn't seem to be on the path.

In the .jnlp I do:

<resources>
<jar href="data.jar"/>
</resources>

// Tomas

CTO Agency9
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!