Efficient Tomcat Management from NetBeans IDE 4.1 with Ant
By Geertjan on May 03, 2005
This brings up an odd little page containing a few weird links. However, if you go to this URL instead, assuming the bundled Tomcat Web Server is running at the default port 8084, you get a whole different picture altogether:
When you go there, this is what you'll get (click to enlarge):
Now this is really helpful (especially compared to what I get when I choose Open in Browser from the /manager node in the Runtime window). In this page, there are links for each application deployed to the Tomcat Web Server. These links allow me to start, stop, reload, and undeploy my application. And there are various other things available from this page, things I haven't even discovered yet.
Dealing with the Manager's Password
However, before I'm able to access it, I am asked for a username and password, but the only acceptable username/password combination is that of a user who has been assigned the "manager" role. This username and password is located in the tomcat-users.xml file which is found in Tomcat's Home directory (which is, by default, within your user directory). This tomcat-users.xml file was discussed in an earlier blog, where I wrote about an Ant script to open the file in a text editor so that you can see what the IDE-generated password is for the IDE-generated user "IDE", which is a user with the "manager" role. (This is generated by the IDE to help you, because Tomcat doesn't provide a user that is assigned the "manager" role, because this is a powerful role for which you have to specifically create a user yourself or, in the IDE's case, by the IDE.)
But a better solution than clicking a menu item in the IDE to open the tomcat-users.xml file (so that you can see the IDE-generated password) is to use Ant in a different way:
- Create a copy of the tomcat-users.xml file in a local directory, outside of the IDE's user directory.
- Create a user and assign it the "manager" role.
- Create an Ant script to copy this file over the tomcat-users.xml file in the IDE's installation directory:
<target name="copy-my-personal-tomcat-users-file" description="Copy Tomcat Users"> <copy file="C:\\tomcat-users.xml" todir="C:\\Program Files\\netbeans-4.1rc2\\enterprise1\\jakarta-tomcat-5.5.7\\conf" /> </target>
- Create a menu item, toolbar button, or shortcut key to invoke the target.
Now, whenever I have a fresh IDE installation, I need only run the above target for the tomcat-users.xml file to be copied to Tomcat Base directory (which is the bundled Tomcat Web Server's directory inside the IDE's installation directory). Then, when the IDE creates the Tomcat Home directory inside my user directory, which happens the first time that the bundled Tomcat Web Server is started, it will copy the tomcat-users.xml file in the Tomcat Base directory into the Tomcat Home directory. And, since I know what username/password combination has been assigned to the "manager" role (because I defined those once myself, in my local directory), I will never need to dig into the user directory to find the Tomcat Home directory so that I can locate the tomcat-users.xml file in the Tomcat Home directory's conf subdirectory in order to find out what the manager's password is.
Question of the Day. Deepak Jacob asks: "I have added a menu named start tomcat (ide-wide-targets.xml). But Tomcat opens its own window and runs in it. I want to run it inside my Netbeans output window."
Answer: The reason for this is that at startup Tomcat opens two successive DOS-boxes: the first contains a short list of parameters and their values (for CATALINA_HOME, CATALINA_BASE, JAVA_HOME, etc.), the second contains various types of error messages. When using an Ant script to start Tomcat from the IDE, the output of the first DOS-box goes to the Output window, while the output of the second DOS-box -- because it has nowhere else to go -- opens in a separate DOS-box. To circumvent this situation, you can change Tomcat's startup.bat script so that all the output goes to one DOS-box, which means that everything ends up in the Output window and no second DOS-box is opened. In the startup.bat script, there's this line right at the end:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
Change the word "start" to "run". That's it. Now everything will work the way you want it to. I've successfully tested this on Tomcat 4 and Tomcat 5.5.7.