Weka ClassNotFoundException - java

I'm attempting to install Weka, which I have installed into /weka directory. I set the CLASSPATH variable, but that shouldn't matter anyway because I'm using -cp.
I enter this into SSH:
java -Xmx5G -cp /weka/weka.jar
weka.core.converters.TextDirectoryLoader -dir /home/myuser/test >
/home/myuser/test.arff
And it spits out:
Exception in thread "main" java.lang.NoClassDefFoundError:
weka/core/converters/TextDirectoryLoader Caused by:
java.lang.ClassNotFoundException:
weka.core.converters.TextDirectoryLoader
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: weka.core.converters.TextDirectoryLoader.
Program will exit.
What wrong? There is no "weka/core/converters/TextDirectoryLoader" because its all stored in weka.jar, which is where it should be looking.
My Java version:
java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.10)
(rhel-1.23.1.9.10.el5_7-x86_64) OpenJDK 64-Bit Server VM (build
19.0-b09, mixed mode)
I just downloaded Weka today from the link on their downloads page, so there shouldn't be anything wrong with it.
Now I know that this would normally be because it can't find weka.jar, but I promise you that it is right there at: /weka/weka.jar. And I can also promise that both the /weka directory and weka.jar have execute permissions.
Please help!

Just downloading and running the .jar works for me:
carsten#dallas:~$ java -Xmx5G -cp /tmp/weka-3-6-5/weka.jar weka.core.converters.TextDirectoryLoader
Usage:
TextDirectoryLoader [options]
Options:
...
as well as java -jar /tmp/weka-3-6-5/weka.jar, which opens some GUI tool.
You sure that you installed Weka on the server you SSH into?

I happened the same to me in Mac OS when I used the jar released in the dmg packaged.
Instead of that one, I imported the jar file under:
Applications/Weka/Resources/java/weka.jar
To get it you have to:
go to Applications
right click over weka-3-x-x
Show package content
go to /Resources/java/weka.jar
import that one jar into your classpath

Related

Ant media server: java.lang.reflect.InvocationTargetException

I have downloaded the ant-media-server files and tried to launch the server.
But, I recently learned that Ant Media Server requires java 11.
So I updated the java version to java 11:
So when I run this command:
java -version
This is the result:
openjdk version "11.0.11-ea" 2021-04-20
OpenJDK Runtime Environment (build
11.0.11-ea+4-Ubuntu-0ubuntu3.16.04.1)
OpenJDK 64-Bit Server VM (build 11.0.11-ea+4-Ubuntu-0ubuntu3.16.04.1,
mixed mode, sharing)
And when I run this command:
javac -version
This is the result:
javac 11.0.11-ea
When I try to launch the Ant Media Server, this is the result I get:
Bootstrap exception: null
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.red5.server.Bootstrap.bootStrap(Bootstrap.java:122)
at org.red5.server.Bootstrap.main(Bootstrap.java:50)
Caused by: java.lang.UnsatisfiedLinkError: no jniavutil in java.library.path: [/home/ahmed/Desktop/CodingPlayground/ant_media_server/ant_media_server/lib/native]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2670)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
at java.base/java.lang.System.loadLibrary(System.java:1873)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
at org.bytedeco.javacpp.Loader.load(Loader.java:1300)
at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
at org.bytedeco.ffmpeg.global.avutil.<clinit>(avutil.java:14)
at org.red5.server.Launcher.launch(Launcher.java:65)
... 6 more
Caused by: java.lang.UnsatisfiedLinkError: /home/ahmed/.javacpp/cache/ffmpeg-4.3.1-1.5.4-linux-x86_64.jar/org/bytedeco/ffmpeg/linux-x86_64/libjniavutil.so: libva-drm.so.2: cannot open shared object file: No such file or directory
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2627)
at java.base/java.lang.Runtime.load0(Runtime.java:768)
at java.base/java.lang.System.load(System.java:1837)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1633)
... 10 more
Any idea what's going on?
EDIT 1:
When I checked the JAVA_HOME environment variable, I found-out, it still points to java-8 files:
JAVA_HOME=/usr/lib/jvm/java-8-oracle
So I tried to see the files in /usr/lib/jvm, and this is what I found:
So maybe this is causing the problem?
I don't know to which file should I make JAVA_HOME point to instead.
EDIT 2:
I opened /etc/environment and modified JAVA_HOME to this:
JAVA_HOME='/usr/lib/jvm/java-11-openjdk-amd64'
I also changed it globally by running:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
And, I am still getting the same error.
check variables in /etc/profile
you may set java environment strong textvariables like this:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

What is wrong with my attempt at Spring quickstart?

So I am trying out the very very simple spring quickstart. You can find it here.
I have have java 1.8 installed, but am downloading Java 11 in the mean time from the suggested location (AdoptOpenJDK) just to be sure that isn't the problem.
I followed all the instructions, but when running the project, I get... nothing...
~/spring/demo$ java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)
~/spring/demo$ ./mvnw spring-boot:run
It has been like this for 30 minutes while I've been typing out this question. There are no logs or anything to suggest what might be wrong.
Any ideas?
UPDATE: I am now getting a zip error within maven. I am still using java 1.8
~/spring/demo$ ./mvnw spring-boot:run
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.zip.ZipFile.<init>(ZipFile.java:169)
at org.apache.maven.wrapper.Installer.unzip(Installer.java:169)
at org.apache.maven.wrapper.Installer.createDist(Installer.java:86)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:121)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:61)
Trenin , Please check whether you have 7Zip/Winzip Software because during startup it looks for these to unzip certain dependencies that it downloads .

Unsupported major.minor version on Mac OS X El Capitan

Following the solutions online for Major Minor version of Java being incorrect on El Capitan, I saw several solutions which made you either disable rootless, which i didn't like the sound of, or just didn't work anymore in OS X El Capitan.
When trying to run webdriver-manager start on El Capitan, you may get an error saying:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncher : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
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)
Selenium Standalone has exited with code 1
The recommended fix for this online is to change the symlink that Mac OS X has to Java, which you can find by running echo $JAVA_HOME in the terminal.
This is pointing to the incorrect folder, and the error is because the application was compiled with a higher version of JRE than the machine is running in the terminal.
You should go to Oracle, and download the latest JRE version (http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
After this has been installed, you will have Java 8 on your machine, but it will not update the terminal properly. If you run java -version in your terminal, you'll see Java Version "1.6", you want this to say Java Version "1.8". The previous way to do this was to change the symlink manually, however, since El Capitan, Apple have made certain folders unchangable even to admin users, with their Rootless install. This includes the /usr folder.
There are two ways to fix this, the first is dangerous, and what everyone else seems to recommend. The second, is safer, and what I am putting here.
If you go to your System Preferences -> Java -> Java -> View... -> System and copy the Path field.
It will look something similar to the following:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
We want most of this path, except the /bin/java on the end.
So your path should now be copied as:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Run the following command in the terminal, replacing [PATH] with the path you have from above.
export JAVA_HOME="[PATH]"
and run that in the terminal.
Afterwards, run java -version again, and it should now say Java Version "1.8"
Now, webdriver-manager start should succeed.
Adding the following line to ~/.bash_profile worked for me:
export JAVA_HOME="$(/usr/libexec/java_home --version 1.8)"
You might have to restart your shell for these changes to reflect or just run:
. ~/.bash_profile

Inconsistency in ant command - CentOS 6.3

I'm in CentOS 6.3 and I'm attempting to recompile a .java file using the ant command however I'm getting these two results.
When I run ant:
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
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.tools.ant.launch.Launcher. Program will exit.
When I run sudo ant:
Error: JAVA_HOME is not defined correctly.
We cannot execute java
When I run *echo $JAVA_HOME*:
/usr/lib/jvm/java-1.6.0-openjdk/
Before anyone suggests that I should be using the JRE instead of the JDK, I just need to mention that my installation manual for the software I'm running - OpenGTS - specifically requests the JDK. Any ideas as to what I'm doing wrong?
Thanks in advance.
ant is script to launch a java program. It appears that script could not figure out a value for ANT_HOME. On linux the script tries to load /etc/ant.conf which reset the ANT_HOME. Your symptoms does not match, but it is worth checking.
Quote from site
The cause of this is that there is an old version of ant somewhere in
the class path or configuration.
A version of this problem may be seen on some linux systems. Some
linux systems (Fedora Core 2 for example), comes with a version of ant
pre-installed. There is a configuration file called /etc/ant.conf
which if present, the ant shell script will 'dot' include. On Fedora
Core 2, the /etc/ant.conf file resets the ANT_HOME environment
variable to /usr/share/ant. This causes the problem that an old
version of ant (1.5.x in this cause) will be used with a new version
of the ant script file.
One can check if this is the case by doing ant --noconfig -version.

Programs works on my pc, but not server

I have a program i've written and turned into a jar file. The jar file works just fine on my computer. When I try to run the program on the server it will be running on, the jar file doesn't work. I get this error.
Exception in thread "main" java.lang.NoClassDefFoundError: Publish
Caused by: java.lang.ClassNotFoundException: Publish
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: Publish. Program will exit.
I think this problem is caused by different versions of java or different environments or something. I think the libraries are not the problem here, but the environments where this program is being run. The jar file works perfectly on my own computer.
My java version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
Server java version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
I also get this error, which suggests that I may have a 32 bit java while the server has a 64 bit and this might be causing problem.
Error occurred during initialization of VM
Could not reserve enough space for object heap
I got around this error easily by just allocating some memory to running this process.
Does anyone have any idea about how to fix this problem?
Note: i also looked at the manifest file and it seems fine
You are using Publish without the package. This means java expects this class in default package.
You need to use the fully qualified name, for instance: foo.bar.Publish
From documentation:
By default, the first non-option argument is the name of the class to
be invoked. A fully-qualified class name should be used. If the -jar
option is specified, the first non-option argume nt is the name of a
JAR archive containing class and resource f iles for the application,
with the startup class indicated by the Main-Class manifest header.
You need to include the full package name. This error is not that of 32/64 bit OS's, or differences in Java Environments.

Categories