Efficient Tomcat Management from NetBeans IDE 4.1 with Ant

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:

http://localhost:8084/manager/

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:

http://localhost:8084/manager/html/list

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" />
      </target>
  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:

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.


Comments:

My NB 4.1 runtime panel does not have a "Web Applications" node.

Posted by Jeff on September 03, 2005 at 05:32 AM PDT #

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...

Posted by Geertjan on September 03, 2005 at 06:56 PM PDT #

PLEASE HELP ME! 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? THANKS! L

Posted by L on March 14, 2006 at 01:37 AM PST #

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.

Posted by Geertjan on March 14, 2006 at 01:47 AM PST #

guguigjkhbjkbjkb

Posted by guest on September 28, 2006 at 10:32 PM PDT #

Is that the sound of laughter? Of gagging? Of despair? Of you drowning? Hmmm. Please enlighten me!

Posted by Geertjan on September 28, 2006 at 10:34 PM PDT #

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..

Posted by guest on August 30, 2007 at 12:35 AM PDT #

Sounds like need to get acquainted with our FAQ:
http://wiki.netbeans.org/wiki/view/NetBeansUserFAQ

Posted by Geertjan on August 30, 2007 at 12:43 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today