Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
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  
  How to use a jar from another jar  (Read 1891 times)
0 Members and 1 Guest are viewing this topic.
Offline bert

Junior Member




Miles of road and miles of code


« Posted 2006-07-21 20:58:16 »

I'm working on a game that takes joystick input. I like to package my software into jar files, it's easier to download that way. However, I still need a batch file to run it that looks like this:
java -cp JInput.jar -jar MyGame.jar
Is there any way that I can embed the JInput in my jar?

w00t, i'm winning
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2006-07-21 21:14:16 »

a) fat jars... that is... extract em (first libs, then yours) and compress the whole thing.
b) putting the jar into the other jar and doing some classloader voodoo (xjar)
c) well, you can always use webstart Wink

弾幕 ☆ @mahonnaiseblog
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2006-07-22 05:12:50 »

There is a classpath entry in the jar manifest.
Any jar you name there will become part of the classpath when you run that jar using java -jar

This is what the SGS in the SDK does.

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline purpleguitar

Junior Member





« Reply #3 - Posted 2006-07-23 12:35:22 »

There is a classpath entry in the jar manifest.
Any jar you name there will become part of the classpath when you run that jar using java -jar

Last I checked, this was not a robust solution since one cannot use variable expansion in the manifest.  I haven't tried it in cases where all of the jars in are the same folder, and maybe that works okay, but I don't think it works when the jars are spread about the user's system.  Hence I've been forced to write launchers to run my programs, since the locations of libraries (specifically tools.jar) changes from system to system.  Of course, if anyone has a better idea, I'm open to it Wink
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #4 - Posted 2006-07-23 12:47:13 »

Quote
since the locations of libraries (specifically tools.jar) changes from system to system.

This is even less robust because you don't know if a user has the JDK.
You could write a classloader which adds jars from a directory to the classpath, if you need something like that.

Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2006-07-24 04:39:52 »

There is a classpath entry in the jar manifest.
Any jar you name there will become part of the classpath when you run that jar using java -jar

Last I checked, this was not a robust solution since one cannot use variable expansion in the manifest.  I it Wink


*shrug*

Depends on what you want to use it for.  In the SGS SDK we assume you are running from the root directory and havent cfhanged the inatalled layout.

If you dont match those criteria, you just have to write your own CLASSPATH.  I dont see a problem with this-- the manifest entries are just a convenience, they don't keep you from doing things the hard way if you want to.

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 purpleguitar

Junior Member





« Reply #6 - Posted 2006-07-24 13:17:32 »

Quote
since the locations of libraries (specifically tools.jar) changes from system to system.

This is even less robust because you don't know if a user has the JDK.
(snip)

Agreed, and that's why I had to write a launcher for the program:  need to find the JDK install, its tools.jar, add it to a classpath, then launch the app.  I should have clarified the context:  my team (at the time) was hoping to run the application as a single executable jar.  However, the tools.jar is system-dependent, so it seemed foolish to attempt to repackage our tool for every single java installation; this would lead to a maintenance nightmare, if it would even work at all.  Java WebStart allows you to run an app with multiple jars instead of one executable jar; however, I don't think you can get to the user's JDK install automagically that way either.  Hence, we're stuck with a custom launcher that does the work of hunting down the installation.

I didn't mean to imply that manifest classpaths are bad; just that they're not robust.  They work perfectly for many applications, but they are useless for any case where you do not know the directory structure of the client ahead of time, and they break if the client makes changes to that structure.
Offline CommanderKeith
« Reply #7 - Posted 2006-08-08 06:04:52 »

I'm working on a game that takes joystick input. I like to package my software into jar files, it's easier to download that way. However, I still need a batch file to run it that looks like this:
java -cp JInput.jar -jar MyGame.jar
Is there any way that I can embed the JInput in my jar?

There's a Request For Enhancement about that here, I just voted for it.  Put a vote in too  Smiley

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648386

Offline tigeba

Junior Member





« Reply #8 - Posted 2006-08-22 03:52:25 »

I have used this before, fairly simple solution.

http://one-jar.sourceforge.net/

Basically does allthe classloader voodoo for you, and allows you to bundle everything in a single jar
Offline CommanderKeith
« Reply #9 - Posted 2006-08-22 05:09:55 »

Thanks for that.  I tried and failed to find this out but maybe you could tell me:

Does its classpath-voodoo work with Web Start? (so a Web Start jnlp file can point to that single jar alone & Web Start will work even though Web Start uses its own special class loader?)

Keith

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 (26 views)
2014-08-19 09:29:53

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

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

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

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

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

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

BurntPizza (30 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!