I installed the latest version of Weka on Windows
http://www.cs.waikato.ac.nz/ml/weka/
and I tried to run one of the weka features from the command line:
java weka.core.converters.TextDirectoryLoader -dir text_example > text_example.arff
which is a reference to this: http://weka.wikispaces.com/Text+categorization+with+WEKA
but then weka returns this error:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
Exception in thread "main" java.lang.NoClassDefFoundError: weka/core/converters/
TextDirectoryLoader
Caused by: java.lang.ClassNotFoundException: weka.core.converters.TextDirectoryL
oader
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: weka.core.converters.TextDirectoryLoader. Progra
m will exit.
I already set the CLASSPATH environment variable to point to the weka jar.
What did I do wrong?
The shell you run the command in apparently doesn't have the CLASSPATH environment variable set properly, otherwise the ClassNotFoundException wouldn't occur. As an alternative to the environment variable you can specify the classpath using the command line:
java -cp path/to/weka.jar weka.core.converters.TextDirectoryLoader -dir [...]
You can also check whether the environment variable is set correctly by executing echo %CLASSPATH% in the cmd shell.
Related
I am trying to run a java based java profiler to find out what uses up resources on my java application on my dedicated machine. The profiler I am trying to use is called warmroast.
I get the following error from running.
java -jar warmroast.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/AttachNotSupportedException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
I think this error is caused by running the file with jre instead of jdk.
I have installed java-1.7.0-openjdk-1.7.0.55-2.4.7.1.el6_5.x86 as a yum package.
[root# ~]# java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
I think to fix this problem, I will need to run the jar file using jdk. Is there some kind of a jdk path to the jdk bin file? If so, what is it in centos? I've googled for a while and came up with dozens of wrong paths. I feel stupid because I think jre is a part of jdk and jdk is only using for compiling stuff and I don't think you can run files with jdk...
...
...
The class that could not be found is in tools.jar in your JDK. This library is usually not automatically on the class path, even if you use JDK instead of JRE.
According to the documentation, on Linux warmroast should be started as follows (replace PATH_TO_JDK with the path to your JDK):
java -Djava.library.path=PATH_TO_JDK/jre/bin -cp PATH_TO_JDK/lib/tools.jar:warmroast-1.0.0-SNAPSHOT.jar com.sk89q.warmroast.WarmRoast --thread "Server thread"
Here, tools.jar is manually added to the classpath.
I used to launch a java tool with a batch like this :
java -classpath "./lib/JSanExport.jar;./lib/JSanRmiApiEx.jar;./lib/JSanRmiServerUx.jar" -Xms128M -Xmx768M -Dmd.command=command_VSPLA.txt -Dmd.logpath=log sanproject.getmondat.RJMdMain
For some reasons i need to convert that batch into a Powershell script. But when I copy the same line on my powershell script I got an error, whereas I launch it in the same workingdir.
c:\Program Files\ExportTool\export>powershell .\Run_VSPLA.ps1
Exception in thread "main" java.lang.NoClassDefFoundError: /command=command_VSPLA/txt
Caused by: java.lang.ClassNotFoundException: .command=command_VSPLA.txt
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: .command=command_VSPLA.txt. Program will exit.
Do you know what happens?
try to set jvm options before classpath :
java -Xms128M -Xmx768M -Dmd.command=command_VSPLA.txt -Dmd.logpath=log -classpath "./lib/JSanExport.jar;./lib/JSanRmiApiEx.jar;./lib/JSanRmiServerUx.jar" sanproject.getmondat.RJMdMain
It searches for class named /command=command_VSPLA/txt. For batch = is a delimiter and is parsed in a different way than powershell.
EDIT
The solution given by the OP:
java -Xms128M -Xmx768M "-Dmd.command=.\command_VSPLA.txt" "-Dmd.logpath=log" -classpath "./lib/JSanExport.jar;./lib/JSanRmiApiEx.jar;./lib/JSanRmiServerUx.jar" sanproject.getmondat.RJMdMain
Seem like it can't find command_VSPLA.txt, maybe try a full path.
I m trying to compile an open source software . The build works fine and results into a jar file "five-server.jar". When I try to run this file from cmd , I get these errors.
C:\Users\vickey\code\five-server\dist\main>java -jar five-server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.devtcg.five.Main. Program will exit.
any suggestion what is wrong?
The SWT Jar files are platform dependent.
See http://www.jarfinder.com/index.php/java/info/org.eclipse.swt.SWTError
e.g. on Windows a suitable jar would be:
org.eclipse.swt.win32.win32.x86_3.1.0.jar
or on Mac OS X:
swt-macosx-3.0m7.jar
and so on.
You might run into call kinds of followup problems if you add this dependency e.g. whether you are
using 32bit or 64bit libraries.
It is too bad that these kind of dependency problems show up more often than not these days :-(
You have to set the classpath so that it includes at least the class org.eclipse.swt.SWTError
or the jar containing it:
java -classpath path/to/jar/containing/org.eclipse.swt.SWTError -jar five-server.jar
You should also set the Main-class attribute in the manifest file in the five-server.jar
Following the #Wolfgang Fahl answer, you might download the references here:
Standard Widget Toolkit » 4.3 x86
Maven reference:
https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86.4.3.swt/org.eclipse.swt.win32.win32.x86/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
Standard Widget Toolkit » 4.3 x64
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86_64.4.3.swt/org.eclipse.swt.win32.win32.x86_64/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
I'm running into problems trying to use The Grinder. The tutorial on the site tells me to run "StartAgent.bat", which looks like this:
call "C:\Documents and Settings\dkeller\Desktop\Grinder\setGrinderEnv.bat"
java -cp %CLASSPATH% net.grinder.Grinder %GRINDERPROPERTIES%
When I open the Command Console and try to run it, I get this error:
"C:\Documents and Settings\dkeller\Desktop\Grinder>java -cp "C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar;"C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar;"C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar;"C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar; net.grinder.Grinder "C:\jython2.5.2\grinder.properties"
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/grinder/G
rinder (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)"
Yikes. Not totally sure what the problem is. Thinking it might be an issue with java versions, I made sure to update to the latest, but I'm not sure if it worked correctly. Here are some commands I ran, so you can see what I mean.
"java -version" returns
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
and "javac -version" returns
javac 1.6.0_26
Any help would be much appreciated, as I'm not sure what to try next.
Looks like your PATH environment variable is the problem. It's probably easiest just to edit that to have your JDK's bin directory in the PATH of the "user" part of the environment variables, so it comes before anything else which might contain java.exe.
Basically when you run java -version, you want it to show the same version number as javac -version.
Alternatively, you might consider uninstalling Java 1.4.2 unless you're still using it for something else...
class HelloWorld
{
public static void main(String[] args)
{
System.out.println("hey");
}
}
Command prompt session:
C:\Users\zobdos\Desktop>javac HelloWorld.java
C:\Users\zobdos\Desktop>dir *.class
Volume in drive C is OS
Volume Serial Number is A45E-7B01
Directory of C:\Users\zobdos\Desktop
11/20/2010 10:16 AM 417 HelloWorld.class
1 File(s) 417 bytes
0 Dir(s) 8,145,432,576 bytes free
C:\Users\zobdos\Desktop>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: HelloWorld. Program will exit.
C:\Users\btolbert\Desktop>
Nevermind, it works after using:
java -classpath . HelloWorld
You've a %CLASSPATH% environment variable in your environment. Get rid of it, it's disturbing your java commands, it's a poor practice tought by Sun Oracle anyway. Once you use -classpath argument or its -cp shorthand, then the %CLASSPATH% will be overridden. If the classpath is not specified by either the environment variable or the arguments, then the current path will be taken as default (as you initially expected).
run with classpath specified to the current directory:
java -cp . HelloWorld