This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Mig Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Mig Layout" Watch "Mig Layout" New topic
Author

Mig Layout

Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
Hi, i�m using miglayout in a little project, works great when i execute my gui in eclipse 3.3, but when i export the project into a jar file, it gives me "NoClassDefFoundError: net/miginfocom/swing", i dont know how to solve it since i have added the miglayout-3.6-swing.jar to the proyect classpath.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

When running java applications outside of the IDE you still need to specify the classpath. The most common way is while executing from the command line:

java -classpath library.jar -jar app.jar

So make sure your miglayout jar file is specified in the classpath as noted above.


GenRocket - Experts at Building Test Data
Pavan Kumar Srinivasan
Greenhorn

Joined: Sep 17, 2008
Posts: 27
I think the standard jdk jar(rt.jar) is not on your classpath, considering it is not a ClassNotFoundException but a NoClassDefFoundError which your are getting.
Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
i've tried java -classpath miglayout-3.6-swing.jar -jar miproyect.jar
and also java -classpath miglayout-3.6.jar -jar myproject.jar, still not working, i have another version of the same proyect that dont use any external libraries and works fine.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37874
    
  22
You don't need rt.jar in your classpath, at least not for recent versions of Java.

One thing I have tried is copying the .jar into the current directory where you can start your application by writing java foo.bar.MyClass, then unzipping the .jar. You then have the jar folders in the same directory as your own folders, and it is a naughty cheat technique, but seems to work.
Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
I've decompressed the jar that eclipse generated, this is the dir structure:
.settings -->dir
META-INF --> containing manifest indicating the main class
controller --> dir
model --> dir
view --> dir, where the miglayout.jar is needed, so i've put the miglayout.jar here
.classpath --> file
.project --> file

Then i've created a new jar --> jar cmf META-INF\MANIFEST.MF MyProject.jar * But still have the same error message
[ November 08, 2008: Message edited by: Jorge Bendahan ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Jorge, is it possible for you to provide access to your JAR file? I'd be happy to test it out on my machine to see if I can get it working.

One thing to remember is by typing

java -classpath miglayout-3.6-swing.jar -jar miproyect.jar

you are saying that miglayout-3.6.swing.jar and miproyect.jar are both in the directory where you are running the java command from. If either are in different locations you need to provide the absolute path to either/both. So something like:

java -classpath /path/to/miglayout.jar -jar miproyect.jar
Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
i'll be happy to, give me your email address and i'll send it over.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jorge Bendahan:
i'll be happy to, give me your email address and i'll send it over.


Check your private messages.
Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
you have a new email
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ok, I think I have figured out the problem. I was running into the same problem as you were. Then I realized that we are using the MANIFEST file to specify the main class. By doing this the -classpath switch pretty much gets ignored. So you have to tell the MANIFEST file what your classpath is. After doing this, it worked for me. Your new MANIFEST file should look like this:

Manifest-Version: 1.0
Main-Class: vista.Principal
Class-Path: miglayout-3.6-swing.jar

And then, assuming miglayout-3.6-swing.jar and myproyect.jar are in the same path...

java -jar mypryect.jar

And you should be good to go.
Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
Thank you so much Gregg, now it works!
Jorge Bendahan
Ranch Hand

Joined: Apr 11, 2008
Posts: 82
Gregg actually took the time to examine the jar file and found the problem , i apologize for the code, pretty bad yet. But i'm learning, i must add threads to the gui and other major improvements. Thanks again.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jorge Bendahan:
Gregg actually took the time to examine the jar file and found the problem , i apologize for the code, pretty bad yet. But i'm learning, i must add threads to the gui and other major improvements. Thanks again.


No problem at all. Glad I could help. My biggest hurdle was not knowing spanish.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mig Layout
 
Similar Threads
Unable to connect to mySQL DB.
Is your book going to include tutorial for JFXtras library
FlowLayout issue
Coding for GUI is such a drag :(
Is MiGLayout the best layout manager?