Skip to content

4. Tomcat 7 Installation and Configuration

Dominik edited this page Jul 30, 2014 · 2 revisions

Tomcat Installation and Configuration.

The API, which we've developed, is a java application, which is build as a deployable Tomcat .war-file. To set up your own instance of our API you need to perform the following steps:

Java Installation

  1. Firstly you need to install java.
  2. Add the repository: sudo add-apt-repository ppa:webupd8team/java
  3. Update your repository: sudo apt-get update
  4. Install Java: sudo apt-get install oracle-java8-installer

Tomcat Installation and Configuration

  1. Install Tomcat: sudo apt-get install tomcat7
  2. Answer yes at the prompt to install tomcat. This will install Tomcat and its dependencies and it will also create the tomcat7 user. It also starts Tomcat with its default settings.
  3. Up to now, Tomcat is not completely set up yet, but the default splash page is accessible by going to your domain or IP address followed by :8080 in a web browser: http://your_ip_address:8080
  4. Install the additional packages (like Admin pack...) by executing the following command: sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples
  5. You have to edit the users.xml, which includes the user management of your Tomcat instance. Type sudo nano /etc/tomcat7/tomcat-users.xml to open and edit the corresponding file.
  6. Search for the follwoing block: <tomcat-users></tomcat-users>
  7. To add a new user with all privileges add the follwoing line between the tomcat-users block: <user username="admin" password="password" roles="manager-gui,admin-gui"/>
  8. Save and quit the tomcat-users.xml file.
  9. Restart the Tomcat service: sudo service tomcat7 restart

CORS Support

To enable CORS Support for your Tomcat Server you need to edit the global web.xml file.

  1. Open and edit the gloabl web.xml file via: sudo nano etc/tomcat7/web.xml
  2. Add the following lines and save and exit the file and restart the Tomcat7 service.
<filter>  
    <filter-name>CorsFilter</filter-name>  
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>  
</filter>  
<filter-mapping>  
    <filter-name>CorsFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
</filter-mapping>

It's also possible to create the filter for CORS Support only for a certain application. To do so, you have to edit the web.xml file for the application, which can usually be found here: sudo nano /var/lib/tomcat7/webapps/<applicaion>/web.xml. Paste the above mentioned block in this file, save and exit the file and restart the Tomcat7 service. For further information take a look at the official documentation sites.

Firewall Settings

Please note that Tomcat communicates through the in the setup defined port (which is by default port 8080), which have to be opened by creating a Firewall exception to work properly. To define a new Firewall Rule, follow the steps below:

  1. Enable the ufw-firewall: ufw allow
  2. Type ufw allow 8080/tcp to open the port 8080.
  3. To save the changes type ufw reload