Geertjan's Blog

  • May 4, 2005

Efficient Tomcat Management from NetBeans IDE 4.1 with Ant

Geertjan Wielenga
Product Manager
Until yesterday, I'd never been aware of the fact that the Tomcat Manager has a web page from which applications can be started, stopped, reloaded, and undeployed. In the Runtime window, when you start the Tomcat Web Server and then expand the Web Applications node, one of the subnodes is called /manager. However, when you right-click this node and choose Open in Browser, you go to this URL:


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:

  1. Create a copy of the tomcat-users.xml file in a local directory, outside of the IDE's user directory.
  2. Create a user and assign it the "manager" role.
  3. 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" />
  4. 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:


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.

Join the discussion

Comments ( 8 )
  • Jeff Saturday, September 3, 2005
    My NB 4.1 runtime panel does not have a "Web Applications" node.
  • Geertjan Sunday, September 4, 2005
    Start the Tomcat Web Server in the Runtime window. Then expand the Tomcat Web Server's node. There you'll find the web Applications node. (In other words, you need to start the Tomcat Web Server first.) Is this clear? Does it help? If not, please leave another message here...
  • L Tuesday, March 14, 2006
    I am using Sun Studio Enterprise 8 with Tomcat 5.5.7.
    I added a user with the role "manager" to tomcat-users.xml.
    But I can't log on! None of the user names and passwords in tomcat-users.xml are recognized.
    What is the password for the user IDE that you refer to?
    Or do you have any other ideas on how I can log on?
  • Geertjan Tuesday, March 14, 2006
    Look at tomcat-users.xml in the USER DIRECTORY, not in the INSTALLATION DIRECTORY. In NetBeans, the user directory is ".netbeans" in your computer's home directory. I don't know what it is for Sun Studio Enterprise.
  • guest Friday, September 29, 2006
  • Geertjan Friday, September 29, 2006
    Is that the sound of laughter? Of gagging? Of despair? Of you drowning? Hmmm. Please enlighten me!
  • guest Thursday, August 30, 2007

    It must be laughter.... User Directory not Install Directory? An hour trawling the web? Borderline insanity? You got to laugh (insanely). Thank you by the way..

  • Geertjan Thursday, August 30, 2007

    Sounds like need to get acquainted with our FAQ:


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.