0

I wrote and tested a small Java program using Eclipse. I'm now trying to deploy it on a Windows 7 box and Java cannot find the class. I copied the class file to C:\dxtester\classes. I'm trying to run it from the dxtester directory with: C:\dxtester>java -classpath classes;. dxtester

This produces this exception which I think I understand. Java examined the class file and is prompting me to provide the fully qualified name.

Exception in thread "main" java.lang.NoClassDefFoundError: dxtester (wrong name:
 dxtester/dxtester)

If I use the FQN I get

C:\dxtester>java -classpath classes;. dxtester.dxtester
Error: Could not find or load main class dxtester.dxtester

The application is a simple test driver where everything is done in main().

package dxtester;
public class dxtester {
    public static void main(String[] args) {

This seemed like an extremely simple thing to do but I'm completely baffled. What am I missing?

2
  • Your class is called dxtester and is also in a package called dxtester, but you haven't compiled it appropriately to be in the right directory. Ideally, you should use different names to start with (dxtester doesn't follow Java naming conventions, for example) and make sure the file hierarchy follows the package hierarchy. Commented Jun 24, 2013 at 15:08
  • Thanks Luiggi! The problem was not the compilation but the deployment. The deploy script did not create the correct dxtester directory for the class file. Commented Jun 24, 2013 at 15:14

1 Answer 1

1
  1. Your current directory is dxtester;
  2. in this directory you have dxtester.class (I presume);
  3. your classpath is the current directory.

This setup is wrong: your classpath must be the base directory such that package names correspond to its subdirectories. In your case you should cd to C:\ and repeat the command; ideally, however, you will have your package structure in a dedicated directory instead of the root.

I should also mention that class names should be in CamelCase.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.