Wicket Jetty integration with Start.java from quic

2019-09-08 15:40发布

问题:

I just checked out my (working) wicket project to a new development machine and all of a sudden I get this error whenever I try to start jetty.

java.lang.NoClassDefFoundError: net/unbewaff/Start
Caused by: java.lang.ClassNotFoundException: net.unbewaff.Start
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main" 

The class file is there and eclipse rebuilds it, when I delete the file. The class not found is the one containing the main method I'm trying to run and supposed to start the embedded jetty. Even cd'ing to the directory, seeing the file and typing java Start.class onto the command line gives the same error with a slightly different wording.

Wicket and embedded jetty - classNotFoundException seems to be related but isn't as the error described there happens later and after loading the Start-class.

What I did:

  1. checked out the project from repository
  2. ran mvn clean install
  3. ran mvn eclipse:eclipse
  4. created the project in eclipse
  5. tried to start the app
  6. hit the wall

I honestly don't think that this is a wicket or jetty problem, but since they're both involved somehow, I hope there is someone who had and solved this problem...

Things I checked:

  • The file is really really there, it's current and readable
  • I tried to have a look at the bytecode calling javap Start.class without luck (ERROR:Could not find Start.class)
  • opened the class file using a text editor (looks 'propperly binary')
  • running mvn jetty:run (Starts and runs jetty along with the webapp)

What helped:

As Martijn suggested, I grabbed a fresh quickstart and compared the Start-classes. The one from the quickstart worked just fine and the only differences my diff-tool and I could find were changed ports on the connector but the class from the quickstart accepted these without any issues. Then I copied the class from the quickstart to my project and it worked fine under the name of Dummy.java. After deleting the offending class, cleaning the workspace and renaming it to Start.java it stopped working. Renaming it back to Dummy put it back to working conditions.

So I got a working workaround, while still not knowing, what was wrong.

回答1:

There is something you reference in your Start class that is not being found: it is a ClassDefNotFoundException, which is one of the hardest errors to solve. It prevents the class loader from loading your Start class.

The best way to go forward would IMO be to generate a new quick start, run it, and move stuff from your own start class to the quick start one until it breaks.