Help Executing this Java Application - java

I received this source code: http://www.sbbic.org/split.zip under the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
It came to me from the author without documentation or support (the author doesn't have the time right now, he is writing a book). My knowledge of Java is very limited.
Can someone tell me how to run the application in order to split the words in columns.txt file that is included in the source?
I've looked around in TextSegmenter.java trying to find how it should be called on the command line, but I have not been successful.
If I call: java com\whitemagicsoftware\dictionary\TextSegmenter lexicon.csv columns.txt
I get this error:
Exception in thread "main"
java.lang.NoClassDefFoundError:
com\whitemagicsoftwar
e\dictionary\TextSegmenter (wrong
name:
com/whitemagicsoftware/dictionary/TextSe
gmenter)
at java.lang.ClassLoader.defineClass1(Native
Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native
Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
I tried putting it into a .jar (again with limited experience, I only zipped the files with manually created manifest files included), but it is unable to load.
I am a newbee - sorry if this is a dumb question, but I would appreciate your help!
The purpose of the script is to break words that are joined (ex. "addresstype") into separate words (ex. "address" and "type"). The hope is to use this script in breaking words for the Khmer language which uses no spaces between words.
Thank you!

You are missing external libraries on the CLASSPATH. You have to set the CLASSPATH environment variable, or pass a classpath to the java command via the -cp option, like
java -cp externallib.jar:otherlib.jar -jar myjar.jar

Related

add library to java, CLASSPATH, jar, linux

I've been browsering the Internet for a couple of hours and I am unable to find an answer to my question. The library I'm trying to add is JGraphT
I'm new to Java and I wanted to add a free graph library. I downloaded all .jar files and then the issues startet. What step by step should I do?
I found information about compiling with -cp or -classpath or addng .jar to CLASSPATH (I'm using Linux and I write my programms in gedit (obligatory for my studies) and compile it with terminal). But I wonder what should I do step by step?
What do I have so far:
I have downloaded multiple .jar and they all sit in one folder with
the xxx.java file I would like to compile
do I need to change CLASSPATH? How to do it? How should I compile and
run my program after changing CLASSPATH? The ordinary way(javac
xxx.java; java xxx) or should I change sth?
or maybe I don't need to change CLASSPATH just add -classpath while
compiling? If so, what should the compile anr run commend look
like?
Also I have already tried using -cp... I'm enclosing my lines in terminal. It compiled correctly, but when I tried to run it, I received strange errors. I'm sure the code is correct since it was given in the library as a way to test wether or not is it installed correctly.
wiktoria#wiktoria-1015PW:~/programowanie/grafy/java/testy$ javac -cp jgrapht-ext-0.9.1-uber.jar: HelloJGraphT.java
wiktoria#wiktoria-1015PW:~/programowanie/grafy/java/testy$ java -cp jgrapht-ext-0.9.1-uber.jar: HelloJGraphT
Exception in thread "main" java.lang.NoClassDefFoundError: HelloJGraphT (wrong name: org/jgrapht/demo/HelloJGraphT)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
wiktoria#wiktoria-1015PW:~/programowanie/grafy/java/testy$
Let's say your class belongs into the package net.example.graph. This means the real name of the class is net.example.graph.HelloJGraphT.
This also means you have a directory structure like this:
project_dir/net/example/graph
Go to the project_dir folder, then try this:
javac -cp <path to jgrapht JAR> net/example/graph/HelloJGraphT.java
java -cp <path to jgrapht JAR> net.example.graph.HelloJGraphT

Weka from command line Mac OS

I usually use Weka from command line on Linux systems to perform feature selection on attributes as:
java -cp PATH_TO_WEKA_JAR weka.attributeSelection.CfsSubsetEval ... (other parameters)
I'm trying to run the same code on Mac OS but I have this error:
Exception in thread "main" java.lang.NoClassDefFoundError: weka.attributeSelection.CfsSubsetEval
Caused by: java.lang.ClassNotFoundException: weka.attributeSelection.CfsSubsetEval
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 run the same command on Mac OS? Shouldn't be the same as it's a UNIX based OS?
I also tried to include the path within " " but there is no difference. What's is wrong?
Try this command:
jar tf PATH_TO_WEKA_JAR | grep weka.attributeSelection.CfsSubsetEval
In the output you should see a line with weka.attributeSelection.CfsSubsetEval.class.
If you don't see such line, then the jar file doesn't contain that class,
and the command cannot work.
In that case, try to run this:
jar tf PATH_TO_WEKA_JAR | less
to just see what is in the jar file.
One way or another, this is a simple class path issue:
the class weka.attributeSelection.CfsSubsetEval is simply not on your classpath.
You need to find the correct path to the jar,
possible to other dependencies as well,
and construct the correct parameter to use in:
java -cp CORRECT_CLASSPATH weka.attributeSelection.CfsSubsetEval # ... your other params
I guess there is something wrong with the Weka jar file. It tells you it can't find a particular class in the file.
Mac OS has evolved away from Unix quite a bit, which may make it necessary to use a differend JAR file.
This may help you: Weka Site download

Java SQLite org.sqlite.JDBC classpath broken?

I stumbled upon a weird error while using JDBC sqlite with org.sqlite.JDBC
my code compiles and runs fine on Windows.
But when I tried moving it to Ubuntu it started showing this:
Exception in thread "main" java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at mall.SQLiteJDBC.<init>(SQLiteJDBC.java:27)
at mall.AllegroReader.<init>(AllegroReader.java:33)
at mall.Mall.main(Mall.java:31)
I'm running it with java -classpath "sqlite-jdbc-3.7.2.jar" -jar Mall.jar" and java -classpath "sqlite-jdbc4-3.8.2-SNAPSHOT.jar" -jar Mall.jar
with both versions in the same directory as my jar and I've tried a dozen different options specifying classpath and it behaves exactly the same. I tried openjdk and oracle jdk.
I tried rebuilding it on Ubuntu, changing ant .xmls, changing paths, etc.
I have no idea what is going on. Pls help.
Here is what happens inside my dist directory:
work1#workwork:/var/www/mall/dist$ ls
mall.db Mall.jar Mall.jar.old sqlite-jdbc-3.8.4.3-SNAPSHOT.jar
work1#workwork:/var/www/mall/dist$ java -classpath "sqlite-jdbc-3.8.4.3-SNAPSHOT.jar:Mall.jar" Mall
Error: Could not find or load main class Mall
The classpath is ignored when you use -jar.
You have to either include the dependencies in the jar (or at least have the jar manifest point to them), or run it with -classpath sqlite.jar:Mall.jar the.main.class.
Error: Could not find or load main class Mall.main. all files are there,
my main class comes from Mall.java and is in mall package which
compiles to Mall.jar
So the correct command line is:
java -classpath "sqlite-jdbc-3.8.4.3-SNAPSHOT.jar:Mall.jar" mall.Mall
OP findings
to view the classes in jar use jar tf Mall.jar - from this I got mall/Mall.class meaning my class containing main was mall.Mall
it showed
mall/Mall.class
so I should have used mall.Mall as the class to run (instead of pulling my hair)
After spending over 6 hours total with many failed attempts at running "portable" jar package using classpath and whatnot, after having tried OneJar and jarjar to no avail (ended up with Class file too large!) I decided to write the offending piece of code in PHP.
It proved to be more portable than Java in my case.

java.lang.NoClassDefFoundError is thrown when running an executable file

I am using Ubuntu 12.04, and I am trying to run a Java program on the command line.
It is a program from a famous programming interview book, Cracking the Coding Interview, and the structure of directories and java files can be seen at
https://github.com/gaylemcd/ctci/tree/master/java
Here, I am running Chapter 2/Question2_5/QuestionB.java, and I use LinkedListNode.java class in CtCILibrary directory, and I also need Chapter 2/Question2_5/PartialSum.java
I went to Chapter 2/Question2_5 directory, and compiled QuestionB.java using the compiling command
javac -cp .:../../CtCiLibrary/CtCILibrary/LinkedListNode.java ./PartialSum.java QuestionB.java
and it compiled(it took a while to figure out the compiling command), and made QuestionB.class file.
I ran java QuestionB, but it throws an error,
Exception in thread "main" java.lang.NoClassDefFoundError: QuestionB (wrong name: Question2_5/QuestionB)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
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: QuestionB. Program will exit.
There were so many references when I looked up on Google, but none of them worked for me.
Can anyone tell me how to run this?
You didn't say what directory you were running the java command from. since you did not specify the classpath the command it will look in the current directory (I believe) and down the classpath in the environment. make sure that the file(s) are
available on the classpath
in directory appropriate for their package (if no package name then in the current directory)
Hope this provides some help.

What this following error means?

I am running my java program but on executing it gives me following error.
before it was running fine but now it's throwing following error.
I checked my class path, path in environment variable all are correct.
Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile
.open(Ljava/lang/String;IJ)J
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:135)
at java.util.jar.JarFile.<init>(JarFile.java:72)
at sun.misc.URLClassPath$JarLoader.getJarFile(URLClassPath.java:646)
at sun.misc.URLClassPath$JarLoader.access$600(URLClassPath.java:540)
at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:607)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:599)
at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:583)
at sun.misc.URLClassPath$3.run(URLClassPath.java:333)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:322)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:299)
at sun.misc.URLClassPath.getResource(URLClassPath.java:168)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
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: com.sun.tools.javac.Main. Program will exit.
To elaborate on #Peter Lawrey's answer ...
The start of the stacktrace is this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile
.open(Ljava/lang/String;IJ)J
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
...
The UnsatisfiedLinkError is thrown when you attempt to call a native method that has not been resolved to a method in the corresponding native library. The rest of the message tells us that the method at fault has the signature:
long java.util.zip.ZipFile.open(String, int, long)
and that meshes with the top frame of the stack trace ... and the fact that Java's ZipFile code is known to use a native library for the heavy lifting.
The fact that it has gotten this far means that the JVM has found the native library and loaded it. But apparently, the load didn't resolve this overload of the native open method. That can only mean one thing: that the version of the ZipFile class on the bootclasspath does not match the native library.
We cannot make any definite conclusions about whether this is a JDK or a JRE, but it seems likely that it is a JDK ... unless the OP is trying to call the Java compiler in a strange way. (The "could not find the main class: com.sun.tools.javac.Main" message probably means that the JVM could not load the class ... because of the UnsatisfiedLinkError breakage.)
Either way, JDK versus JRE is not the immediate problem. The real problem is a mismatch between the "rt.jar" on the JVM's bootclasspath, and the native libraries.
The question asks:
how to solve this then?
It depends on what exactly you did to get this error.
What command did you run?
What were the command line options and arguments?
Have you been "messing around" with your JRE / JDK installation?
Are you trying to use the "rt.jar" file from one installation in another one?
It means your rt.jar is for a different version of Java as your JVM.
I would ensure that you don't have a rt.jar in your boot class path and your JRE is installed correctly.
Could not find the main class: com.sun.tools.javac.Main. Program will exit.
When a class fails to load due to some low level error, it reports that the class could not be found.
The reference in the error message about not finding com.sun.tools.javac.Main leads me to believe that this is a program that needs to be run with the JDK rather than just a JRE.
your JRE path is pointing to the JDK path
Solution :
Step 1: Right click the server
Step 2: Click the Run Time Configuration
Step 3: GIVE the JRE path under the JDK.
Solution fixed

Categories

Resources