I am trying to embed Tomcat into a Java application using the following builds:
Tomcat 4.1.16beta JDK 1.4.1_01 I started with the source code that appeared in the OnJava article http://www.onjava.com/pub/a/onjava/2002/04/03/tomcat.html. I am trying to serve a webapp that does work fine when I run Tomcat standalone. When I start the embedded Tomcat, it serves HTML pages just fine. When trying to serve JSPs however, the servlet code is generated, but the compile fails (log at the end of this message, my changes to the source follow that). I suspect that it fails because Ant can't resolve any java files in the work directory, since the compile fails with: Error compiling file: C:\Program Files\Apache Group\Tomcat 4.1\work\_\localhost\texas\/index_jsp.java The forward slash at the end of the path is not correct. I can't find where it comes from in the source code. I have found some similar issues in the archives, but nothing that helps me resolve my problem. Any ideas would be greatly appreciated. Many thanks. The log shows: Creating engine Creating host 'localhost' with appBase 'C:/Program Files/Apache Group/Tomcat 4.1/webapps' Creating context '' with docBase 'C:/Program Files/Apache Group/Tomcat 4.1/webapps/ROOT' Creating context '/examples' with docBase 'C:/Program Files/Apache Group/Tomcat 4.1/webapps/examples/jsp' Creating context '/tomcat-docs' with docBase 'C:/Program Files/Apache Group/Tomcat 4.1/webapps/tomcat-docs' Adding engine (org.apache.catalina.core.StandardEngine/1.0) Creating connector for address='ALL' port='80' secure='false' Adding connector (org.apache.coyote.tomcat4.CoyoteConnector2/1.0) Starting embedded server Apache Tomcat/4.1.12 StandardContext[]: Starting StandardContext[]: Processing start(), current available=false StandardContext[]: Configuring default Resources StandardContext[]: Configuring non-privileged default Loader StandardContext[]: Configuring default Manager StandardContext[]: Processing standard container startup WebappLoader[]: Deploying class repositories to work directory C:\Program Files\Apache Group\Tomcat 4.1\work\_\localhost\_ ContextConfig[]: ContextConfig: Processing START StandardContext[]: Setting deployment descriptor public ID to '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' StandardContext[]: Setting deployment descriptor public ID to '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' ContextConfig[]: Accumulating TLD resource paths ContextConfig[]: Scanning <taglib> elements in web.xml ContextConfig[]: Scanning TLDs in /WEB-INF subdirectory ContextConfig[]: Scanning JARs in /WEB-INF/lib subdirectory ContextConfig[]: Added certificates -> request attribute Valve ContextConfig[]: Pipline Configuration: ContextConfig[]: org.apache.catalina.valves.CertificatesValve/1.0 ContextConfig[]: org.apache.catalina.core.StandardContextValve/1.0 ContextConfig[]: ====================== NamingContextListener[/null/localhost]: Creating JNDI naming context NamingContextListener[/null/localhost]: Resource parameters for UserTransaction = null StandardManager[]: Seeding random number generator class java.security.SecureRandom StandardManager[]: Seeding of random number generator has been completed StandardContext[]: Posting standard context attributes StandardContext[]: Configuring application event listeners StandardContext[]: Sending application start events StandardContext[]: Starting filters StandardWrapper[:default]: Loading container servlet default StandardWrapper[:invoker]: Loading container servlet invoker StandardContext[]: Starting completed 0 [main] INFO http11.Http11Protocol - Initializing Coyote HTTP/1.1 on port 80 61 [main] INFO http11.Http11Protocol - Starting Coyote HTTP/1.1 on port 80 StandardHost[localhost]: Installing web application at context path /texas from URL file://C:/Program Files/Apache Group/Tomcat 4.1/webapps/texas WebappLoader[/texas]: Deploying class repositories to work directory C:\Program Files\Apache Group\Tomcat 4.1\work\_\localhost\texas WebappLoader[/texas]: Deploy class files /WEB-INF/classes to C:\Program Files\Apache Group\Tomcat 4.1\webapps\texas\WEB-INF\classes WebappLoader[/texas]: Deploy JAR /WEB-INF/lib/dom4j.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\texas\WEB-INF\lib\dom4j.jar WebappLoader[/texas]: Deploy JAR /WEB-INF/lib/filetags.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\texas\WEB-INF\lib\filetags.jar WebappLoader[/texas]: Deploy JAR /WEB-INF/lib/xtags.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\texas\WEB-INF\lib\xtags.jar ContextConfig[/texas]: Added certificates -> request attribute Valve StandardManager[/texas]: Seeding random number generator class java.security.SecureRandom StandardManager[/texas]: Seeding of random number generator has been completed StandardWrapper[/texas:default]: Loading container servlet default StandardWrapper[/texas:invoker]: Loading container servlet invoker StandardEngine[null]: Mapping server name 'localhost' StandardEngine[null]: Trying a direct match StandardHost[localhost]: Mapping request URI '/texas/index.jsp' StandardHost[localhost]: Trying the longest context path prefix StandardHost[localhost]: Mapped to context '/texas' Error compiling file: C:\Program Files\Apache Group\Tomcat 4.1\work\_\localhost\texas\/index_jsp.java [javac] Compiling 1 source file StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: -1 in the jsp file: null Generated servlet error: [javac] Compiling 1 source file at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293) at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:313) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:324) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474) ... My changes from the OnJava article: public class WebServer { ... /** This method Starts the Tomcat server. */ public void startTomcat() throws Exception { // Set the home directory System.setProperty( "catalina.home", getPath() ); System.setProperty( "catalina.base", getPath() ); // Create an embedded server embedded = new Embedded(); // print all log statments to standard error embedded.setDebug( 2 ); embedded.setLogger( new SystemOutLogger() ); // Create an engine Engine engine = embedded.createEngine(); engine.setDefaultHost( "localhost" ); // Create a default virtual host host = embedded.createHost( "localhost", getPath() + "/webapps" ); engine.addChild(host); // Create the ROOT context Context context = embedded.createContext( "", getPath() + "/webapps/ROOT" ); host.addChild(context); // Install the assembled container hierarchy embedded.addEngine(engine); // Assemble and install a default HTTP connector Connector connector = embedded.createConnector( null, 80, false ); embedded.addConnector(connector); // Start the embedded server embedded.start(); } ... public static void main( String args[] ) { try { WebServer tomcat = new WebServer(); tomcat.setPath( "C:/Program Files/Apache Group/Tomcat 4.1" ); tomcat.startTomcat(); URL url = new URL("file://C:/Program Files/Apache Group/Tomcat 4.1/webapps/texas"); tomcat.registerWAR("/texas", url); Thread.sleep(1000000); tomcat.stopTomcat(); System.exit(0); } catch( Exception e ) { e.printStackTrace(); } } } -- Bradford Holcombe c/o Triveni Digital 40 Washington Road Princeton Junction, NJ 08550 609.716.3504 [EMAIL PROTECTED] www.trivenidigital.com AIM: colbadhombre (aim:AddBuddy?ScreenName=colbadhombre) Yahoo!: bradfordholcombe -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
