This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I run from command line program created by Eclipse?
I am getting below exception when I try to run class file from command prompt,the same I run in eclipse,there I don't get any error
Trying to run from the same folder
Exception in thread "main" java.lang.NoClassDefFoundError: testClient (wrong nam
e: com/mindcraft/queryExecutor/actionclass/testClient)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Could not find the main class: testClient. Program will exit.
I suspect you're running in a directory of com/mindcraft/queryExecutor/actionclass
Instead, you should be running in the root directory (i.e. the parent of com), like this:
java com.mindcraft.queryExecutor.actionclass.testClient
run the .class file from root directory with full name space. i.e, if your class is in com.test package as com.test.App.java in your src then on compiling its class file will have a qualified class name as full name. i.e, com.test.App.class
So from your root/src run it as java com.test.App in command line.
Before posting a question kindly Search enough if the question has been asked before or even better answered before. When i Googled i found a similar question being answered. Hope the link provides you the answer you are looking for
Related
I recently moved a project from one machine to another but I am now given an error when attempting to run java files on the new machine. I'm trying to run a java file from part of an Android project in command prompt but I am given an error. The file compiles okay but fails to run. Here is the error I am given;
Exception in thread "main" java.lang.NoClassDefFoundError: ChatServer (
e: edu/UTEP/android/ChatServer)
at java.lang.ClassLoader.defineClass1(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.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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Any ideas why I am receiving this error?
Your ChatServer is having a package declaration of edu.UTEP.android in the top. So either you need to remove that package declaration recompile your java file again and run it
(or)
you need to create folder structure like this
CurrentDir/edu/UTEP/android/
Keep your java file in android folder and invoke java ChatServer from CurrentDir. Any of these two will solve the issue :-)
For more info on packages, you can refer to my previous answer on a similar issue here
Make sure that the .jar that provides ChatServer is in your runtime Classpath.
This issue rise when jvm don't file class path.
check where u have placed your jar file or lib folder.
Move to that directory then run javac and then java .
Issue will be resolved.
I have a class file that creates a monthly report by talking with a MySQL database, it also creates graphs as JPEGs (Hence why it must be in the TomCat Directory and not compiled as an app)
The front end simply uses this data to display a "Monthly Report".
My problem is I cannot figure out how to run the class file once it's compiled from the server. The Class file works 100% in eclipse and then automatically publishes to a server (locally).
I'm trying to compile the JAVA class file and run it locally on a Windows machine, the live version is on a Linux environment.
Here's what I have so far:
So compiling the class and running it: (Tried with -cp as well)
java C:\p_sys\tomcat\webapps\PR\WEB-INF\classes\au\gov\vic\pdd\PPA createreportsmonthly
We get the following error:
C:\p_sys\tomcat\webapps\PR\WEB-INF\classes\au\gov\vic\pdd\PPA\createreportsmonthly>java CreateMonthlyReportTable
Exception in thread "main" java.lang.NoClassDefFoundError: CreateMonthlyReportTa
ble (wrong name: au/gov/vic/ppd/PPA/createreportsmonthly/CreateMonthlyReportT
able)
at java.lang.ClassLoader.defineClass1(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.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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Can anyone help me out here?
* EDIT
Some clarity
CreateMonthlyReportTable.class is located within:
C:\p_sys\tomcat\webapps\PR\WEB-INF\classes\au\gov\vic\pdd\PPA\
have you tried
java -cp C:/p_sys/tomcat/webapps/PR/WEB-INF/classes<space> au.gov.vic.pdd.PPA.CreateMonthlyReportTable
should be a space character
Well, I exported my application into JAR with eclipse, but now whenever I try running it I get the: "A Java Exception has occurred". When I try to run it through command line it says:
C:\Users\Arturas>java -jar D:\Dropbox\EclipseWorkspace\Exports\Dantracio_skaiciu
oklis3.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widge
ts/Composite
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.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite
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
C:\Users\Arturas>
Any solutions to this? I just hate java for this... It never works on desktops when you want it to... sorry I'm really stressed out from this, I'm overreacting...
Any ideas what could cause this? I doesn't work on other computers as well. Right now it's using Java 1.7. And the application runs perfectly on Eclipse.
You need to get your dependencies. Looks like you are depending on swt, which is not part of the core java language. You'll need to get all the third party jars that you depend on and include them in your classpath. It runs perfectly on eclipse because eclipse takes care of setting up the classpath for you.
You can set the classpath in your manifest file as described in the documentation, or you could include a script to start your application that will use the -cp command when running the jar, or you can use something that will package everything into one monster jar like the solutions to this question.
Hi I have made a runnable JAR file useing export option on eclipse. However, when I go to run the file via command prompt i get the following
Exception in thread "main" java.lang.NoSuchMethodError
at org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStream(RsrcURLConnection.java:43)
at java.net.URL.openStream(Unknown Source)
at sun.misc.URLClassPath$Loader.getResource(Unknown Source)
at sun.misc.URLClassPath.getResource(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 java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Does any one have any ideas as to what im doing wrong? pretty new to the whole creating runnable files etc.
Your jar is compiled with a newer version of java than the computer you are running it on.
Extract the jar file look for the file META-INF/MANIFEST-MF. This file should have an entry
Main-Class : <you fully qualified classname having main method>
Check if the class you mentioned as Main-Class has a main method (public static void main(String[] arg))
Every program I run in java gives similiar error.
This is a helloworld program:
Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong nam
e: helloworldapp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Could not find the main class: helloworld. Program will exit.
The class file helloworld.class contains a class called helloworldapp.class. The only real reason for this that I can think of is that you manually renamed the .class file.
That won't work! A class called helloworldapp must be found in a .class file called helloworldapp.class.
If you want to change the name of the class, rename the .java source file, edit the class definition and recompile it.
Try this one:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
Read this tutorial about this problem.
How do you start the Java program? Are you passing the arguments correctly? Pay attention to the class path. If you have helloworld.java file and have compiled it to helloworld.class, you should run it like this (from a command prompt in the same directory the class file is located):
java -cp . helloworld