|
From: Danijel B. <da...@zr...> - 2003-12-04 22:32:50
|
Hi all, I got stuck and I hope someone you can help me.
> I'm running jetty from code as a separate threat in my app.
> I have couple html and jsp pages which I use as gui for my app.
> I'm tiring to precompile all of my jsp pages with=20
> org.apache.jasper.JspC class and create a jar file in my Web-inf/lib
> Than I want to pack everything in a war and deploy webapp like that
> dir structure is:
> WebGui
> Web-inf
> lib
> classes
>=20
> All my pages and build.xml file are in WebGui
> All neded jar's are in lib
> web.xml is in Web-inf
> JSP pages include index.jsp page, starting page of web app.
> So far I have succeded to compile jsp pages and pack them in the=20
> jsp.jar file in lib folder.
> But now I have problem that index.jsp won't open when I start Jetty=20
> and go to http://localhost:9090/gui
> I belive that I need to put something in web.xml but I don't know=20
> what, and from what I have read in forums and doc I'm not sure do I=20
> need to leave these jsp pages in WebGui or do I delete them after=20
> Ant build.
>=20
> Here is my code for running jetty, I just instantiate this class=20
> from my main class
>=20
> import java.io.IOException;
>=20
> import org.mortbay.http.handler.ResourceHandler;
> import org.mortbay.jetty.Server;
> import org.mortbay.jetty.servlet.ServletHttpContext;
> import org.mortbay.jetty.servlet.WebApplicationContext;
> public class WebServer extends Thread {
> private Server server =3D null; // ref to web server
> private String guiResourceBase;
> private String webpath=3DSystem.getProperty("ev.home");
> public WebServer(){
> start();
> }
> /**
> * Method run
> *
> */
> public void run(){
> //GuiTree guiTree =3D new GuiTree();
> String FILE_SEP =3D System.getProperty("file.separator");
> guiResourceBase=3Dwebpath+FILE_SEP+"lib"+FILE_SEP+"gui"+FILE_SE
> P+"WebGui";
> String errors =3D null; // if no errors returns null
> server =3D new Server();
> ServletHttpContext context;
> WebApplicationContext guicontext =3D null;
> try{
> server.addListener( ":" + UiMgr.jettyPort );
> context =3D (ServletHttpContext)server.getContext("/");
> context.addServlet
> ("JSP","*.jsp","org.apache.jasper.servlet.JspServlet");
> guicontext =3D server.addWebApplication
> ("/gui",guiResourceBase);
> context.setResourceBase( guiResourceBase );
> context.addHandler(new ResourceHandler());
> }catch( IOException ioe ){
> errors =3D "Caught IO exception " + ioe;
> }catch( ClassNotFoundException cnfe ){
> errors =3D "Caught class not found exception " + cnfe;
> }catch( InstantiationException ie ){
> errors =3D "Caught instantiation exception " + ie;
> }catch( IllegalAccessException iae ){
> errors =3D "Caught illegal access exception " + iae;
> }
> if( errors =3D=3D null ){
> try{
> server.start();
> // catch( MultiException me )
> }catch( Exception e ){
> errors =3D "Caught MultiException in=20
> WebServer::run() : " + e;
>=20
> }
> }
> else {
> System.out.println("Jetty errors: "+errors);
>=20
> }
> }
>=20
> }
>=20
>=20
> And here is build.xml, didn't yet implement code for war creation:
>=20
> <project name=3D"WebGui" default=3D"dist" basedir=3D".">
> <description>
> simple example build file
> </description>
> <property name=3D"dist" location=3D"dist"/>
>=20
> <target name=3D"dist" description=3D"generate the distribution"=20
>=20
> </target>
>=20
> <jspc srcdir=3D"${basedir}"
> destdir=3D"${basedir}/Web-inf/classes">
> <classpath>
> <pathelement path=3D"${classpath}"/>
> <fileset dir=3D"${basedir}/Web-inf/lib">
> <include name=3D"**/*.jar"/>
> </fileset>
> </classpath>
> <include name=3D"*.jsp" />
> </jspc>
> <javac
> srcdir=3D"${basedir}/Web-inf/classes"
> destdir=3D"${basedir}/Web-inf/classes">
> <classpath>
> <pathelement path=3D"${classpath}"/>
> <fileset dir=3D"${basedir}/Web-inf/lib">
> <include name=3D"**/*.jar"/>
> </fileset>
> </classpath>
> </javac>
>=20
> <jar destfile=3D"${basedir}/Web-inf/lib/jsp.jar"=20
> basedir=3D"${basedir}/Web-inf/classes"
> includes=3D"*.class">
>=20
> </jar>
> </project>
>=20
> and here is web.xml
> <?xml version=3D"1.0" encoding=3D"ISO-8859-1"?>
>=20
> <!DOCTYPE web-app
> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
> "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
>=20
> <web-app>
> =20
> <description>
> =20
> </description>
> =20
> </web-app>
>=20
> Can you please help me with this.
> I read something about adding code to web.xml after usage of JspC
> but I don't know what, I tried adding servlet mappings for=20
> precompiled jsp paged but that didn't work.
>=20
> Thanks and best regards,
> Danijel=20
|