Running Tomcat from JBuilder IDE
Everything should be made as simple as possible, but not simpler.
---Albert Einstein
Last updated: December 25th, 2001
|
This article was published by Borland.
The editors changed the article a lot, they made the language better, but they deleted one important trick -
placing runtime directory within repository structure.
|
The life is too complex, so it is our task to make it as simple as possible.
One of the problems I encountered working on several projects - it was not easy to build them!
Some projects required special drive mappings, environment variables, third-party libraries.
So in the first project I managed I decided that a programmer should be able to compile and run the sources
just after they are checked out. Almost... We still needed JBuilder and Visual C++ installed.
The problem was the absolute paths required to compile/run our projects.
We dealt with libraries by putting them into CVS. (See why it is a good idea) JBuilder helped us by providing local (project) library definitions.
One of the challenges was configuring Tomcat.
So we imported the whole Tomcat into our repository and recreated its minimal required folder structure in runtime folder (also within the repository),
where we placed Tomcat configuration, our web application configuration, images, pages, JSPs. The trick was that JBuilder took
Tomcat Jars from one place, but Tomcat executed in another, prepared by us. That way we were able to configure
several independent servers (we even used two Tomcat versions 3.3 and 4.0b).
Here is an example how to do that. The provided class is working with any JBuilder 3.5+ and it should work with other IDEs too.
- At first you need to define Tomcat library. I hope you know how to do it. With Tomcat 4.0.1 I added the following jars:
- bin/bootstrap.jar
- common/lib/*
- server/lib/*
- lib/*
- Then configure your project to put the generated class files into PATH/webapps/*youapp*/WEB-INF/classes directory
- Copy Tomcat.java file into your source directory and change it to have corrent web application directory.
- Set Tomcat.java class as your main class. Upon execution the class will try calculate Tomcat home directory, set catalina.home property and run Tomcat.
Sample repository structure:
| ... |
| ProductDevelopment | - development home. Put main makefile or ANT's build.xml here. |
| Java | - all JBuilder projects are here |
| src | - Java sources |
| C++ |
| Runtime |
| ThirdParty | - Third party libraries, products (Tomcat, Xerces, ...) |
| WebProduct1 |
| conf | - Tomcat configuration |
| webapps | - Web Applications directory |
| ... |
Good Luck!
package com.inventigo.misc;
import java.net.*;
import java.io.*;
import java.util.*;
/**
* This class helps start Tomcat without specifying the full path to Tomcat's
* configuration directory when it is started from JBuilder.
*/
public class Tomcat {
// classpath suffix: /webapps/app/WEB-INF/classes
private final static String PATH_SUFFIX=File.separator+"webapps"+File.separatorChar+"app"+File.separatorChar+"WEB-INF"+File.separatorChar+"classes";
public static void main(String[] args) {
if (System.getProperty("catalina.home")==null) {
String classpath=System.getProperty("java.class.path");
StringTokenizer tokenizer=new StringTokenizer(classpath, File.pathSeparator);
String home=null;
while (!(home=tokenizer.nextToken()).endsWith(PATH_SUFFIX)) { // looking for a suffix
if (!tokenizer.hasMoreTokens()) {
System.err.println("!! Cannot find a classpath directory ending with '"+PATH_SUFFIX+"'");
return;
}
}
home=home.substring(0, home.length()-PATH_SUFFIX.length());
System.out.println("catalina.home='"+home+'\'');
System.setProperty("catalina.home", home);
}
org.apache.catalina.startup.Bootstrap.main(args);
}
}