Search code examples
javaeclipsejvmexecutable-jarjvm-arguments

Application runs in Eclipse, exported jar crashes


Inside my Swing application I have to parse xml documents. Sometimes they have more than 190 MB. It caused crashes in applications because no enough memory could be allocated. Inside Eclipse I changed JVM arguments so it can allocate up to 2gb of memory using this argument:

-Xmx2048m

When I start it like this there are no problems. But when I exported it to runnable jar file app keeps crashing. I changed the JVM memory settings for my Windows environment

ControlPanel->Programms->Java->Java-View

It crashes at the following line:

 doc = docBuilder.parse(inputSource);

But no exception is thrown. For this reason I think my JVM crashes. What could be the problem?


Solution

  • Create a BAT and double-click that instead of your JAR.

    MyApp.bat:

    @ echo off
    java -Xmx2048m -jar MyJar.jar
    

    Or better yet, wrap the JAR in an EXE that also sets the JVM parameters. A tool like Launch4J can do this.