1

I am building (not executing !) an executable jar that has 81K clases in it. Building a jar file that big is gradually slowing down during the building process until a java.lang.OutofMemoryException is thrown.

So - then how to specify the -Xmx1024m to give the jvm used while building the jar some extra memory headroom?

Note the

jar

command does not accept any -D command line parameters.

Now I did try setting

export JVM_OPTS=-Xmx1024m

and it may have helped - since the jar command did work. But I have no clear way to know if it did in fact get applied.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

3 Answers3

1

Setting JVM_OPTS does resolve this issue

export JVM_OPTS="-Xmx2048m"
jar -cvfm myjar.jar /tmp/manifest.txt classdir/

The other answers -as well as the vote to close - jumped to conclusions that this OP were about executing the jar file via java -jar myjar.jar.

The problem was - as stated in OP - that there are tens of thousands of classes to include - and it was overwhelming the default JVM settings - leading to OOME. I could watch the jar command slow down towards the end before it just gave up. After adding the JVM_OPTS there were no more issues in building the jar.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
0

The amount of memory must be determined by process, at the time of starting the JVM:

java -Xmx1024m ... -jar my.jar ...

See:

Little Santi
  • 8,563
  • 2
  • 18
  • 46
0

You cannot.

The build phase is different from the run phase. At build time, you compile java sources, and assemble them along with some resources in a jar. No JVM options are involved here.

Then at run time, you can pass options to the JVM through the java command. You cannot include JVM options at build time, because :

  • you cannot know on which JVM the jar will be executed not on what system
  • you cannot know if special options (notably -X ones) will be accepted on the JVM
  • you cannot know the available resources

For those reasons, it would make little sense if any to specify run time options at build time, that's the reason why it is not possible.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • This answer is not addressing the OP: it is *not* referring to `java -jar`. The OP is about *creating* the jar file in the first place. Why are you referring to "target" jvm's? I only need the jvm *creating* the jar. – WestCoastProjects Aug 06 '15 at 10:28