2

I modified a Java code in Eclipse on my laptop with a Windows O.S. Now I have to run the code on a linux O.S. via SSH. I copied all the files and I tried to compile the code. The compilation went well, so there were no errors in the code. Anyway, when I tried to run it, the following errors appeared on the shell:

  [ac6411@epigenetic models]$ java TanaModel
    Exception in thread "main" java.lang.NoClassDefFoundError: TanaModel (wrong name:     models/TanaModel)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        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)

Do you know what kind of the problem is?I'm new in Java coding, so I don't know how to solve it. Thank you.

2
  • 1
    Did you compile the code on the Linux box? Is java set up correctly on it (try java -version)? Commented Feb 9, 2012 at 22:38
  • What is the name of file and class? (please be accurate with case) Commented Feb 9, 2012 at 22:40

4 Answers 4

2
wrong name:     models/TanaModel

This means it expected to find TanaModel.class under the models directory, but found it somewhere else (maybe the current directory?). Put the class file in a the models directory, and run it as

java models.TanaModel

Java expects class files to be organized in directories that mirror the package structure you used in your source code.

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

6 Comments

I tried but it give me the following message: [ac6411@epigenetic models]$ java models.TanaModel Exception in thread "main" java.lang.NoClassDefFoundError: models/TanaModel
You're getting closer, then. Make sure the current directory (".") is part of your classpath (usually set up in the CLASSPATH environment variable).
I modified the CLASSPATH so that now it refers to the directory in which i put all the files but it gives me the same problem. Have you got ideas?
Please post your exact CLASSPATH and the command that you are using to start your program. Remember also that CLASSPATH uses ":" in Unix and ";" in Windows.
This is the path: PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/local_machine/bin:/usr/local_machine/sbin:/home/ma/a/ac6411/bin:/home/ma/a/ac6411/Cairoli_Thesis:/home/ma/a/ac6411/Cairoli_Thesis:/home/ma/a/ac6411::/home/ma/a/ac6411/bin This is the command line: [ac6411@epigenetic models]$ java models.TanaModel Exception in thread "main" java.lang.NoClassDefFoundError: models/TanaModel This is the path of the files where the code is put: [ac6411@epigenetic models]$ pwd /home/ma/a/ac6411/Cairoli_Thesis/tana_java/src/models
|
1
java.lang.NoClassDefFoundError: TanaModel (wrong name: models/TanaModel) at 

What command did you run, I'm guessing java TanaModel ? Most likely your TanaModel is declared to be in package models;

Try calling it like this:

java models.TanaModel

2 Comments

I tried but it give me the following message: [ac6411@epigenetic models]$ java models.TanaModel Exception in thread "main" java.lang.NoClassDefFoundError: models/TanaModel
Please post some more info about your code, directory/package layout and code snippets.
1

If it is a Eclipse security issue, this would help.

//Java Code

try 
{
    AccessController.doPrivileged(new PrivilegedAction<Object>() 
    {
        public Object run() 
        {    
                 try 
                 {
                 // Insert code here to do required action (get or open file)
                 }
                 catch (Exception e) 
                 {
                 // Insert code to catch exception from trying to do above action
                 }
        }    
    }
    );
}
catch(Exception e)
{
// Insert code to catch failed doPrivileged()
}

Comments

0

When you try to run your program, try calling it like this:

java models.TanaModel

1 Comment

I tried but it give me the following message: [ac6411@epigenetic models]$ java models.TanaModel Exception in thread "main" java.lang.NoClassDefFoundError: models/TanaModel

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.