21

I'm trying to increase the heap size in java for weka which keeps crashing. I used the suggested line:

> java -Xmx500m -classpath

but I get the following error:

-classpath requires class path specification

I'm not sure what this means. Any suggestions?

screechOwl
  • 27,310
  • 61
  • 158
  • 267

17 Answers17

23

What I found was the actual issue was in the file 'RunWeka.ini' in '\Program Files (x86)\Weka-3-6'. I opened it with notepad and in the middle of the file there is a line 'maxheap = 512m'.

I changed the line to read 'maxheap=2000m', saved the file and reloaded weka and this fixed my problems.

I'm not sure if this is the correct way to do it or not but it worked for me.

screechOwl
  • 27,310
  • 61
  • 158
  • 267
  • well you change the max heap size from the the command line as well while running weka.jar. Its the same thing – Pandit Dec 14 '15 at 01:47
  • More recent versions of Weka accept the option `-m`. So you can just run `weka -m 2g`. – giusti Feb 19 '18 at 18:13
  • For version 3.8 I added maxheap=5000m, I cant see the change in Help >> SystemInfo memory.max . If changed at this level its not reflecting either. – Morse Feb 27 '18 at 15:06
13

Run this command in your terminal:

java -Xmx1024m -jar weka.jar
Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51
12

Omit the -classpath option. Use just -Xmx500m option.

So, instead of just:

java weka.core.Instances data/soybean.arff

you do:

java -Xmx500m weka.core.Instances data/soybean.arff

If you run weka via some script (RunWeka.bat for example), then you need to modify that script (with some text editor like notepad).

Michał Šrajer
  • 30,364
  • 7
  • 62
  • 85
9

If you're using Weka 3.8.1 on Windows you can save yourself a lot of trouble by editing the javaOpts parameter. The parameter maxheap isn't used anymore, so you can set javaOpts like this in RunWeka.ini file:

javaOpts= -Xmx1040m

Where 1040m is the amount of memory you want to allocate.

Mind that the file is case sensitive.

There are a lot of ways to set this up, but this is the faster way to get Weka runing on a Windows environment at this version.

Edit: If you want Weka to use more than 1gb on windows, you need to have JDK installed. Regular JRE wont do it.

Wesley Costa
  • 91
  • 1
  • 3
5

The official Weka answer (for all operating systems and Weka versions) can be found on http://weka.wikispaces.com/OutOfMemoryException.

In case you are using a recent Weka version on Windows, the answer is:

Modify the maxheap parameter in the RunWeka.ini file.

Robert Pollak
  • 3,751
  • 4
  • 30
  • 54
4

On Ubuntu i had the same problem but i solve it by increasing the amount of memory to use for the Java Virtual Machine run this : weka -m 1024m

Ali Dabour
  • 135
  • 1
  • 7
3

For Mac OS, you have to edit a configuration file in order to increase the heap size of the Weka UI application.

I am repeating what I wrote in: Is there a workaround to solve "Java heap space" memory error when the max heap value has been already specified?

  1. Quit out of Weka if it is running.

  2. cd into /Applications/weka-XXX.app/Contents , or wherever your weka executable was installed. There will be a file called Info.plist there. It is an XML text file. I suggest you save a copy of it to another location, as you'll need to edit it in the next step.

  3. Open the Info.plist (XML) file in your favorite text editor and look for a block that says "VMOptions". There should be a value that says "-Xmx256M" or something similar that specifies the maximum heap size. You should change that value to something bigger, such as "-Xmx1024M".

  4. Start Weka.

Community
  • 1
  • 1
stackoverflowuser2010
  • 38,621
  • 48
  • 169
  • 217
3

You need to specify a classpath after -classpath, similar to the PATH env variable you need to specify the path where Java can find the classes.

The -Xmx500m setting looks fine, except that I would suggest to use 512m.

Jonas
  • 854
  • 13
  • 33
  • something like: java -Xmx512m -c:\Program Files(x86)\Java ? – screechOwl Dec 29 '11 at 00:26
  • 1
    you do not need to set a classpath for the Java libs, only to your own classes, so it could be `java -Xmx512m -classpath .` if your compiled classes are in the working directory. Or you compile them into a jar file, then you do java `-Xmx512m -classpath c:\path\to\your\jarfile.jar' – Jonas Dec 29 '11 at 00:48
1

I am running Weka 3.6 in windows. This is what i did. Go to the Weka installation directory and you will find a RunWeka.bat file. Open this file in a text editor and add -Xmx argument in the java command line.

for instance this sets to 4GB memory, %_java% -Xmx4096m -classpath . RunWeka -i .\RunWeka.ini -w .\weka.jar -c %_cmd% "%2"

Rahav
  • 23
  • 4
1

The official Weka answer is right..But....crucial is to first get rid of all JVM files and install the relevant 32 or 64 bit Java version. Not using the relevant version causes many problems including the impossibility to increase the heap further than 1024m (by changing the ini file).

Roel
  • 11
  • 2
1

Weka 3.9.2 also does not has the option of maxheap anymore. RunWeka.ini have the option of javaOpts, So you may change the below to your required memory allocation,

javaOpts=%JAVA_OPTS%   ---- > javaOpts= -Xmx1024m

Here 1024m is the customised amount of memory you want to allocate.

monir zaman
  • 309
  • 1
  • 3
  • 13
0

The best way to do it using this command

    java -Xmx1024m -[weka classifier] -t [training file path]
John Sick
  • 427
  • 6
  • 15
0

The answers above are too old (last one is 1 year ago). I had same issue with my WEKA (version 3.8.1) on Windows 10.

I had a problem to update the heap size , the way I fixed it is by adding an environment variable (under control panel) as follows:

JAVA_OPTS = -Xms30000m -Xmx30000m

Tip: Just ensure that RunWeka.ini is using this environment variable.

In the above example I give WEKA 30GB. It works.

Hope it will be helpful for some people.

Samer Aamar
  • 1,298
  • 1
  • 15
  • 23
0

You should also see if default thread stack size 20MB is enough. Increase the value to 50MB in the file /Applications/weka-3-8-1-oracle-jvm.app/Contents/Info.plist (on MAC) like below:

<string>-Xss50M</string>
Lokendra Chauhan
  • 367
  • 1
  • 6
  • 18
0

If we are using Weka Workbench CLI or Knowledge explorer we need to change as below.

As the documentation suggests the runtime parameter should be -Xmx[size_required]m where [size_required] is memory size you intend to keep to avoid memory exception.

Open RunWeka.ini

Define maxheap=[size_required]G

In my case I kept maxheap=4G , One can set like maxheap=4096m and add -Xmx#maxheap# to all the run options at # setups (prefixed with "cmd_") sections next to java commands like below

cmd_default=javaw -Xmx#maxheap# ...............
cmd_console=cmd.exe /K start cmd.exe ..................
cmd_explorer=java -Xmx#maxheap# .................
cmd_knowledgeFlow=java -Xmx#maxheap#....................

maxheap=4G

Verify the same by restarting Weka and Help>>SystemInfo

Morse
  • 8,258
  • 7
  • 39
  • 64
0

If you run weka from the command line but not through java i.e. typing weka into the command line, instead of typing

weka

specify the memory flag

weka -m 1024m

This will specify 1024 megabytes.

Blubber
  • 1,375
  • 1
  • 15
  • 32
0

If you're running weka via weka.sh, you can directly run it with memory option. For example,

sh weka.sh -memory 10g

This will increase the heap size to 10Gb (tested using Weka 3.8.4 on Ubuntu 18.04)