java SWT application giving error while executing jar file
Asif Usman
Greenhorn
Joined: Mar 16, 2009
Posts: 12
posted
0
HI all,
I had created one SWT(java) application using net beans IDE. As i set all the jar files which is required to run this application. its running in development platform. but when i build this application in net beans and try to execute the jar file its giving error.
C:\Documents and Settings\Asif>java -jar "C:\Documents and Settings\Asif\My Documents\NetBeansProjects\JavaApplicatio\dist\JavaApplication2.jar"
following is the error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/events/MouseListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at javaapplication2.DragAndDropExample.main(DragAndDropExample.java:23) Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.events.MouseListener at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 13 more
And Here is the Source code.
its having two files.
1) DragAndDropExample.java
package javaapplication2;
public class DragAndDropExample {
public static void main(String[] args) {
NewClass ob=new NewClass();
ob.getthatworkdone();
}
}
public class NewClass implements org.eclipse.swt.events.MouseListener
{
public int count=0;
TreeItem itemSecond;
Shell shell;
public Display display ;
Text newtext;
Tree tree1;
// Point point;
static StringBuilder fulltext=new StringBuilder();
Text displaytext;
JPanel panel;
int countofresult=0;
public NewClass()
{
}
public void getthatworkdone()
{
try
{
display = new Display();
shell = new Shell(display,SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.MAX | SWT.MIN);
panel=new JPanel();
// shell.setLayout(new FillLayout());
shell.setText("Drag and Drop");
shell.setSize(100,100);
shell.setLocation(0,0);
Button b1 = new Button(shell, SWT.BOTTOM | SWT.BORDER);
b1.setLocation(0,400);
b1.setSize(100,40);
b1.setText("Result");
b1.setVisible(true);
final Tree tree = new Tree(shell, SWT.BORDER);
newtext.setText(fulltext.toString());
countofresult+=1;
System.out.print("total result attempt is " + countofresult);
// shell.pack();
// shell.open();
break;
}
}
});
shell.setSize(1000, 700);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
}
catch(Exception expr)
{
}
}
public void mouseDoubleClick(MouseEvent e) {
// Nothing to do
try
{
final TreeEditor editor = new TreeEditor(tree1);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
final TreeItem item3 = tree1.getSelection()[0];
final Text text = new Text(tree1, SWT.NONE);
text.setText(item3.getText());
text.setFocus();
FontDialog fd1 = new FontDialog(shell, SWT.NONE);
fd1.setRGB(new RGB(0,0,200));
FontData defaultFont2 = new FontData("Courier",11,SWT.BOLD);
fd1.setFontData(defaultFont2);
text.setFont(new org.eclipse.swt.graphics.Font(display, defaultFont2));
text.setForeground(new Color(display, fd1.getRGB()));
text.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
item3.setText(text.getText());
text.dispose();
for (int i = 0; i < items.length; i++) {
System.out.println("to check its loop condition");
traverse(items[i]);
}
}
catch (Exception ex)
{
}
}
}
Please help me to run this application using jar file.
Thanks in advance..
Thanks!
Asif
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35223
7
posted
0
I suspect that even if you used code tags -and you absolutely should do that- this would still be too much code to ask anyone to go through and try to understand.
This always a red flag, though - you must do proper error handling:
catch(Exception ex)
{
}
C:\Documents and Settings\Asif>java -jar "C:\Documents and Settings\Asif\My Documents\NetBeansProjects\JavaApplicatio\dist\JavaApplication2.jar"
Does this jar file contain the MouseListener class that's missing? If not, then you need to add that to your classpath.