Reputation: 1048
When I try to run my code from the command line, I get the following exception error;
X:\User temp\httpclient>java httpclient_main 10 10
Exception in thread "main" java.lang.NoClassDefFoundError: httpclient_main (wron
g name: httpclient/httpclient_main)
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)
httpclient_main.java;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package httpclient;
import java.io.DataInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**
*
* @author tsothcott
*/
public class httpclient_main {
protected String host;
protected String file;
protected int port;
protected DataInputStream in;
protected DataOutputStream out;
static double threadResult;
String get_file()
{
return this.file;
}
DataOutputStream get_outputstream() {
return this.out;
}
public static void main(String[] args) throws IOException {
InputTxt servers = new InputTxt();
threadResult = 0.0D;
SharedCell cell = new SharedCell();
if(args.length <1)
throw new IOException("Usage: HTTPClient URL Number_Thread");
int num_thread = Integer.parseInt(args[0]);
int count_interval = Integer.parseInt(args[1]);
servers.printservers();
Manufacture prod = new Manufacture(cell, num_thread, count_interval);
prod.start();
}
}
Screenshot of project structure;
Howewver, when I run it from inside NetBeans, it runs fine?
Any help would be appreciated!
Thanks
Upvotes: 0
Views: 10672
Reputation: 204
Exception in thread "main" java.lang.NoClassDefFoundError: httpclient_main
So, you ran it as java httpclient_main
. It's expecting a httpclient_main.clas
s without any package.
The class is trying to tell you that it has a package httpclient;
. You need to run it from the package root on. Go one folder up so that your class folder contains the httpclient
folder representing the package and then execute
java httpclient/httpclient_main.
Upvotes: 0
Reputation: 40036
.
in your classpath and execute the java command at X:\User temp\Tom Sothcott
, OR, have X:\User temp\Tom Sothcott
directly in your classpathjava httpclient.httpclient_main 10 10
java
command is expecting the fully qualified classname for the class containing the main method to execute.
Upvotes: 0
Reputation: 1581
java httpclient_main 10 10
It is wrong usage.Use this parameter with package name.eg.java httpclient.httpclient_main 10 10
Upvotes: 0
Reputation: 20618
According to your posted command line output, you are invoking the program from inside the package httpclient
. Your current dir is
X:\User temp\Tom Sothcott\httpclient
That is wrong. You must invoke your Java programs from the project's root directory. In this case, that will be
X:\User temp\Tom Sothcott
And of course, you must provide the fully qualified class name, as Ihsan Kocak told you.
Upvotes: 1
Reputation: 118
NoClassDefFoundError comes when class file of your code is present at compile time but not found at runtime.
Upvotes: 1