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.