Domanda

I keep getting NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext when trying to launch HTTP Preview in Eclipse Juno with Web Tools Platform.

Steps to reproduce:

  1. Download, extract and launch Eclipse Juno
  2. Install "Eclipse Web Developer Tools" via "Install new Software..." from http://download.eclipse.org/releases/juno
  3. Create new "Static Web Project"
  4. Create HTML File inside new Project
  5. Right click Project -> Run as -> Run on Server -> HTTP Preview at localhost -> Finish

At this point I keep getting NoClassDefFoundError no matter what I do.

What I already tried:

  • tried with 32/64 bit Eclipse
  • tried with Windows XP, Windows 7
  • tried installing all tools from "Web, XML, Java EE and OSGi Enterprise Development"
  • tried installing "Eclipse Jetty" and "Run-Jetty-Run" from Eclipse Marketplace
  • tried different bundles of eclipse: "Eclipse IDE for Java Developers", "Eclipse Classic"

Similar questions I found:

My main environment is:

  • Windows 8 64 bit
  • Eclipse Juno (4.2.2) 64 bit
  • Web Tools Platform 3.4.2
  • JRE 7

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.getMainMethod(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.webapp.WebAppContext 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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 6 more

È stato utile?

Soluzione

You can create the patch and make it work for you in the following four phases:

Phase 1: Create a plug-in project for the plug-in you need to patch.

  1. Create a new workspace (recommended) or open an existing one.
  2. Select File -> Import
  3. Expand Plug-in Development, select Plug-ins and Fragments, then click Next
  4. In the Import As section, select Projects with source folders and then click Next.
  5. Enter (or copy & paste, no quotes) org.eclipse.wst.server.preview.adapter into ID field at the top and click Add All. This should move this one plug-in to the right pane.
  6. Click Finish to import the "org.eclipse.wst.server.preview.adapter" plug-in source into a project.
  7. Expand the root of the project and ensure it contains a folder named "src". You will only get the "src" folder if you have the "WST Server Adapter Plug-in Developer Resources" installed.

Phase 2: Apply the changes needed to update the plug-in. Since there is a bug with a patch attached that can be used to apply the changes, the following steps will take advantage of that.

  1. Open Bug 402848 in a browser.
  2. Click on the Patch v1.0 for 3.4.2p attachment link to open the patch.
  3. Starting with the second occurrence of a line starting with ---, select this line through the end of the text and copy it to the clipboard. This contains the changes to the PreviewLaunchConfigurationDelegate.java file which is where the fix is needed. You don't want the upper portion of the patch as that would change the version of the plug-in, and that would complicate things.
  4. Back in Eclipse, right-click on the "org.eclipse.wst.server.preview.adapter" project. Select Team and click on Apply Patch.
  5. Leave Clipboard selected and click Next.
  6. Ensure the "org.eclipse.wst.server.preview.adapter" project is selected, and click Next.
  7. Set the Ignore leading path name segments to 3. The "Patch Contents" window should change to have a blue left pointing arrow instead of red x indicators.
  8. Click Finish to apply the changes.

Phase 3: Create the replacement jar. Due to the approach in Phase 1, the name of this jar will be identical to your current jar, which simplifies updating the Eclipse installation.

  1. Right-click on the org.eclipse.wst.server.preview.adapter project in the Project Explorer or other navigator view and select Export
  2. Expand Plug-in Development, select Deployable plug-ins and fragments, then click Next
  3. Click the Browse button next to the Directory selection in the Destination tab followed by OK. This will set the output directory to be the same as your workspace.
  4. Click Finish to build the replacement plug-in jar. It will appear in a "plugins" folder under the root of your workspace.

Phase 4: Replace the installed plug-in jar with the fixed version.

  1. Exit Eclipse if it is running.
  2. Under the "plugins" folder of your Eclipse installation, move or rename the org.eclipse.wst.server.preview.adapter_1.1.101.v20121107_1651.jar if you don't want to overwrite it with the patched version (mentioned in step 3 below). If you have a different version, it means you aren't using Juno SR2 and hopefully you installed the "WST Server Adapter Plug-in Developer Resources" that matched your version.
  3. Copy the org.eclipse.wst.server.preview.adapter_1.1.101.v20121107_1651.jar from the "plugins" folder under your workspace and paste it to the "plugins" folder of your Eclipse installation.

You should be able to run Eclipse now with the fixed plug-in. Because the patched jar had the same version number, no additional changes are needed.

Hope it helps !

Altri suggerimenti

Likely fixed in the upcoming Kepler release in June.

http://bugs.eclipse.org/402848

Thanks nitind,

Just download the patch;

http://download.eclipse.org/webtools/patches/drops/R3.4.2/P-3.4.2-20130506185528/patches32x-P-3.4.2-20130506185528.zip

Then;

copy files to eclipse directory

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top