Help with JAR and JNLP

Hey guys –

I’ve got a project that uses LWJGL, and I keep trying to create an executable JAR file (so I can make a JNLP), but executing the file always fails. I’ve got the manifest with the main class specified, and I’ve even tried to have Eclipse do it automatically with the same results. I think the problem is that while working in Eclipse, it automatically includes the workspace in my class path, and therefore the LWJGL JARs and dylib’s are all included in the path. When I make a JAR, however, it seems even to ignore everything within the JAR as part of its class path (I have the JARs and the dylibs inside the folder for the JAR file I am building).

So how can I specify the class path correctly so that it includes everything within its own directory? I tried just a slash, but that does nothing.


Main-Class: Agent00PK
Class-Path: /


The above was one attempt at a manifest, another was without the “Class-Path” part. I also tried creating a containing folder called “Agent00PK” and making that the class path, but that didn’t work either. I seem never able to get the class path working at all. Do I need to specify containing folders as well?

Help, please!
Thanks.

PS – Even though I’ve been programming in Java for 5 years, I have simply dealt with not knowing how to do this by putting the JARs into my Java Extensions folder. I’d love to finally learn how to get this working.

Ah… I couldn’t find the error reports, but I finally located them (the new OS X puts them in subfolders).


Apr 13 19:58:40 computer [0x0-0x4d24d2].com.apple.JarLauncher[10557]: Exception in thread "main" 
Apr 13 19:58:40 computer [0x0-0x4d24d2].com.apple.JarLauncher[10557]: java.lang.NoClassDefFoundError: Agent00PK

You have to put the relative locations to all your dependencies in the Class-Path section. And by the way, don’t put things in the default package:):


Main-Class: <your-package>.Agent00PK
Class-Path: ./lib/lwjgl.jar ./lib/jinput.jar <etc.>

But be aware that you cannot specify native code locations for an executable jar. The only way I know of is to deploy the .dll files beside the main jar, and this does only work for windows. Since you are not after local deployment but webstart, this probably doesn’t matter.

You might also want to take a look at this: http://www.cokeandcode.com/webstarthowto

:slight_smile: I started with Kev’s tutorial but couldn’t get the classpath part to work when making my JAR file, so I couldn’t get anywhere beyond that.

If I can’t specify native code locations, how would I ever do that without Webstart? I also have a question about packages. I do have some packaged stuff in my program (and non-packaged stuff), so when creating my initial JAR, does it automatically search through all containing folders for any .class files, or do I need to specify every single folder within the command line? Like if I have:

net/stuffa/.class
net/stuffb/
.class

etc.

If I just have it include the net folder will it get everything within?

I am afraid you have to write a starter script for that…

Don’t know since I am using ant to create my jars. I am afraid you have to read the jar documentation http://java.sun.com/j2se/1.4.2/docs/tooldocs/tools.html :stuck_out_tongue:

Okay, well I got Eclipse to make a JAR that at least executes if I put LWJGL in my Java Extensions, which is fine for now. The real issue at this moment is modifiability. In order to export everything as a JNLP, it’s got to be in a JAR. That means my Levels folder does as well, and my program includes a Level Editor that is supposed to allow you create your own levels. If you’re working using directories, that’s not a problem at all because you can just make a new .lvl file in the Levels folder, but when I have to bundle the Levels folder that creates issues. Similarly, save files pose a similar problem.

As such, do I need to have two places to look for levels, one in the JAR, and one on the local disk? It just seems way too difficult for the user to do much, then. They especially can’t modify the level files I created and put in the game, which I was hoping they could do.

Is there any way to make a JNLP have directories as well? I’m thinking maybe I’ll have my actual program load levels from a web site, but that’s still pretty annoying to have to do.

Resource files for java webstart applications should be in a jar to make the application selfcontained and can be run unsigned. If you sign your app (and you might have to anyway because of lwjgl natives), you could just create a folder on the local disk (preferable using FileSystemView.getFileSystemView().getDefaultDirectory()+"/" which resolves to “<your app name>” on windows and “<user.home>/” on linux) and unpack the levels on the first application start.

Another note on putting something into the java extensions folder: don’t do it! Chances are that you are breaking java webstart applications that use lwjgl as well. And more importent - you can’t test if your jnlp is correct as long as you have lwjgl there, because the files from the ext folder are always loaded regardless of the jnlp settings.

Yeah, I know not to put stuff in extensions, but if it’s the only way to see if my JAR works, I do it temporarily. Don’t worry, I just took them out as soon as I finished. :slight_smile:

Okay, I’ve almost got it. :smiley:

Just one last problem. In Kev’s example, his nativelib’s are JAR files. I figured this was just in his case, so I substituted those with the library files.

ex:

becomes

I got an error saying that my .so was a corrupted JAR file… because it’s not a JAR file. How do I get it to read in the libraries instead of a JAR? Or do I need to package all the libraries into a JAR and use that?

The natives have to be packaged in jars. Just put all .so/.dll/.jnilib files in a jar for the appropriate platform and reference the jar.

Okay, cool, I’ve done so. Now I’m waiting for the JAER signer, because apparently I have to sign all of LWJGL’s stuff as well. Annoying!

[EDIT]
Woohoo! We have success!

Boy-o did that take a long time. :o

Seems like you don’t have to… There is an jnlp extension available:


    <extension name="lwjgl" href="http://lwjgl.org/jnlp/extension.php" />

I just looked into the jnlps linked on the lwjgl demo page :slight_smile:


<!-- JNLP File for LWJGL Demos --> 
<jnlp 
  spec="1.0+" 
  codebase="http://lwjgl.org/jnlp/" 
  href="lwjgl-demo.php/test.input.TestControllers"> 
  <information> 
    <title>LWJGL Demo [test.input.TestControllers]</title> 
    <vendor>LWJGL</vendor> 
    <homepage href="http://lwjgl.org/"/> 
    <description>Demonstration of LWJGL</description> 
    <description kind="short">Technology Preview</description> 
    <icon kind="splash" href="logo.png" />
    <offline-allowed/> 
  </information> 
  <resources> 
    <j2se version="1.4+"/> 
		<jar href="lwjgl_test.jar"/>
    <jar href="lwjgl_media.jar"/>
    <extension name="lwjgl" href="http://lwjgl.org/jnlp/extension.php" />
  </resources> 
  <application-desc main-class="org.lwjgl.test.input.TestControllers">
    </application-desc>
</jnlp>

Well that’s good to know.

Thanks for all the help, cylab, it’s been, well, very helpful.