문제

Currently I am starting my Slick 2D application via this batch file-

java -Djava.library.path=lib -Xms512m -Xmx512m -jar myapp.jar %1

Where lib is the folder that contains the LWJGL/Slick libraries and myapp.jar is my application.

Although this is easy and effective I want to be able not to have to run a script all the time and actually create a java .jar to do this.

So my question is, how would I 'convert' this batch script into Java code?

도움이 되었습니까?

해결책

Any -D command line arguments can be set via java.lang.System.setProperty. But the memory parameters can't be set from inside a JVM as far as I know. Therefore, there is no way to do what you want.

Instead you could generate e.g. a Windows executable with JSmooth. Such a wrapper should be able to set all JVM arguments. But in the end the situation is similar to the script. You have some kind of wrapper.

다른 팁

Why you would want Java code for this is beyond me as that creates exactly the same problem for you again – namely running your startup Java program that then starts another Java program; you'd be at the same point as before.

However, you don't need to create a JAR in any case. You can stuff all your compiled .class files somewhere and set that as the classpath. A JAR is little more than a main class and a classpath bundled into one.

So instead of your invocation above you can then use

java ... -cp %USERPROFILE%\Java\MyApp myapp.gui.Main

or something like that. Set the classpath with -cp and give the main class on the command line instead of the JAR.

The easiest way is to use a program like JarSplice (http://ninjacave.com/jarsplice)

You can easily create a jar executable with all needed lib. it works very well

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top