Blog / News

Posted on by Matt

Gotta love open source … I fixed it myself

I’m currently using the excellent Eclipse Java IDE for development work, and using the Jetty Launcher plugin to enable firing up the Jetty web server within Eclipse. It allows you to debug your web application directly in the IDE, making Java web development much smoother.

Unfortunately the current version of the Jetty Launcher does not work with the latest Jetty release (5.1), and Jetty 5.0 doesn’t seem to be available for download anymore. I searched the issue database at SourceForge and found that the issue had been reported by Marino Jonsson, and he suggested a possible fix. But there was no response from the project owner. The plugin is open source, so I figured I should get the source, code up the fix and build the project for myself.

I haven’t done any Eclipse Plugin development, so it took some fiddling with the Ant build.xml to get the plugin to build (the Eclipse jars could not be found when compiling). The result is a jettylauncher.jar that you can drop into your Jetty Launcher 1.2.1 directory and overwrite the old one (in [eclipsedir]/plugins/com.iw.plugins.jettylauncher_1.2.1).

Download the fixed Jetty Launcher (jettylauncher.jar)

If you’re interested in what I changed, here’s the unified diff …

diff -u -r1.9 Utils.java
--- Utils.java	29 Aug 2004 16:42:37 -0000	1.9
+++ Utils.java	17 Feb 2005 12:21:53 -0000
@@ -29,6 +29,8 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -303,7 +305,8 @@
*/
public static String getJettyVersionString(File jarLocFile)
throws MalformedURLException, ClassNotFoundException,
-		InstantiationException, IllegalAccessException, NoSuchFieldException
+		InstantiationException, IllegalAccessException, NoSuchFieldException,
+        NoSuchMethodException, InvocationTargetException
{
ClassLoader currentClassLoader = null;
currentClassLoader = Thread.currentThread().getContextClassLoader();
@@ -314,10 +317,20 @@
URLClassLoader jarClassLoader = URLClassLoader.newInstance(
new URL[]{jarLocFile.toURL()}, currentClassLoader);
Class versionClass = jarClassLoader.loadClass("org.mortbay.http.Version");
-		Object version = versionClass.newInstance();
-		Field versionImplField = versionClass.getField("__VersionImpl");
-		String versionString = (String)versionImplField.get(version);
-		return versionString;
+
+        String versionString;
+
+        try {
+    		Object version = versionClass.newInstance();
+    		Field versionImplField = versionClass.getField("__VersionImpl");
+    		versionString = (String)versionImplField.get(version);
+        } catch (NoSuchFieldException e) {
+            // This must be Jetty 5.1+
+            Method method = versionClass.getMethod("getImplVersion", null);
+            versionString = (String) method.invoke(null, null);
+        }
+
+        return versionString;
}

/**



This entry was posted in General. Bookmark the permalink.


Comments

  • Elifarley

    Well, just wanted to say thanks for your fixed jar !

  • Elifarley

    Just tried to open the preference page for your modified Jetty Launcher, but then I got this error:

    Plug-in com.iw.plugins.jettylauncher was unable to load class com.iw.plugins.jetty.launcher.JettyLaunchTabGroup.

    java.lang.ClassNotFoundException: com.iw.plugins.jetty.launcher.JettyLaunchTabGroup
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:404)
    at org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(AbstractClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:307)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:336)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1313)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:131)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:124)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:113)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupExtension.newTabGroup(LaunchConfigurationTabGroupExtension.java:164)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager.getTabGroup(LaunchConfigurationPresentationManager.java:135)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer$6.run(LaunchConfigurationTabGroupViewer.java:728)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.createGroup(LaunchConfigurationTabGroupViewer.java:743)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.showInstanceTabsFor(LaunchConfigurationTabGroupViewer.java:624)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.displayInstanceTabs(LaunchConfigurationTabGroupViewer.java:516)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer$5.run(LaunchConfigurationTabGroupViewer.java:473)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.inputChanged(LaunchConfigurationTabGroupViewer.java:490)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.setInput(LaunchConfigurationTabGroupViewer.java:454)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.handleLaunchConfigurationSelectionChanged(LaunchConfigurationsDialog.java:775)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog$2.selectionChanged(LaunchConfigurationsDialog.java:585)
    at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:159)
    at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:616)
    at org.eclipse.core.runtime.Platform.run(Platform.java:747)
    at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:157)
    at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1394)
    at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:693)
    at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:718)
    at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:180)
    at org.eclipse.jface.util.OpenStrategy.access$400(OpenStrategy.java:33)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:324)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:954)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2595)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2298)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:668)
    at org.eclipse.jface.window.Window.open(Window.java:648)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.open(LaunchConfigurationsDialog.java:419)
    at org.eclipse.debug.ui.DebugUITools$1.run(DebugUITools.java:381)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
    at org.eclipse.debug.ui.DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUITools.java:385)
    at org.eclipse.debug.ui.DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUITools.java:327)
    at org.eclipse.debug.ui.actions.OpenLaunchDialogAction.run(OpenLaunchDialogAction.java:80)
    at org.eclipse.debug.ui.actions.OpenLaunchDialogAction.run(OpenLaunchDialogAction.java:99)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:276)
    at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:206)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:915)
    at org.eclipse.jface.action.ActionContributionItem.access$500(ActionContributionItem.java:47)
    at org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:785)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:954)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2595)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2298)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
    at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
    at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
    at org.eclipse.core.launcher.Main.run(Main.java:704)
    at org.eclipse.core.launcher.Main.main(Main.java:688)

    eclipse.buildId=200409161125
    java.version=1.4.2-p7
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=freebsd, ARCH=x86, WS=gtk, NL=en

  • Matt Doran

    That’s wierd. It works for me. Looks like it can’t even find the plugin classes. Did you drop the new version of the plugin into the /plugins/.. directory? If you drop the old one back in, does it work again?

  • Elifarley

    First, I copied your jar over the old one and got the error above.
    Now, I copied the original jar over your jar and got the old error (‘/blah/blah/blahblah/jetty-5.1.2 is not a valid Jetty installation directory’).

    In case I manage to fix it, I’ll let you know.

  • Matt Doran

    Hmmmm… I’m using Eclipse 3.0.1 (on Windows). Are you using a different version?

  • Elifarley

    I’m using Eclipse 3.0.1 too, on FreeBSD 5.3

  • Wayland Chan

    This patch isn’t working for me when using Eclipse 3.1M4 and Jetty 5.1.2

    Same error about “not a valid Jetty installation directory”.

  • Mark Stang

    Hi,
    Does anyone have a fix for this on a non-windows platform?

    thanks,

    Mark

  • Hi, this is the current maintainer of jettylauncher. Sorry guys! I totally missed the bugreports. I am used to getting email notices whenever new issues are reported, but that didn’t happen this time. Furthermore I have been very bussy with another project (Wicket), so I did not check the jettylauncher site for a while.

    Anyway, there is a new build now, available at both the SF download site and the eclipse update site (http://jettylauncher.sourceforge.net/updates). The new build supports Jetty 5.1.x now, and – as you suggested – I put in another catch so that jettylauncher won’t fail when it does not regconize the version of Jetty. Furthermore, it supports Eclipse 3.1 M6 (M6 broke some stuff) while still supporting 3.0.x (the patch that was submitted as part of the bugreport for M6 only supports 3.1).

    If you have any problems with the new build, pls send a note to the email list, or to me directly.

    Cheers,

    Eelco Hillenius

Blog Categories & Archives