Unfortunately only Tomcat5 can register as a web server in NetBeans4. But there seem many people wanting to develop web apps for Tomcat4. Never give up, we have mighty Ant. Let's try to make Tomcat4 project as graphical as possible! Please read down from the top.
It's as usual installation. I had Tomcat4.1.18 and intalled it in my Windows XP PC. The install directory was c:\tomcat4118, never including halmful blanks in the path.
Then, try on NB4. Create a standard "Web Application" as a new project. It is done from Menu bar, selecting "New"->"New Project".The project name was cat4trial.This project folder can locate to anywhere. In my case, c:\nonidata\nbrc4works.
The simplest installation of Web
application into Tomcat is to put the web folder with proper structure for the
Web app.BThis folder can be arranged by "Web Pages" node of the
Web Project created in NetBeans4.
Now let's see what happens by "Build" this web project. The whole
content in "Web Pages"node is copied to "build/web" folder
within the project.Normally, bundled or newly registered Tomcat5 would read
this "build/web" information and starts application based on this.
But you know in every NB4 project its Source Package folder and even build folder can be located anywhare. Switch from "Project" window to "Files" window, find "nbproject/project.properties"and edit this value.
from
build.web.dir=${build.dir}/web
to
build.web.dir=${tomcat4.home}/webapps/cat4trial
as tomcat4.home=/tomcat4118 (also write in project.properties)
Then right-click the "cat4trial" project node in "Projects" Window and select "Build Project". So the content of this web module goes to webapps folder of Tomcat4!
Is it really only Tomcat5 to be controlled in "Runtime" window graphically for start, shutdown, manage web apps? How about register Tomcat4 like an innocent child?...Fail. Not surprising.
Then edit configuration of the bundled Tomcat. change the value CATALINA_HOME to c:\tomcat4118. Then start bundled Tomcat from the "Runtime" window....Ah, this cheap trick failed again.
Let's go straightforward. add the new target in build.xml of this project.
<target name="startcat4"
depends="initnew">
<exec executable="c:\tomcat4118\bin\startup.bat">
<env key="CATALINA_HOME" value="c:\tomcat4118"/>
<env key="CATALINA_BASE" value="c:\tomcat4118"/>
</exec>
</target>
Here the target "initnew" is defiend former, as
<target name="initnew"
depends="init"/>
It's just calling "init" target in build-impl.xml. Important or fatal targets for a NB4 project is escaped to build-impl.xml, not directly in build.xml. Notice this build-impl.xml is so important that touching this will be penalized with "shido" from NB4 seniors. These targets in build-impl.xml all depends on a seried of initialization, represented by "init" target. So I made a new target "initnew" for just calling it from build-impl.xml.
Let's run starttcat4 target. Switch to "Files" windos. find "build.xml" of this "cat4trial" project, right-click "startcat4" node under it to select "Run Target". Then Tomcat4 will start.
Also to shutdown Tomcat4:
<target name="stopcat4"
depends="initnew">
<exec executable="c:\tomcat4118\bin\shutdown.bat">
<env key="CATALINA_HOME" value="c:\tomcat4118"/>
<env key="CATALINA_BASE" value="c:\tomcat4118"/>
</exec>
</target>
What to write for starting the Web browser? Exec task will help. set arg value to access a given URL on starting it:
<exec executable="${browser.exe}">
<arg value="http://localhost:8080/cat4trial/index.jsp"/>
</exec>
This only start with the URL described directly in the Ant script (in this case, index.jspj. If you want to change the page on start, you have to edit this file. It's not so graphical way.
How about this?
<exec executable="${browser.exe}">
<arg value="http://localhost:8080/cat4trial/${client.urlPart}"/>
</exec>
</target>
This target "run" is the
great one prepared by NB4, related to "Run Project" command for the
project. Sorry I don't know this relation in detail. All I can say is "it's
arranged so" like a B-class SF movie.
build-impl.xml itself is inviolate, but you can override the targets in build.xml.
And I dared override the important, dominant, definifive "run" target
this time.
The clever thing is ${client.urlPart}. This value can be set graphically from the properties window of the Web project: "Relative URL".

So you have no more to touch the Ant file itself to start any pages you can and you like.
But don't forget building the whole project and starting Tomcat4 separately before...
Ok, I will not forget it, but it's bothering! To access build.xml and its target I have to switch to "Files" window, and then return to "Projects" window to select "Run Project" command. Shuttling between two windows when start Tomcat or browser
So try for simpler operation.
Recently I found such a nice command.

Apply this "Create Shortcut" command for "startcat4" target. Then a wizard comes out.

First form is for the location of this shortcut. I selected "Add a menu item". Next is select the root menu for it. I selected "Run" from the list.
Hey, what's that under the Run menu of Menu bar?

This enabled to start/stop Tomcat4 without switching to "Files" windows.
Yes, let's try the whole procedure.
Select "Start Tomcat4" from menu bar.
Add your JSPs or servlets to this Web project "cat4trial".
Build the project.
Display "properties" window of this project, set the starting URL.
OK, "Run Project"!
My friends, could you access to your
URL? Coud you make sure it's Tomcat4 that's working?
Yes I could! I got the page showing "Servlet error: ; is missing , Apache
Tomcat 4.1.18"!....