tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject svn commit: r351608 - in /tomcat/sandbox/java/org/apache/tomcat/standalone: ./ Tomcat.java
Date Fri, 02 Dec 2005 06:07:53 GMT
Author: costin
Date: Thu Dec  1 22:07:50 2005
New Revision: 351608

URL: http://svn.apache.org/viewcvs?rev=351608&view=rev
Log:
I'm sure there are other good examples on starting tomcat without
server.xml, I just wanted to have a simple and minimal one I can use here.



Added:
    tomcat/sandbox/java/org/apache/tomcat/standalone/
    tomcat/sandbox/java/org/apache/tomcat/standalone/Tomcat.java

Added: tomcat/sandbox/java/org/apache/tomcat/standalone/Tomcat.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/standalone/Tomcat.java?rev=351608&view=auto
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/standalone/Tomcat.java (added)
+++ tomcat/sandbox/java/org/apache/tomcat/standalone/Tomcat.java Thu Dec  1 22:07:50 2005
@@ -0,0 +1,74 @@
+/*
+ */
+package org.apache.tomcat.standalone;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardServer;
+import org.apache.catalina.core.StandardService;
+import org.apache.catalina.startup.HostConfig;
+
+public class Tomcat {
+
+    public static void main( String args[] ) {
+        try {
+            startTomcat();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    private static void startTomcat() throws Exception {
+        String catalinaHome = System.getProperty("catalina.home");
+        if(catalinaHome==null) {
+            catalinaHome=System.getProperty("user.dir");
+            File home = new File(catalinaHome);
+            if (!home.isAbsolute()) {
+                try {
+                    catalinaHome = home.getCanonicalPath();
+                } catch (IOException e) {
+                    catalinaHome = home.getAbsolutePath();
+                }
+            }
+            System.setProperty("catalina.home", catalinaHome);
+        }
+        
+        if( System.getProperty("catalina.base") == null ) {
+            System.setProperty("catalina.base", catalinaHome);
+        }
+        System.setProperty("catalina.useNaming", "false");
+        
+        StandardServer server = new StandardServer();
+        server.setPort( -1 );
+        //tc.setServer( server );
+        
+        StandardService service = new StandardService();
+        server.addService( service );
+        
+        Connector connector = new Connector("HTTP/1.1");
+        service.addConnector( connector );
+        connector.setPort( 8000 );
+        
+        StandardEngine eng = new StandardEngine();
+        eng.setName( "default" );
+        eng.setDefaultHost("localhost");
+        service.setContainer(eng);
+        
+        StandardHost host = new StandardHost();
+        host.setName( "localhost");
+        host.setAppBase("webapps");
+        HostConfig hconfig = new HostConfig();
+        host.addLifecycleListener( hconfig );
+        
+        eng.addChild( host );
+
+        server.initialize();
+        
+        server.start();
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message