This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't execute .class file created in NetBeans

 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I created this Swing java program in NetBeans and successfully compiled and run it (in NetBeans). However when I try to execute the program from the command prompt I keep getting some errors:

I typed:
java -classpath "c:\Program Files\Java\Java Files" Password_Generator

Exception in thread "main" java.lang.NoClassDefFoundError: org\jdesktop\layout\GroupLayout$Group

Anybody has an idea why this is so?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you take a look at the source code for your Swing app,

netbeans tends to put package imports in the files which you

created with netbeans...

if this is the case, just comment/delete those out, and try
to compile and run it then, should work


Justin
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But aren't those the codes that make up the actual GUI? If I remove them wouldn't it mess the GUI up? I mean there's a reason they are there right?
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GroupLayout is the class used by Netbeans to create GUIs using Matisse. GroupLayout is standard in the JDK as of Java 1.6 (6). However prior to that you will need to make sure swing-layout-1.0.jar is on your classpath.
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er... So does that mean I should really delete those code or is there something I need to do with the way I execute the program?
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I'm going to assume you actually used GroupLayout to make your GUI, so its absolutely required (you most likely did if you used Netbeans visual GUI makes).

The good news all you have to do is add swing-layout-1.0.jar to your classpath. your current -classpath option adds the classes in the "c:\Program Files\Java\Java Files" directory to your classpath you just need to expand this to include swing-layout-1.0.jar like -classpath "c:\Program Files\Java\Java Files";c:\PATHTOJAR\swing-layout-1.0.jar

swing-layout-1.0.jar is somewhere in the netbeans directory.

Are you going to want to eventually distribute this? Then you should look at packaging your code in a jar with a MANIFEST.MF file and include your dependencies with it. Or use java web start. Or some third party installer. Or...
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know if you want to do it, but i had an assignment that
was originally created in netbeans, there was meaningless package imports..

remove the package imports that have to do with the file/classes you created...

and just make sure all the files are in the same directory, they should
compile and run fine...

i dont know about all that other stuff, but it always works for me...
i like visual studio better, netbeans/eclipse arent that great

[removed encouragement to use pirated software - Ilja]

lol Justin
[ October 22, 2006: Message edited by: Ilja Preuss ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol dont remove

import java.awt.*;
import java.awt.event.*;
import java.swing.*;

only the package declaration...

Justin
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty cool. Now I have an executable jar file that can run the program outside NetBeans. It's a little annoying though to always have this swing-layout-1.0.jar in the same directory as my jar file. Is this really how it should be or is there a way for the program to run on its own?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make your GUI without NetBeans...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic