Problem with the jar launcher for windows (.bat)

Hi again (and again),

Sorry to bother, but I have one more problem trying to distribute a single Jar file.

I did everything according to the tutorial here and managed to create a HelloApp.jar through OneJar.

I also created a HelloApp.bat file to lauch the jar but when I execute it, windows open a command and shows an error very briefly. I managed to take a screenshot. Apparently I m missing the lwjgl, but I dont understand where and why.

Could anyone help me out with that?

here s the screenshot:



Edit your.bat file and make sure the you have


somewhere after the java command.

For example:

java -jar -Xmx256m -Djava.library.path=<path-to-jme>libnatives HelloApp.jar


Just to elaborate a bit, I am not aware of any nice way of using native libraries (like lwjgl.dll) bundled in a JAR. I once heard of a quick and dirty way of doing this that first extracts the dll from the file (you can do that in the batch file as well, for instance) and then calling the line (similar to what roslamir is mentioning):

jar x HelloApp.jar lib/lwjgl.dll
java -jar -Xmx256m -Djava.library.path=. HelloApp.jar

or whatever the actual path to the DLL is in the JAR.

roslamir =>

I m not sure the problem comes from the bat file…  :expressionless: I just wanted to try something out and I lauched the HelloApp.jar through the windows command prompt like this:

java -jar HelloApp.jar

The prompt then answered a different error:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at ...
at ...

This means that there's a problem that has nothing to do with the .bat file right (and possibly another error within the .bat file)?

Any idea what it means? For info, my application comes from the tutorial as well (moving around the 3d box). I just copy-pasted this file TutorialGuide/ , as said in the tuto.

Thank you anyways...

duenez =>

Thank you for elaborating, but I m not sure I understood what you meant. See, I m a very deep noob and windows command prompt is somewhat obscure to me... ;)

In the .bat file you set the maximum heap size: -Xmx 256m but in the command line you didn’t. So the JVM uses its default value which is (I think) only 64m. That’s why you got the message: 

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

Try changing the heap size to say 1GB (-Xmx 1024m) and see what happens.

java -Xmx 1024m -jar HelloApp.jar

roslamir said:

java -Xmx 1024m -jar HelloApp.jar

Hmmmm... this would give him the same problem with lwjgl.dll not found.

In short, I don't think it is possible to simply boundle everything in a JAR and run it. You do need command line arguments to set up the heap size (memory) and library path (to the DLL). You can hide most of this from the end user by giving them two files, the JAR and the BAT. The BAT file would contain code to extract the DLL and then run the JAR with the required heap space.

I guess if you upload your JAR I could try looking at it and giving you a definite BAT file that would do all of the above.

Hey Roslamir and duenez,

Thank you so much for your help!!!  :slight_smile:


java -Xmx 1024m -jar HelloApp.jar

in the command line doesnt work. I gives me an error message that says

Invalid Maximum heap size: -Xmx
Could not create the Java virtual machine.

I also tried with 256m, but got the same message.  :oops:

duenez =>

I dont really care about having one single executable file. Like everyone who ended up here (I guess), I would like to be able to write a full featured 3d program (game... not really, but it s similar). I m still far from that but I hope with a few months learning java & jME, I could get there...

So my objective, in the end, is to create an executable installer (I heard it wasnt too harsh) that places my program's files onto a definite location (like program files on windows), so that it looks nice and tidy, like a professional software that would be installed in "All programs" in the windows Start menu... I guess you got that ;) but its to say that ending up with a bat and a jar file is just fine :D

I dont really underestand the thing about bat files and I dont understand who is looking for what library path, since I remember very well having linked my project to the lib/native/ directory that actually contains a lwjgl.dll file among other. If you have a tutorial that explains that, it d be great!

Anyways, here s my HelloApp.jar

Put this in a .bat file (I called it run.bat  ;))

jar vxf HelloApp.jar binlib
java -Xmx512m -Djava.library.path=binlib -jar HelloApp.jar

I tested it on Linux and it works. It should work on Windows all the same.

Hey  :wink:

Thank you for your help. It works perfectly!

But it s very strange… I was waiting for your answer, and I did one more test. I went through the whole tutorial once again from scratch and I must have made some kind of mistake somewhere in the process because now it works with just this line

java -jar -Xmx256m HelloApp.jar

sorry that you went through all this with me, but it wasnt useless cause I learned a lot of stuff! :wink:

Is there any "solved" button in this forum?

Is there any "solved" button in this forum?

No, there isn't.
But it would be fine if you modify the Title of you first post and add a [solved] or something.
.:emp...imm0|82:. said:

Is there any "solved" button in this forum?

No, there isn't.
But it would be fine if you modify the Title of you first post and add a [solved] or something.
There is now :) Hoping there's a better solution for it in SMF 2.0 though, because this one is very restricted...