I'm new to Weka. I downloaded it and can use the GUI interface, but I cannot figure out why I cannot run it from the command line (on a Mac OS X).
I'm in bash. When I do echo $PATH, I can see the path to weka.jar, but when I run
java -cp weka.jar weka.classifiers.functions.MultilayerPerceptron
Error: Could not find or load main class weka.classifiers.functions.MultilayerPerceptron
Caused by: java.lang.ClassNotFoundException: weka.classifiers.functions.MultilayerPerceptron
Now, I go to the weka folders and I can see that I have classifiers/functions/ there, but the files inside are only htmls.
I also tried
java weka.core.WekaPackageManager
Error: Could not find or load main class weka.core.WekaPackageManager
Caused by: java.lang.ClassNotFoundException: weka.core.WekaPackageManager
You need to set the classpath
export CLASSPATH=/home/weka/weka.jar:$CLASSPATH
I use this bash script to start wekafrom the command line:
#!/bin/bash
WEKA_HOME=/opt/smallapps/weka-3-9-1
export WEKA_JAR=$WEKA_HOME/weka.jar
export PATH=$WEKA_HOME:$PATH
CP="/usr/share/java/:/opt/dbvis9/jdbc/jtds/jtds.jar:/opt/database/sqlite/sqlite-
jdbc.jar:$WEKA_JAR"
echo "used CLASSPATH: $CP"
DIR=$WEKA_HOME
echo "changing to '$DIR'"
cd "$DIR"
export WEKA_HOME
# start small GUI Chooser, with 8GB of max memory
java -cp $CP -Xmx8092m weka.gui.GUIChooser &
#java -cp $CP -Xmx500m weka.gui.GUIChooser &
This also includes jarfiles with database drivers to the classpath
I think not all of these variables WEKA_HOME, WEKA_JAR, DIR etc are necessary, it's just what I'm using at the moment.
Related
When i try to execute to execute this line
bash -x ExecutionAuto.bat
I get an error from my Lib folder saying that one of the jars isnt working properly.
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 1: $'PK\003\004': command not found
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 2: $'ؔ\220L': command not found
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 8: syntax error near unexpected token `)'
��������0 6&»���2<��߽�{�i'���arseBitSet-1.2.jar: line 8: `��6)Ѐ*u)�����RP �rN-p�đ�
�{�eB�M}i��Qa0�{}/�aHU�
'���xQXk)�Ћ.'?l3����A�I�|��0AİV���v�)s ?���5N���V��v��hH�;"���~Gt D��}|ȣ^�`�ܨ"r��d���}7��0t)y���{�W���
+ java org.testng.TestNG ../Demo_Automatisation/testng.xml
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
I dont know if there is a probleme with the jar files since it works fine in Windows but in linux it doesnt work.
This is my .sh file:
export projectLocation=../Demo_Automatisation
cd $projectLocation
export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*
java org.testng.TestNG $projectLocation/testng.xml
I just coppied what i found on the internet since i had a .bat file at first since i was using Windows does transferring from Windows to linux requieres that i do something to my jar files ?
The issue is that the ; in your classpath definition actually separates two commands so the $projectLocation/lib/* is interpreted as a new command, expands to the name of the jar file and the shell tries to execute the jar file as a shell script (which fails miserably). On Linux the separator for classpaths is : and not ; (almost certainly for exactly this reason).
In other words: instead of
export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*
you need
export CLASSPATH=$projectLocation/bin:$projectLocation/lib/*
As a bonus suggestion: the /* in the CLASSPATH should be interpreted by Java and not the shell, so it's better to actually quote the value:
export CLASSPATH="$projectLocation/bin:$projectLocation/lib/*"
I made a java project.
The project is....output log message and system.out.println message. just simple.
So I changed into a jar file(the name is LinuxSample.jar).
and I wrote a shell script to run this jar file.
Look at this shell script. (speakee is package name and PrintLinux is main class name)
#!bin/bash
CLASSPATH=/home/tangooc/TANGOOC/test/libs/*
CLASSPATH="${CLASSPATH};/home/tangooc/TANGOOC/test/linux/LinuxSample.jar"
java speakee.PrintLinux
this jar file and this shell script work in Window.
but linux didn't work. I don't know why
this is error message.
Could not find or load main class
Hi Best way to run a java application is to set CLASS_PATH and PATH variable first. If your current jar file depends on external jar files you will face lots of problem. Better set your path variable like below and run the application:-
#!/usr/bin/ksh
export PATH=/usr/java/bin:$PATH
# =/usr/java/bin is your java bin folder
#set environment variable CP with all the jar libraries
CP=/home/flussi/xmlEncoder/encoder.jar
CP=${CP}:/other/jar/somejar.jar
java -Xmx256M -classpath "$CP" "com.myproj.Example"
I made it
I changed the shell script.
CLASSPATH=/home/tangooc/TANGOOC/test/client/LinuxSample.jar
LIB_TOTAL=/home/tangooc/TANGOOC/test/libs/*
echo ${LIB_TOTAL}
echo ${CLASSPATH}
java -cp ${LIB_TOTAL}:${CLASSPATH} speakee.PrintLinux
also there is another way.
CLASSPATH=/home/tangooc/TANGOOC/test/client/LinuxSample.jar
CLASSPATH=${CLASSPATH}:/home/tangooc/TANGOOC/test/libs/*
echo ${CLASSPATH}
java -cp ${CLASSPATH} speakee.PrintLinux
If the someone like me change the shell script.
and check a line, a line, a line...
java -Xms512m -Xmx512m -Djava.util.logging.config.file="$FILE"\
-classpath "$HH_CLASSPATH" home.bitsbridge.Desktop.HPPP.HomeHealthGrouper.dist.com.mmm.cms.homehealth.test.HomeHealthGrouper_HP\
"input=$TEST_FILE" "config=$BASEDIR/config/HomeHealthGrouper.properties"\
$OPTIONS
As mention above,I have this java code embed inside shell code:
#!/bin/bash
BASEDIR=/home/bitsbridge/Desktop/HPPP/HomeHealthGrouper
FILE=/home/bitsbridge/Desktop/HPPP/HomeHealthGrouper/config/logging.properties
export HH_CLASSPATH=.:/home/bitsbridge/Desktop/HPPP/HomeHealthGrouper/dist/HomeHealthJava.jar:.:$BASEDIR/dist/HH_PPS_V_API.jar
#JAVA_VERSION="$(java -version)"
export JAVA_VERSION
export TEST_FILE=$BASEDIR/TestData/TestDataV7118.txt
export OPTIONS=1
java -Xms512m -Xmx512m -Djava.util.logging.config.file="$FILE"\
-classpath "$HH_CLASSPATH" home.bitsbridge.Desktop.HPPP.HomeHealthGrouper.dist.com.mmm.cms.homehealth.test.HomeHealthGrouper_HP\
"input=$TEST_FILE" "config=$BASEDIR/config/HomeHealthGrouper.properties"\
$OPTIONS
export BASEDIR=""
export HH_CLASSPATH=""
export TEST_FILE=""
export OPTIONS=""
So I need to run this file but i want to know what parameter to use for providing the class file:
Home.bitsbridge.Desktop.HPPP.HomeHealthGrouper.dist.com.mmm.cms.homehealth.test.HomeHealthGrouper_HP
as it is giving the error:
Error: Could not find or load main class home.bitsbridge.Desktop.HPPP.HomeHealthGrouper.dist.com.mmm.cms.homehealth.test.HomeHealthGrouper_HP
Is there any parameter i might be missing before providing the class to be executed.
If i am replacing -classpath with -jar:
java -Xms512m -Xmx512m -Djava.util.logging.config.file="$FILE"\
-jar "$HH_CLASSPATH" /home/bitsbridge/Desktop/HPPP/HomeHealthGrouper /dist/com/mmm/cms/homehealth/test/HomeHealthGrouper_HP.class\
"input=$TEST_FILE" "config=$BASEDIR/config/HomeHealthGrouper.properties"\
$OPTIONS
It is giving the error:
Error: Unable to access jarfile .:/home/bitsbridge/Desktop/HPPP/HomeHealthGrouper/dist/HomeHealthJava.jar:.:/home/bitsbridge/Desktop/HPPP/HomeHealthGrouper/dist/HH_PPS_V_API.jar
The last argument of the java command would be the class to execute
You specified main class as home.bitsbridge.Desktop.HPPP.HomeHealthGrouper.dist.com.mmm.cms.homehealth.test.HomeHealthGrouper_HP. I think it is little mistake.
Instead add directory /home/bitsbridge/Desktop/HPPP/HomeHealthGrouper/dist/ to variable HH_CLASSPATH which is contains classpath and specify main class as com.mmm.cms.homehealth.test.HomeHealthGrouper_HP. And make shure that exists compilled class file /home/bitsbridge/Desktop/HPPP/HomeHealthGrouper/dist/com/mmm/cms/homehealth/test/HomeHealthGrouper_HP.class. It must be *.class file, not *.java file. *.java files contains source code and *.class files contains compilled binary code.
Thanks for the effort guys i figure it out:
java -Xms512m -Xmx512m -Djava.util.logging.config.file="$FILE"\
-classpath "$HH_CLASSPATH" com.mmm.cms.homehealth.test.HomeHealthGrouper_HP\
"input=$TEST_FILE" "config=$BASEDIR/config/HomeHealthGrouper.properties"\
$OPTIONS
The problem was that the jar file inside classpath was extracted and i only need to remove the extracted folder and mention .jar file path in class path and .class file path after that in com.mms.... form.
I have a simple, single file java program that relies on a single static jar. The java code and the jar reside in the same directory. For this one-off solution I don't want to bring in the weight of ant or maven, and just want to compile it directly.
On my dev box, the following compiles and runs my code fine:
javac -cp ".;dependency.jar" File.java
java -cp ".;dependency.jar" File
However, on my test box, the java command fails, and I get the following output:
Error: Could not find or load main class File
If I change my classpath arg to -cp "." I get the following output:
Exception in thread "main" java.lang.ClassNotFoundException: dependency
My dev box is 64-bit Windows/Cygwin and java version 1.7.0_55. My test box is 64-bit Linux and java version 1.7.0_45.
What is going wrong on my test box?
The classpath separator character is different on Linux (and on Unix) than it is on Windows. It's ; on Windows, but it's : on Linux (and Unix).
Try this on Linux:
javac -cp ".:dependency.jar" File.java
java -cp ".:dependency.jar" File
I have a java program that I would like to be able to run from anywhere on my machine. I would like to run it from my Cygwin command prompt. I've made scripts to call the java program. I added the location of the java program to the classpath, and the scripts work when I run them from the java program's directory. However, when I try to run from any other directory, I get:
java.lang.NoClassDefFoundError: commandprogram/CommandProgram
This is my script:
#!/bin/sh
CWD=`dirname "$0"`
java -cp "$CWD/classes;$CWD/lib/AJarFile.jar" commandprogram/CommandProgram
Changing the java line to the following:
java -cp "$CWD/classes;$CWD/classes/commandprogram;$CWD/lib/AJarFile.jar" CommandProgram
produces the same results.
add your directory to classpath example:
java -classpath commandprogram CommandProgram
or
java -classpath directory_to_program Program
After trying just about everything I could think of, I echoed out the command and saw that there was mixing of Cygwin paths and Windows paths. The solution was to change the script to:
#!/bin/sh
CWD=`dirname "$0"`
CWD=`cygpath -w "$CWD"`
java -cp "$CWD/classes;$CWD/lib/AJarFile.jar" commandprogram/CommandProgram
Then CWD changed to "C:\Program Files\..." instead of "/cygdrive/c/Program\ Files/..."
I had previously encountered this problem and solved it with the cygpath -w solution, but then changed my script slightly and didn't notice that the path problem came back.
you have to use a dot to separate packages, not a slash.
java -cp "$CWD/classes;$CWD/lib/AJarFile.jar" commandprogram.CommandProgram
The usual way of running a java file is to save it in the Java/Bin folder and Run cmd
C:\Program Files\Java\jdk1.7.0_05\bin> javac filename.java && java classname
If you save the file in different directory such as D:, you can use the following on the cmd prompt:
D:\Project java> set path=%path%;C:Program Files\Java\jdk1.7.0_05\bin