Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Sunday, 16 September 2012

Installing and Running Tomcat 7 on Windows 7

This post is a reminder about Tomcat 7 manual installation on Windows 7.

Installation

  1. Remove any existing Tomcat 7 installation.
  2. Download Tomcat 7 from here, the 32-bit/64-bit Windows Service Installer is the easiest solution.
  3. Double click on the Windows Service Installer.
  4. Follow the screen instructions.

Creating An Administrator Profile

In order to access the manager console of Tomcat, one needs to create a administrator profile. See the bottom of this post for details.

Starting Tomcat As A Service

To start Tomcat 7 as a service:
  • Open the control panel
  • Select view by: Large Icons
  • Select Administrative Tools
  • Click on the Service Shortcut (eventually right-click and run as administrator if there are permission issues)
  • Select Apache Tomcat 7
  • Right-click to Start/Stop/Restart

Monday, 13 August 2012

What is the context.xml file in a Web Application?

When one creates a default maven web application (from the corresponding archetype), a file called context.xml is automatically be created in /src/main/webapp/META-INF/ if the selected server is Apache Tomcat.

For example:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/MyApplication"/>
From the Tomcat documentation, this file represents the application withing Tomcat. It contains a very important information: the application path. In other words:

  http://www.mytomcatserver.com/MyApplication/index.html

When multiple applications are deployed on Tomcat, users' requests are sent to the proper application by checking each application's path. Longer matching paths have priority on shorter paths.

This file can be used to set some application configuration too (see the bottom of the Tomcat documentation page mentioned above) or a JNDI resource such as a data source for example.

Friday, 27 July 2012

How to Deploy a .war to Tomcat 7 via Maven?

In order to deploy a .war to Tomcat 7 during a maven build process, the cargo plugin is very useful.

One should add the following plugin in your pom.xml:
  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.1.2</version>
    <configuration>
      <container>
        <containerId>tomcat7x</containerId>
        <type>remote</type>
      </container>
      <configuration>
        <type>runtime</type>
        <properties>
          <cargo.remote.uri>
            http://localhost:8080/manager/text
          </cargo.remote.uri>
          <cargo.remote.username>admin</cargo.remote.username>
          <cargo.remote.password>admin</cargo.remote.password>
        </properties>
      </configuration>
      <deployer>
        <type>remote</type>
        <deployables>
          <deployable>
            <groupId>com.my-group-id</groupId>
            <artifactId>my-artifact</artifactId>
            <type>war</type>
          </deployable>
        </deployables>
      </deployer>
    </configuration>
  </plugin>

The remote URI is configured to deploy the .war on a local Tomcat 7 installation listening to port 8080. The host could be a remote host too (one should use https instead for security).

The profile used to connect to maven must be configured with proper roles in the /conf/tomcat-users.xml file where Tomcat is installed, as following:
  <tomcat-users>
    <user name="admin" password="admin"
       roles="admin-gui,manager-gui,manager-script" />
    ...
  </tomcat-users>

Then you can use the following maven goals to deploy or redeploy your application:
  cargo:deployer-deploy
  cargo:deployer-redeploy
More Maven tips & tricks here.

How to Add JSLT Taglibs in a Maven Project?

Here are the dependencies you need to add to your pom.xml, to include JSLT 1.1.2 taglibs in your maven project, for Tomcat:
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <!-- Apache Taglibs does not implement version 1.2 -->
    <version>1.1.2</version>
  </dependency>

  <dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
  </dependency>

  <dependency>
    <groupId>taglibs</groupId>
    <artifactId>c</artifactId>
    <version>1.1.2</version>
    <type>tld</type>
  </dependency>

  <dependency>
    <groupId>taglibs</groupId>
    <artifactId>fmt</artifactId>
    <version>1.1.2</version>
    <type>tld</type>
  </dependency>
If you want to use JSLT version 1.2 with Tomcat, set the following dependencies:
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

<dependency>
  <groupId>org.glassfish.web</groupId>
  <artifactId>jstl-impl</artifactId>
  <version>1.2</version>
  <exclusions>
    <exclusion>
      <artifactId>servlet-api</artifactId>
      <groupId>javax.servlet</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jsp-api</artifactId>
      <groupId>javax.servlet.jsp</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jstl-api</artifactId>
      <groupId>javax.servlet.jsp.jstl</groupId>
    </exclusion>
  </exclusions>
</dependency>

For GlassFish:
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

What Is The Difference Between  JSTL 1.1.2 and 1.2?

For more information about the difference between JSTL version 1.1.2 and 1.2, see the answer to this StackOverflow question.

JSTL Documentation

JSLT (the Java Server Page (JSP) tag library) is a core element of web applications. It is not easy to find documentation about tags, but some useful one is still available here and here.

More Maven tips & tricks here.