Install Netbeans & Tomcat

In this lesson, we’ll complete the buildout of our development environment:  a single Virtual Box virtual machine running Linux Mint.

In the previous lessons, we’ve installed the Apache web server and WordPress and so now we want to install Netbeans and Tomcat to make it easier to build back end web services.  We’ll dedicate a number of lessons to web services in the coming days; but for now, let’s just complete the installation and configuration of our platform.

Install Netbeans & Tomcat

On the Netbeans site, download the distro that has Java EE and Tomcat.

Before you continue, you should find where the Java JDK is installed.  If you have followed these instructions and installed the Oracle Java JDK, the location is probably at:  /usr/lib/jvm/java-8-oracle

From the command terminal, execute the setup program by navigating to the folder where the downloaded file is and execute the following (adjust as needed for the downloaded version): sudo sh

When prompted, make sure to select the Apache Tomcat option for an application server.  I selected both Tomcat and Glassfish.

When you hit the screen that asks for the location of the JDK for the Netbeans IDE, browse-for or key-in the path to the JDK we found earlier.  TIP: pressing the down arrow next to the browse box might point you to the correct path.

Make a note where the Tomcat Server is installed such as /usr/local/apache-tomcat-8.0.2.  We’ll need that next.

Configure Tomcat
  • Let’s confirm we can start Tomcat.  Navigate to the bin directory where the server is installed such as /usr/local/apache-tomcat-8.0.2/bin/
  • From a command window in the /bin directory, execute the startup script: sudo sh
  • You should see a list of “Using” data and then Tomcat started.
  • To confirm that, open a browser and navigate to http://localhost:8080

Click here to Toggle Sidebar: What the heck is the “8080”?

  • Once we confirm that Tomcat can start, let’s shut it down from the command line: sudo sh
  • Start Netbeans and navigate to the Services tab in the left panel.  Then, the Servers icon and expand.  Right-click on the Apache Tomcat… icon and select the properties.  Note the Server Port, 8084 in the following screenshot

  • Close the dialog and once again, right-click over the Apache Tomcat icon and select Start.  Once again, from your browser, navigate to the tomcat server address using the port for the Netbeans instance such as: http://localhost:8084  NOTE: that you can start, stop, restart and generally manage your Tomcat server from this interface.
  • We will want to run two instances of Tomcat on our server:  one for development and one to serve up the application.  The server ports should therefore be different such as 8080 and 8084.  Likewise the Apache JServ Protocol (“AJP”) port should be different and so we’ll want to change that port in Netbeans.  Right click on the Tomcat node under the Servers tab again in Netbeans and select the “edit servers.xml” option.  In the connector port for ajp, change it from the default of 8009 to something else such as 8029.  Save the file.
  • Now you can start both servers and not have a conflict.  So we can now configure our non-develop Tomcat instance to start automatically.  Using the information from here, we’ll do the following:
    • Create a new group under which tomcat will run: sudo groupadd tomcat
    • Create tomcat user:   We’ll make this user a member of the tomcat group, with a home directory of /usr/local/apache-tomcat-8.0.27 (where we installed Tomcat), and with a shell of /bin/false (so nobody can log into the account):
      sudo useradd -s /bin/false -g tomcat -d /usr/local/apache-tomcat-8.0.27 tomcat
      sudo chgrp -R tomcat /usr/local/apache-tomcat-8.0.27
      sudo chmod -R g+r /usr/local/apache-tomcat-8.0.27/conf
      sudo chmod g+x /usr/local/apache-tomcat-8.0.27/conf
      sudo chown -R tomcat webapps/ work/ temp/ logs/
    • Create a tomcat.service account in: /etc/systemd/system/tomcat.service
      Paste the following, with appropriate edits:

Description=Apache Tomcat Web Application Container
Environment=’CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC’

    • And now these:
      sudo systemctl daemon-reload
      sudo systemctl start tomcat
      sudo systemctl status tomcat
      sudo systemctl enable tomcat
    • Open the /conf/tomcat-users.xml file and add an admin user:
      <user username=”admin” password=”password” roles=”manager-gui,admin-gui”/>
      Open the /webapps/manager/META-INF/context.xml and remove the comment marks so the admin is only available from localhost
    • Restart tomcat: sudo systemctl restart tomcat and confirm you can go to the management pages from the host instance: http://localhost:8080/manager

In this lesson, we installed and configured Netbeans, our development tool; and Tomcat, our Application server which will host our web service requests.

In the next lesson, we’ll build our first web service application and show how to configure our sites to serve up the content for us.

Leave a Reply

Your email address will not be published. Required fields are marked *