I'm still very new to Java. I'm trying to use CMU's Sphinx4 voice recognition. When I used the compiling process they have prepared, everything worked fine. However, now that I'm trying to compile my own code separately I'm running into a problem.
In the codes source files (src/) exists an apps/ directory which contains the demos I'm trying to compile manually, along with a sphinx4/ directory which contains the main functions to be used. To compile the code I move into the apps/ directory and run
javac -classpath ../sphinx4/ edu/cmu/sphinx/demo/helloworld/HelloWorld.java. This compiles without error. However, then when I try to run the newly made class using java edu/cmu/sphinx/demo/helloworld/HelloWorld the result is:
Exception in thread "main" java.lang.NoClassDefFoundError: edu/cmu/sphinx/util/props/ConfigurationManager
at edu.cmu.sphinx.demo.helloworld.HelloWorld.main(HelloWorld.java:33)
Caused by: java.lang.ClassNotFoundException: edu.cmu.sphinx.util.props.ConfigurationManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
Yet, as far as I can tell, the class does exist right where it should be. src/sphinx4/edu/cmu/sphinx/util/props/ConfigurationManager.class exists. I'm guessing there is a good reason that it is considered not found when it is there, but I just don't know it because I don't know enough about Java yet. What might cause this to happen?
Thank you for your time!
Two problems:
You need to specify the classpath when you run as well as when you compile
You need to specify a class name to run; that won't have slashes in
You want:
java -classpath .:../sphinx4 edu.cmu.sphinx.demo.helloworld.HelloWorld
Use ";" instead of ":" if you're running on Windows.
(Your error message suggests that you actually are giving the right class name, in which case your question hasn't really shown what you're doing. It's important to be accurate in your question, in order to get helpful answers.)
Look:
Note 4:
If you have the source distribution, make sure that the JAR file lib/sphinx4.jar is built. If not, go to the top level directory and type: ant.
You should probably use ant to build the project with your new class(es).
Did you follow the instructions here: http://cmusphinx.sourceforge.net/sphinx4/#how_build ?
Good luck!
Related
I did found quite a lot about this error, but somehow none of the suggested solutions resolved the problem.
I am trying to use JNA bindings for libgphoto2 under Ubuntu in Eclipse (moderate experience with Java on Eclipse, none whatsoever on Ubuntu, I'm afraid). The bindings in question I want to use are here:
http://angryelectron.com/projects/libgphoto2-jna/
I followed the steps described on that page, and made a simple test client that failed with the above error. So I reduced the test client until the only thing I tried to do was to instantiate a GPhoto2 object, which still produced the error. The test client looks like this:
import com.angryelectron.gphoto2.*;
public class test_class
{
public static void main(String[] args)
{
GPhoto2 cam = new GPhoto2();
}
}
The errors I get take up considerably more space:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Structure
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at test_class.main(test_class.java:12)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Structure
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
libgphoto2 itself is installed, it runs from the command line, I even have the development headers and am able to call GPhoto2 functions from python, so the problem can't be located there.
When looking at the .class files in Eclipse, however, they didn't have any definitions. So I figured that might be the problem, especially since there was an error when building the whole thing with ant (although the .jar was succesfully exported, from what I could make out the error concerned only the generation of documentation).
So I loaded the source into eclipse and built the .jar myself. At this occasion Eclipse stated there were warnings during the build (though no errors), but didn't show me the actual warnings. If anyone could tell me where the hell the build log went, that might already help something. I searched for it everywhere without success, and if I click on "details" in eclipse it merely tells me where the warnings occured, not what they were.
Be that as it may, a warning isn't necessarily devastating, so I imported the resulting Jar into the above client. I checked the .class files, this time they contained all the code. But I still get the exact same list of errors (yes, I have made very sure that the old library was removed from the classpath and the new ones added. I repeated the process several times, just in case).
Since I don't have experience with building jars, I made a small helloworld jar, just to see if I could call that from another program or if I'd be getting similar errors. It worked without a hitch. I even tried to reproduce the problem deliberately by exporting it with various options, but it still worked. I tried re-exporting the library I actully need with the settings that had worked during my experiment, but they still wouldn't run. I'm pretty much stuck by now. Any hints that help me resolve the problem would be greatly appreciated.
In addition to what #Paul Whelan has said. You might have better luck by just get the missing jar directly.
Get the missing library here, set the classpath and then re-run the application again and see whether it will run fine or not.
What version of java are you using com/sun/jna/Structure may only work with certain JVMs.
In general, packages such as sun., that are outside of the Java platform, can be different across OS platforms (Solaris, Windows, Linux, Macintosh, etc.) and can change at any time without notice with SDK versions (1.2, 1.2.1, 1.2.3, etc). Programs that contain direct calls to the sun. packages are not 100% Pure Java.
More details here
Your jar needs a MANIFEST.MF which tells your application where the library is found. Create the file in you project root-directory in eclipse and add the following lines:
Manifest-Version: 1.0
Class-Path: <PATH_TO_LIB__CAN_BE_RELATIVE>.jar // e.g Class-Path: ../test.jar
<empty line>
Right-click your project in eclipse, go to Export->next->next->next->Use existing manifest from workspace, select it and click on finish. This should work.
Another solution is to compile the classes into the jar itself with Maven.
This must seem like an idiotic question but I am new to Hadoop and was trying to run a simple example. However, I keep running into problems with JAR files and dont seem to have the correct imports. I am using cloudera CDH 4 and it has a hole lot of JAR files to choose from with several versions of each. Since I am just starting off am not being able to differentiate. Presently i am getting this exception :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<init>(DefaultMetricsSystem.java:38)
at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<clinit>(DefaultMetricsSystem.java:36)
at org.apache.hadoop.security.UserGroupInformation$UgiMetrics.create(UserGroupInformation.java:120)
at org.apache.hadoop.security.UserGroupInformation.<clinit>(UserGroupInformation.java:236)
at org.apache.hadoop.mapreduce.task.JobContextImpl.<init>(JobContextImpl.java:72)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:144)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:131)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:139)
at com.ayon.hadoop.firstimpl.Driver1.main(Driver1.java:23)Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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)
... 9 more
It is probably because of a wrong JAR file import. So my question is this:
Can anyone tell me what are the basic JAR files needed to start up a simple Hadoop job? Also any pointers to the above exception will be much appreciated.
To include all the necessary jar files, compile your code using the following command:
# javac -cp `$HADOOP_HOME\bin\hadoop classpath` YourClassFile.java
Please note the quotes
If you're using Eclipse, follow below steps to add JARs to your project
1.Right click on the project
2.Go to Properties
3.Click on "Java Build Path"
4.Libraries Tab
5.Add External JARs
6.Select the path "/usr/local/hadoop"
7.Select all "JAR files" & add all JARs
8.Again "Add EXternal JARs"
9.Go to path "/usr/local/hadoop/lib"
10.ADD all JARs in there
11.Click "Ok"
You're set. Hope this helps.. again it depends on the Eclipse version you're using.
I was trying to install the PMD plugin to my IntelliJ IDE. I have followed the instructions but when trying to run the pmd check I am getting the following exception. From what it seems the “.” Is being parsed as a / which produce a wrong file name for the class loader.
Meaning the path: Even though the settings are
-cp %CLASSPATH%; C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4.2.5.jar; C:\Development\IDE\Utils\PMDPlugin\lib\asm-3.1.jar; C:\Development\IDE\Utils\PMDPlugin\lib\jaxen-1.1.1.jar net.sourceforge.pmd.PMD "$FilePath$" ideaj unusedcode,imports "$Sourcepath$" $FileClass$.method $FileName$
From some reason it is still looking for C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4/2/5/jar
Here is the exception:
java.lang.NoClassDefFoundError: C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4/2/5/jar;
Caused by: java.lang.ClassNotFoundException: C:.Development.IDE.Utils.PMDPlugin.lib.pmd-4.2.5.jar;
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: C:/Development/IDE/Utils/PMDPlugin/lib/pmd-4.2.5.jar;. Program will exit.
Exception in thread "main"
I am using Intelli IDEA 10.0.3
Build #IC 103.288 built on April 2011
JDK 1.6.0_21
Do you have any advices?? Thanks
Looks like you have spaces between your CLASSPATH entries. That won't do; remove them.
UPDATE:
I downloaded PMD and managed to make it run. I followed the directions that you posted, replacing the path to PMD with my own. I'd recommend not using a path that has spaces in it.
The one thing that was balky was %JAVA_HOME%, so I replaced it with the hard-wired path to my Java /bin. Once I did that, all was well.
I'd ask why you think PMD is better than the inspector tools built into IntelliJ? I'd rather check boxes to set rules than have to do all the nonsense that PMD requires.
Once I was satisfied that I could make it work I deleted it. I'd rather run Inspector.
I am working in a "biggish" Maven/Java project and cannot make sense of an error I am getting when running the app (it compiles OK). The error code I get is:
java.lang.NoClassDefFoundError: Could not initialize class com.sun.management.OperatingSystem
at com.sun.management.OSMBeanFactory.getOperatingSystemMXBean(OSMBeanFactory.java:30)
at sun.management.ManagementFactory.getOperatingSystemMXBean(ManagementFactory.java:100)
at sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:308)
at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504)
at com.sun.xml.internal.ws.server.JMXAgent.<init>(JMXAgent.java:49)
at com.sun.xml.internal.ws.server.JMXAgent.getDefault(JMXAgent.java:77)
at com.sun.xml.internal.ws.server.WSEndpointImpl.<clinit>(WSEndpointImpl.java:84)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
From the look of it, it seems the VM is not finding the "com.sun.management.OperatingSystem" class, but after googling around I cannot find out where is that class supposed to be located.
Any hints?
EDIT: Running with JRE JDK 1.6.0_18 (JAVA_HOME=C:\Program Files\Java\jdk1.6.0_18)
It might not be what's causing your problem, but errors like the one you are seeing can sometimes occur when the JDK is stored under "Program Files". Java doesn't like spaces in the filesystem path.
com.sun.management is an undocumented java package. The class OperatingSystem is the implementation for the OperatingSystemMXBean. If you download the Javasource code you will be able to see the class there.
As far as the location of this file, it should be in your standard JRE package. Make sure your application is pointing to the proper JRE. In Java 5/6, the class can be found in the rt.jar file.
If you want to confirm the file is there, Open the jar in program like JD-Gui and have a look around the Jar to confirm.
Looking at the javadocs for Java 6 and 7, it appears that OSMBeanFactory (which is in your stack trace) was added in 7.
Monitoring and Management Interface for the Java™ Platform (6)
Monitoring and Management Interface for the Java™ Platform DRAFT ea-b120 (7)
I am deploying a web application based on GWT. When I compile, I don't get any errors, but in runtime, I get this one (not complete stack trace):
java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
at org.gvsig.remoteClient.sos.SOSClient.<init>(SOSClient.java:47)
at com.uji.project.server.ConnectServiceImpl.makeConnection(ConnectServiceImpl.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by:
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
I have read on this website that that is probably caused if one or more classes are not available on running time but, as seen, the error is caused by some problem with the XML parser, but I have the XML parser included in my lib folder. In detail, in the project's lib folder, it is possible to find 3 JAR files: gwt-maps.jar, gwt-servlet.jar, and kxml2.jar*.
If I open "kxml2.jar" file I can see folder org that within has xmlpull folder, that within has v1 folder and finally XmlPullParserException.class.
So...why on runtime do I not have this class available if it is included on the lib folder?
In appengine classes can only access to the classesof the JRE which are in this whitelist. If this jar is using another class of the JRE it won't be included in runtime.
Here you can read that "XML processing APIs including DOM, SAX, and XSLT" are compatible with appengine. Maybe xmlpullparser is not compatible, but I'm not sure.
Finally a colleague told me the solution to this runtime error! :D
When a GWT application is deployed, many files are copied under a small file structure (pending from ) that contains all classes, libraries and other files that are needed on runtime.
For some reason, if you don't tell on purpose Eclipse to copy (on compile/deploy time) a specific library into that PATH, the application will not find on runtime that library and will raise an error.
Solution (for me) was as simple as copying by hand that library into that folder: In my case was copying "kxml2.jar" under "C:\gwt-2.1.0\SOSProject\war\WEB-INF\lib". I restarted the application and just worked. :D
I hope this patch/solution will help others to solve this annoying problem under GWT!
Try this
Window->Preferences->Java Build Path->Add Jars
Navigate to your project/lib, select kxml2.jar Hit OK.
In the end, what I did was to start again from the beginning: In the same workspace I had different projects and maybe there were, let's say, interferences between them.
So, I unzipped again the GWT SDK, start a new project, copied the original source code on the new project, deployed it and on runtime, now I am not getting that weird ClassNotDefFound error. Now I am getting another one, but that is another issue! Thanks to all.