2
votes

I have a problem for embeding Jetty into my Eclipse RCP application.

In my RCP application, when user click some button, a browser will be opened and some jsp page shown. The jsp files are in a separated directory, it is a web application, which can be run in tomcat very well.

I have managed this with in a main() method like this:

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class SimplestServer
{
    public static void main(String[] args) throws Exception
    {
      int port = 8080;
      Server server = new Server(port);
      String webapp = "D:/workspace/preview"; 
      WebAppContext context = new WebAppContext();
      context.setDefaultsDescriptor(webapp + "/WEB-INF/web.xml");

      // -------
      // Sorry! I add another question in one post, I think this might be some clue
      // If I do not use setDefaultsDescriptor, I got error like this:
      // java.io.FileNotFoundException: D:\BV\eUpgrade\testEnv\eclipse4-2\org\eclipse\jetty\webapp\webdefault.xml
      // Why it does not go to my web.xml, but goes to some path like: org\eclipse\jetty\webapp\webdefault.xml?
      // And in this case, when access to jsp files, got HTTP 503 error.
      // context.setDescriptor(webapp + "/WEB-INF/web.xml");
      // ------

      context.setResourceBase(webapp);
      context.setContextPath("/preview");
      context.setParentLoaderPriority(true);
      server.setHandler(context);

      try {
        server.start();
        server.join();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
}

It works well for me if just in a main method. i.e., after Jetty started, I can access to all of the pages in my web app.

But when I put this snippet into my plugin, it does not work.

I created a sample eclipse rcp project (with the mail template), and I put the above code into my Activator.java. Then I start the eclipse application, what I saw is some error like :

...
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded interface javax.servlet.Filter  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded interface javax.servlet.Filter from org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@2a49d3b5[javax.servlet:3.0.0.v201112011016(id=4)]  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class java.lang.Object  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class java.lang.Object from null  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class com.broadvision.ssp.webflow.SetCharacterEncodingFilter from WebAppClassLoader=855125537@32f82e21  
19:01:03.762 [main] DEBUG org.eclipse.jetty.servlet.Holder - Holding class com.broadvision.ssp.webflow.SetCharacterEncodingFilter  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class java.lang.Throwable  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class java.lang.Throwable from null  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class java.lang.Exception  
19:01:03.762 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class java.lang.Exception from null  
...

It seems that only the classes in my WEB-INF\lib*.jar can be loaded, those classes in JRE cannot be loaded in runtime.

The result is:
The Jetty server is up (I checked the port is being used by javaw.exe), but all of the page returns: HTTP 404 error. The web application has not been deployed successfully.

I have read these: Embed Jetty in Eclipse RCP
Eclipse RCP plugin + embedded Jetty + JSF
https://stackguides.com/questions/12530256/eclipse-rcp-with-jetty-integration

But I cannot find the answer for my question.

Any help would be appreicated!! Thanks in advance.

1
The log you posted does not contain any error messges. Log level is set to "DEBUG" and what you posted is simply all classes and interfaces that the classloader loaded. Please scan your logfiles for real exceptions and stacktraces. Second, try to get the jetty server running with a simple index.html file first without an application and check if you can access this file with a browser.Frank
Hi Frank, thanks for your comment. In fact, I cannot see WARN/ERROR info in my eclipse console, all of the info is about DEBUG. There are as many as 386 lines for such messages. Do you want to have these messages? (I am afraid these info could confuse someone). Thanks again.LiuWenbin_NO.
Then do a the suggested test with a simple .html first. If your JSP cannot find a references class in it's classpath there would be an ClassNotFoundException.Frank
I tried, even html files cannot be accessed, returns HTTP Error 404. And if classpath issue, the error should be 500. Thanks Frank.LiuWenbin_NO.
"HTTP Error 404" means your HTTP server is listening and recieved the request, but could not deliver the requested file. This could have two reasons: The file is not reachable for the server (is it in the /web folder?) or you typed the wrong URL.Frank

1 Answers

1
votes

To get started with an embedded jetty server start with the most basic tutorials. These will guide you to serve a single static HTML file.

Once you got this working you can move on to expand stuff like serving an application.