I have downloaded and unzipped the following WEKA version weka-3-4-19. This is on a linux operating system. I wish to use WEKA through the command line, however on executing
java weka.classifiers.tress.j48.J48
I get the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/tress/j48/J48
Caused by: java.lang.ClassNotFoundException: weka.classifiers.tress.j48.J48
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: weka.classifiers.tress.j48.J48. Program will exit.
Can someone help me resolve this? Thank you.
Edit1:
On trying the java -jar weka.jar command
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:432)
at java.awt.Frame.<init>(Frame.java:403)
at javax.swing.JFrame.<init>(JFrame.java:202)
at weka.gui.GUIChooser.<init>(GUIChooser.java:98)
at weka.gui.GUIChooser.main(GUIChooser.java:285)
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
Edit 2:
On trying java.weka.classifiers.trees.J48
Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/tress/J48
Caused by: java.lang.ClassNotFoundException: weka.classifiers.tress.J48
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: weka.classifiers.tress.J48. Program will exit.
Edit 3:
{cslinux2:~/weka-3-4-19} echo $CLASSPATH
/people/cs/j/jld082000/weka-3-4-19/weka.jar:
{cslinux2:~/weka-3-4-19} java weka.classifiers.trees.J48
Weka exception: No training file and no object input file given.
General options:
-t <name of training file>
Sets training file.
-T <name of test file>
Sets test file. If missing, a cross-validation will be performed on the training data.
That simply means weka.classifiers.tress.j48.J48 class is not in classpath. You can write java command with -classpath switch or set CLASSPATH (permanent) variable. Another way is to use -jar switch as pointed by #jberg.
EDIT:
As I checked (I downloaded Weka 3-4-19 from that site) there is definitely no weka.classifiers.tress.j48.J48 class in weka.jar package. Probably you are looking for:
java weka.classifiers.trees.J48
For example:
$ export CLASSPATH=/home/grzegorz/weka-3-4-19/weka.jar:.
$ echo $CLASSPATH
/home/grzegorz/weka-3-4-19/weka.jar:.
$ java weka.classifiers.trees.J48
Weka exception: No training file and no object input file given.
General options:
-t <name of training file>
Sets training file.
...
This "weka.classifiers.trees.j48.J48" is a typo in the Weka documentation. It's should be this: "weka.classifiers.trees.J48"
And instead of setting the $CLASSPATH the alternative is just to put:
java -cp /pathto/weka.jar weka.classifiers.trees.J48
Also, you might want to give it more memory to play with, to speed things up:
java -Xmx1G -cp /pathto/weka.jar weka.classifiers.trees.J48
For running a classifier (like you are attempting to do) you need to at least give it some data, which must already be converted to ARFF format.
To run a test on some data enter:
java -Xmx1G -cp /path/to/weka.jar weka.classifiers.trees.J48 -t /path/to/whatever.arff
-t is for training file.
See here:
Weka Primer
I haven't used WEKA on linux, but I think it is just packaged as a jar file, so you want to:
java -jar weka.jar
You can also use the weka source jars to use the classifiers in your own code by including it in your build path like you would other jars.
I run the Linux Developer version in macOS. You can copy the .bash_profile below and modify to your needs.
As I answered here, you can just put the following to your ~/.bash_profile
export R_HOME="/Applications/R.app/Contents/MacOS/R" #for WEKA MLR R plugin
export CLASSPATH="/Applications/weka-3-9-1/weka.jar" #for WEKA commandline
export WEKAINSTALL="/Applications/weka-3-9-1"
export WEKA_HOME="/Applications/weka-3-9-1"
export CLASSPATH=$CLASSPATH;$WEKA_HOME/weka.jar
export HEAP_OPTION=-Xms4096m -Xmx8192m
export JAVA_COMMAND java $HEAP_OPTION
after this and refreshing the terminal, you should be able to run the following command
java weka.classifiers.trees.J48 -t $WEKAINSTALL/data/iris.arff
Related
I am trying to run weka on linux server.
The steps I followed as listed below:
1. I download a zipped archive containing Weka as given on http://www.cs.waikato.ac.nz/ml/weka/downloading.html
I then unzipped the zip file.
I next tried executing weka.jar using the command:
java -Djava.awt.headless=true -jar weka.jar
I also simply tried: java -jar weka.jar
This also gives me errors.
I have set the DISPLAY variable using setenv DISPLAY localhost:0.0.
I have tried other values too such as DISPLAY 0
weka.jar has also been added to the PATH variable.
The error I am getting is as follows:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:433)
at java.awt.Frame.<init>(Frame.java:403)
at javax.swing.JFrame.<init>(JFrame.java:202)
at weka.gui.LogWindow.<init>(LogWindow.java:252)
at weka.gui.GUIChooser.<clinit>(GUIChooser.java:215)
Could not find the main class: weka.gui.GUIChooser. Program will exit.
Any help would be appreciated.
Thank You
Perhaps you need to add the CLASSPATH. For example:
java -cp "$CLASSPATH:./weka.jar" -Xmx500m weka.gui.explorer.Explorer
Google told me to run this command :
sudo apt-get install openjdk-6-jre
When I did as following, it worked.
Extract weka.jar to directoy named weka.
Write a script runWeka.sh:
#! /bin/bash
WEKA_HOME="~/weka";
java -classpath $WEKA_HOME weka.gui.Main
Run this script.
i have a windows batch script which launches a jar which launches a game written all in Java (its a runescape client). It should work.
The original Batch (WIN):
#echo off
#echo Client Is loading......
#echo -----------------------
java -Xmx1000m -cp .;Theme.jar Gui 0 0 highmem members 32
pause
the Shell file ive made for OS:
#!/bin/sh
echo Your client is loading...
echo --------------------
java -Xmx1000m -cp Theme.jar Gui 0 0 highmem members 32
the error in terminal:
Your Client is loading...
--------------------
Exception in thread "main" java.lang.NoClassDefFoundError: Gui
Caused by: java.lang.ClassNotFoundException: Gui
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
How can i fix it or make a shell script that will do the exact as the Batch and actually run?
You didn't convert the shell script correctly. In the Windows version the -cp parameter is .;Theme.jar, so in Linux it should be .:Theme.jar, the path separator ; replaced with :, like this:
java -Xmx1000m -cp .:Theme.jar Gui 0 0 highmem members 32
A ClassNotFoundException in general signals something wrong with the classpath. (The -cp parameter is a shortcut for -classpath).
Judging by the Windows script, Gui is a class name, and the rest are command line arguments passed to the Gui class. The error message tells you it cannot find the Gui class. It must be either in the current directory or the theme.jar. If it's not in any of them then this can't work.
java.lang.ClassNotFoundException
I think there might be two reason:
The jar file which you are including while running the java program is not included into the jar file which you have created for shell script.
You have not defined Main-Class in manifest.mf file while you created your jar file.
Try using this,
java -Xmx1000m -cp .: Theme.jar Gui 0 0 highmem members 32
as ':' is the classpath seperator for Unix environments while ';' is for Windows.
I am very new to Apple scripting so please bear with me. I need to run a .jar file using applescript, the jar is not executable so I invoke the class like com.path.to.myClass. My Apple script looks like below-
display alert "You are about to start the image rename process." buttons {"OK", "Cancel"}
set theAnswer to button returned of the result
if theAnswer is "OK" then
do shell script "java -classpath ./ImageRename_JAVA-1.0.0.jar:. com.mff.image.rename.Main"
else
say "Exit"
end if
Both the applescript and the ImageRename_JAVA-1.0.0.jar are in the same directory, but when I run the script it gives me an error-
error "Exception in thread \"main\" java.lang.NoClassDefFoundError: com/mff/image/rename/Main
Caused by: java.lang.ClassNotFoundException: com.mff.image.rename.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)" number 1
Am I setting the classpath wrong? If so, what is the correct way? Also, how can I add more jars to the classpath?
When I run the below command from Terminal it runs just fine.
$ java -classpath ./ImageRename_JAVA-1.0.0.jar:. com.mff.image.rename.Main
I know that it can be done in a better way using JAR Bundler but I have no control over the JAR and its developed by someone else. Is there a way that I can include all the JARs inside the application under YourApplicationName.app/Contents/MacOS/Resources/Java/ directory and use those in the class path.
I don't think you can guarantee what the working directory is in a do shell script, but you can work it out with something like this:
set scriptPath to the POSIX path of (path to me)
do shell script "SCRIPTDIR=`dirname " & scriptPath & "` ; " ¬
& "java -classpath $SCRIPTDIR/ImageRename_JAVA-1.0.0.jar:$SCRIPTDIR com.mff.image.rename.Main"
To add extra JARs to the classpath you can take advantage of a shortcut provided by the java command whereby a classpath entry ending in * includes all .jar files in the given directory.
do shell script "java -classpath " ¬
& "/Applications/Something.app/Contents/Resources/Java/\\* com.example.MyClass"
The * needs to be backslash escaped to protect it from expansion by the shell, and the backslash itself needs to be backslash-escaped when it is within an AppleScript string literal, hence the \\*.
This is for a class. I've never used shell scripting before, but the instructions are to write a script that runs my java program (which is already all set up to take in command line arguments (at least one arg, with an optional second one)). I'm supposed to be able to run it like this:
./script.sh arg1 arg2
But when I do, I get the following error (my java main class name is A1):
Exception in thread "main" java.lang.NoClassDefFoundError: A1/class
Caused by: java.lang.ClassNotFoundException: A1.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: A1.class. Program will exit.
This is what my shell script looks like right now:
#!/bin/sh
java -Xmx1024m A1.class $#
Any help is appreciated.
You need to tell java where to look for your class (using -cp) - either in a directory or a .jar
To find the directory where the script is (as opposed to where it was launched from), you can use: $(dirname $0).
So, for example:
#!/bin/bash
JVM=java
JVM_OPTS="-Xmx1024m"
$JVM $JVM_OPTS -cp $(dirname $0)/myapp.jar A1 "$#"
It's a good idea to be explicit about the shell you want. Also note the quotes around $#, needed for escaped args.
Use the classpath flag when running java to tell the virtual machine where your A1.class file is located.
See the doc
Should be something like:
java -classpath /myfolder A1 $#
Also, do not use the ".class" suffix when running the command.
The version of Ubuntu I use provides FOP 0.95. Its having problems, so I wanted to try the latest version of FOP. I successfully downloaded and built the sources.
Unfortunately, I can't figure out how to install FOP 1.0. The build instructions (https://xmlgraphics.apache.org/fop/1.0/compiling.html) did not cover the topic, and the README does not offer any instructions.
I naively tried ant install --prefix=/usr/local which failed. Ant listed its flags and switches, but did not include an install option. Next, I performed sudo cp ./fop /usr/local/bin, which resulted in the following
$fop -V
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fop/cli/Main
Caused by: java.lang.ClassNotFoundException: org.apache.fop.cli.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.apache.fop.cli.Main. Program will exit.
How does one install a program with Ant?
Jeff
Uncompress the download to a directory.
Add that directory to your path.
export PATH=~/tech/lang/java/fop/fop-1.0/:$PATH
That's it:
Daves-MacBook-Pro:~ Dave$ fop -V
USAGE
fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>
[OPTIONS]
-version print FOP version and exit
-d debug mode
-x dump configuration settings
# etc...
Welcome to the world of PATH and environment variables in Java.
The error is being caused because java cannot find the class libraries it requires.
You will find that fop is a script which invokes java with the appropriate parameters for this java application.
You also need to check your java installation and make sure everything is straight.