Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem executing jar file

Status
Not open for further replies.

brownie124

Programmer
Sep 19, 2002
61
0
0
US
Guys, I am getting the following error when I try to run my program from a jar file. Note: this is not the main class. I created my jar file specifying a manifest which specifies Main-Class. That works great. However, I am not able to get any further. The very next class that it tries to instantiate, I receive the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: foo

Thanks,
- Brownie
 
Hi,
Provide some more information what you are exactly trying to do.

 
Trying to distribute one jar file and have people execute my program from there.

java -jar my.jar

Like I said in the initial posting, my initial class seems to get instantiated (that is in the manifest) but as soon as another class tries to get instantiated it fails with the error I posted earlier.

Do I have to have all the classes in the manifest?

- Brownie
 
No, you don't need to have all your classes in the manifest.

Open up the jar file with WinZip or equivilant and make sure your other classes are in there, and the directory structure for your packages are in there as well.

Is "foo" a class in your application? If not, is it in another jar file that would normally be on the classpath? Or does it use a class from another jar file?

BTW, I use JDeveloper (free), which has a very nice wizard for building executable jar files.
 
No, Foo is not my application class. It is the class I am trying to instantiate from within my application class (MyClass). I think I know what the problem is. Foo is a class that is literally coded in the same file as my class app (example below). I think if I were to break it out into a separate file it would be fine. However, this seems to point to the fact that if it were in a manifest, it would work. Is this true? I haven't really used manifests before.

Contents of MyClass.java:
Code:
public class MyClass
{
    // Lots of code here.

    Foo foo = new Foo();
    
}// End of class MyClass
class Foo
{
    Foo()
    {
        // Code here.
    }
    // Lots more code here.
}// End of class Foo

- Brownie
 
I created this test program:

Code:
public class Class1 
{
   public Class1()
   {
      Foo foo = new Foo();
   }

   public static void main(String[] args)
   {
      Class1 class1 = new Class1();
   }
}

class Foo
{
   public Foo()
   {
      java.awt.Frame f = new java.awt.Frame();
      f.show();
   }
}

Here's the contents of my manifest file:

Manifest-Version: 1.0
Main-Class: Class1
Created-By: Oracle9i JDeveloper 9.0.3

The jar file ran with no problem. Why don't you post your actual code?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top