ClassNotFoundException

19 views
Skip to first unread message

Daniel Smith

unread,
Aug 13, 2012, 4:53:07 PM8/13/12
to sc2ge...@googlegroups.com
I'm just trying to get a Hello World plugin working but I cannot figure out the cause of this error because I do not know much about Java.

Plugin:   http://tysmith.net/HelloWorld_Sc2Gears.zip
Error:   
Failed to start plugin "HelloWorld_Sc2Gears"!
java.lang.ClassNotFoundException: net.tysmith.HelloWorld_Sc2Gears
at java.net.URLClassLoader$1.run(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 java.lang.ClassLoader.loadClass(Unknown Source)
at hu.belicza.andras.sc2gears.services.plugins.PluginControl.startPlugin(PluginControl.java:140)
at hu.belicza.andras.sc2gears.services.plugins.PluginManager.startEnabledPlugins(PluginManager.java:168)
at hu.belicza.andras.sc2gears.ui.MainFrame.<init>(MainFrame.java:366)
at hu.belicza.andras.sc2gears.Sc2gears.main(Sc2gears.java:129)



András Belicza

unread,
Aug 13, 2012, 6:43:06 PM8/13/12
to sc2ge...@googlegroups.com
Hi,

The problem is with the plugin.jar.

First you have to compile the Java file. use the "javac" command for this.
You have to place the .java file to a folder matching the package declaration. For example if your package is "net.tysmith", it has to be in a package of "net/tysmith". The package must not contain the class name, so remove that from the package declaration.

If the javac command succeeds, you will have a ".class" file. That has to be packaged in the jar file. You can use the "jar" command to make the jar file.

Today's IDE software can do all this for you. I recommend Eclipse.

Daniel Smith

unread,
Aug 13, 2012, 7:11:27 PM8/13/12
to sc2ge...@googlegroups.com
Hello,

Thanks for the fast response.  I am using eclipse.  Here is my eclipse workspace folder: http://tysmith.net/tmp/HelloWorld_Sc2Gears.zip

I have eclipse set to build automatically.  

I have done the following things with no results:
1. Use eclipse to export a JAR file
2. >jar cf HelloWorld_Sc2Gears.jar HelloWorld_Sc2Gears.class

The class file I JAR'd was in workspace/bin/net/tysmith/HelloWorld_Sc2Gears/HelloWorld_Sc2Gears.class

Is there some option I need to make sure I set with eclipise?

Thank you,

Ty

András Belicza

unread,
Aug 14, 2012, 6:54:42 AM8/14/12
to sc2ge...@googlegroups.com
The problem is the class file folder.

To make it clear: if you have a java class which has a package declaration of "net.tysmith.HelloWorld_Sc2Gears" the class file has to be in a folder of "net/tysmith/HelloWorld_Sc2Gears".

When it is exported to a jar file (the jar file is a normal zip file), the class has to be placed in the same folder.
So the jar has to contain 2 files:
/net/tysmith/HelloWorld_Sc2Gears/HelloWorld_Sc2Gears.class
/META-INF/MANIFEST.MF

András Belicza

unread,
Aug 14, 2012, 7:01:13 AM8/14/12
to sc2ge...@googlegroups.com
Also there is another error.

The Sc2gears-plugin.xml file must list the main class of the plugin.

The main class is the class name plus the full package name. In your case:
net.tysmith.HelloWorld_Sc2Gears.HelloWorld_Sc2gears

(In the example you sent the class name is missing from the end, you only entered the package name.)

Daniel Smith

unread,
Aug 14, 2012, 1:44:10 PM8/14/12
to sc2ge...@googlegroups.com
You fixed it.  Thanks a lot.
Reply all
Reply to author
Forward
0 new messages