Home » Linux OS and Software » How-To » Running Java on low-memory environments
Sun, 10 May 2009 11:25 Go to next message
Registered: May 2009
Messages: 21
Hello there,
I just found the solution to my problem running Java on Village and Town VPSs (with openSUSE 11.0) due to the large amounts of memory required by the JVM. Now I want to share with others what I found.

The problem happens whn you try to run java and get the following error:
# java
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

In order to run almost ANY java-powered program when you have low memory, you can replace the java executable with a wrapper that adds the -Xmx option to the real executable. This is how to do that:

*Find the java executable
*Rename java to something else
*Create a bash script that runs the real java executable with -Xmx parameter and the original parameters supplied by the caller

Here are the commands to run as root:
# cd $JAVA_HOME/bin
# mv java xmjava
# touch java
# chmod +x java
# nano java

You can use nano, vi or ANY other editor you like. When in the editor, paste the following code:

./xmjava -Xmx16m "$@"

Replace the "16m" with the amount of megabytes you like, for example "32m", "128m" etc.

To check if it works, try to run "java -version". Here is what it did on my VPS:

marcus:/usr/bin # java -version
java version "1.6.0_0"
IcedTea6 1.4 (suse-24.4-i386) Runtime Environment (build 1.6.0_0-b14)
OpenJDK Client VM (build 14.0-b08, mixed mode)

So it works now Wink

Remember!!! Java is very memory-consuming!! Don't expect all the programs to run fine. If you have a huge Java DBMS process to execute, never expect it to work unless you buy a large VPS. Java will work fine for console scripts, or awt applications if you enabled X11 Tunnelling in SSH.

Again: don't expect taht EVERYTHING will run. You may still wish to try mono................

Thanks to VPSVille support for helping me in my research.

[Updated on: Sun, 10 May 2009 12:32]

Mon, 03 January 2011 22:14 Go to previous messageGo to next message
Registered: January 2011
Messages: 1
no more working on village vps?

16m - Ubuntu 9.04

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

I think is not possible to start a jvm!!

free -m:

total used free shared buffers cached
Mem: 64 64 0 0 0 0
-/+ buffers/cache: 64 0
Swap: 0 0 0

[Updated on: Mon, 03 January 2011 22:15]

Thu, 06 January 2011 14:31 Go to previous message
Registered: November 2007
Messages: 511
You need to set the heap on the command line to run Java in a low memory environment. See the above instructions or consult your Java docs.
Previous Topic:Firefox closes itself
Next Topic:How do i keep programs running after disconnecting from the vps?
Goto Forum:

Current Time: Wed Feb 26 00:03:00 EST 2020
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2006 FUD Forum Bulletin Board Software