📜 ⬆️ ⬇️

Initial setup of Tomcat and its registration with NetBeans

I needed to configure and run Tomcat on Mac OS X (Mountain Lion) and register this application server (servlet container) with NetBeans.
In order to do this, I completed the following points.

Tomcat installation

  1. Download the Tomcat archive from here .
  2. Unpack the archive, for example, in the user folder.
    ~/apache-tomcat-7.0.42 
  3. Open the program "Terminal".
  4. Go to the folder "bin"
     cd ~/apache-tomcat-7.0.42/bin 
    and set permissions to run files with the .sh extension.
     sudo chmod +x ./*.sh 
  5. Set the environment variable CATALINA_HOME. In order for it to be preserved not for the duration of the session in the terminal, but permanently, it is necessary to register it in the file “launchd.conf”.
    Create / open a file (an example is given using the vi editor, but you can use any other, for example emacs):
     sudo vi /etc/launchd.conf 

    Switch to insert mode: “s key”.
    Write the text there:
     setenv CATALINA_HOME /Users//apache-tomcat-7.0.42 

    XXX is the name of your user, if you saved tomcat to the user’s folder as indicated in step 2, if not, specify the path to the folder where you saved tomcat.
    Close the insert mode "Esc key".
    Switch to the "key:" command mode.
    Save the file, the command "wq".
  6. By default, the server is configured on port 8080. To change it, go to the “conf” folder:
     cd ~/apache-tomcat-7.0.42/conf 

    Open the file "server.xml" there.
    Find the tag “Connector” where the port attribute is “8080” and set the port attribute to the desired value:
      <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 
  7. By default, a user with publishing rights (deploy) to the server via the web GUI or through a script is disabled. It must be written in the file "tomcat-users.xml". To do this, go to the folder "conf":
     cd ~/apache-tomcat-7.0.42/conf 

    Open the “tomcat-users.xml” file there and add the following (the username and password can be used other than those listed):
      <role rolename="tomcat"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="tomcat" roles="tomcat, manager-gui, manager-script"/> 

  8. Restart the computer so that the established environment variable CATALINA_HOME is set.
  9. Open the program "Terminal".
  10. Go to the folder "bin"
     cd ~/apache-tomcat-7.0.42/bin 
    and run the startup.sh script
     sh startup.sh 

    The following should be displayed in the terminal (depending on your system settings):
     Using CATALINA_BASE: /Users//apache-tomcat-7.0.42 Using CATALINA_HOME: /Users//apache-tomcat-7.0.42 Using CATALINA_TMPDIR: /Users//apache-tomcat-7.0.42/temp Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home Using CLASSPATH: /Users//apache-tomcat-7.0.42/bin/bootstrap.jar:/Users/XXX/apache-tomcat-7.0.42/bin/tomcat-juli.jar 

  11. Start the browser and type in the address period http: // localhost: 8080 . If you changed the port, as indicated in clause 6, then specify your port.
  12. The tomcat homepage should open.
  13. By the button “Server status” you can see the status of the raised server. You will need to enter a username and password created earlier.
  14. By clicking the “Manager App” button you can publish (delete) applications. You will need to enter a username and password created earlier.
  15. The server is stopped as follows. Go to the folder "bin"
     cd ~/apache-tomcat-7.0.42/bin 
    and run the shutdown.sh script
     sh shutdown.sh 



Register Tomcat Server with NetBeans

  1. If version 8 of Tomcat was installed, it is necessary to make a symbolic link to the library catalog.
     ln -s /Users/XXX/apache-tomcat-8.0.0-RC3/lib /Users/XXX/apache-tomcat-8.0.0-RC3/common/lib 
  2. Open netbeans
  3. Service-> Servers menu
  4. In the window that opens, click "Add server"
  5. In the window that opens, select "Apache Tomcat" and click "Next"
  6. In the next displayed panel, specify the Tomcat home folder, for example "/Users/XXX/apache-tomcat-7.0.42"
  7. Specify the username and password created earlier. Click the Next button.
  8. Specify the port if it has been changed previously. Click the "Finish" button.
  9. For verification, you can create a Web application and select Apache Tomcat as the application server. Then run it from NetBeans. This application will automatically deploy to Tomcat and run in a browser, for example, under the following address: http: // localhost: 8090 / WebApplication1 (usually, by default, the web application template contains a jsp page with the text “Hello World!”).


Note

This does not apply to setting up Tomcat or registering a Tomcat server with NetBeans, but some applications look for java in the / bin folder, and in Mac OS X, java is installed in other folders, but there is a symbolic link to java in the / usr / bin folder.
Thus, you need to make another symbolic link to java.
 sudo ln -s /usr/bin/java /bin/java 

')

Source: https://habr.com/ru/post/196136/


All Articles