tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/startup Main.java
Date Fri, 18 Aug 2000 04:51:02 GMT
costin      00/08/17 21:51:02

  Modified:    src/share/org/apache/tomcat/startup Main.java
  Log:
  Guess tomcat.home.
  
  In fact the guess method should be very exact - i.e. no need to set
  tomcat.home any more.
  If you start tomcat using startup.Main you'll have to include
  tomcat.jar in classpath - and that's enough to find the lib dir.
  
  A good idea would be to use same mechanism as apache - libDir,
  confDir, webappsDir ( separate, with reasonable defaults )
  
  Revision  Changes    Path
  1.3       +49 -17    jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Main.java	2000/08/18 04:12:04	1.2
  +++ Main.java	2000/08/18 04:51:01	1.3
  @@ -101,6 +101,7 @@
    */
   public class Main {
       String installDir;
  +    String libBase;
       String homeDir;
       static final String DEFAULT_CONFIG="conf/server.xml";
       boolean doStop=false;
  @@ -133,9 +134,52 @@
       void log( String s ) {
   	System.out.println("TomcatStartup: " + s );
       }
  +
  +    // -------------------- Guess tomcat.home --------------------
  +
  +    public String guessTomcatHome() {
  +	// If -Dtomcat.home is used - Great
  +	String h=System.getProperty( "tomcat.home" );
  +	if( h!=null ) return h;
  +
  +	// Find the directory where tomcat.jar is located
  +	
  +	String cpath=System.getProperty( "java.class.path");
  +	//	log( "CP=" + cpath );
  +	String pathSep=System.getProperty( "path.separator");
  +	//	log( "PS=" + pathSep);
  +	StringTokenizer st=new StringTokenizer( cpath, pathSep );
  +	while( st.hasMoreTokens() ) {
  +	    String path=st.nextToken();
  +	    //	    log( "path " + path );
  +	    if( path.endsWith( "tomcat.jar" ) ) {
  +		h=path.substring( 0, path.length() - "tomcat.jar".length() );
  +		//		log( "Path1 " + h );
  +		try {
  +		    File f=new File( h );
  +		    File f1=new File ( h, "..");
  +		    //    log( "Path2 " + f1 );
  +		    h = f1.getCanonicalPath();
  +		    //log( "Guessed " + h + " from " + path );
  +		    System.setProperty( "tomcat.home", h );
  +		    return h;
  +		} catch( Exception ex ) {
  +		    ex.printStackTrace();
  +		}
  +	    }
  +	    
  +	}
  +
  +	return h;
  +
  +
  +
  +
  +
  +    }
       
  -    // -------------------- Command-line args processing --------------------
  -    String libBase;
  +    
  +    // -------------------- Utils --------------------
       
       public void setLibDir( String base ) {
           try {
  @@ -162,21 +206,10 @@
           }
       }
   	
  -
  -    public String getPackageDir() {
  -	String tcHome=System.getProperty("tomcat.home");
  -	// XXX process args, find if -install is specified
  -	
  -	if( tcHome==null ) {
  -	    log( "No tomcat.home specified, can't run");
  -	    return null;
  -	}
  -	return tcHome;
  -    }
  -    
       public String getLibDir() {
   	if( libBase!=null ) return libBase;
  -	String pkg=getPackageDir();
  +
  +	String pkg=guessTomcatHome();
   	if( pkg!=null ) setLibDir( pkg + "/lib");
   	else setLibDir("./lib");
   	return libBase;
  @@ -204,8 +237,6 @@
       void execute( String args[] ) throws Exception {
   
   	try {
  -
  -
   	    int jarCount=cpComp.length;
   	    URL urls[]=new URL[jarCount + 1 ];
   	    for( int i=0; i< jarCount ; i++ ) {
  @@ -280,6 +311,7 @@
   	return; 
       }
   
  +    // -------------------- Command-line args processing --------------------
       /** Read command line arguments and set properties in proxy,
   	using ant-like patterns
       */
  
  
  

Mime
View raw message