0

I am new to Maven and I would like to know how can I change the landing page (or the root path) of my application. My project is based on Heroku Maven example application.

What I am trying to do is to set the root path to /Landing (which is a servlet). Here is the pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>spring-hibernate-template</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <org.springframework.version>3.1.1.RELEASE</org.springframework.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.2.8</version>
        </dependency>
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901-1.jdbc4</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.10.Final</version>
        </dependency>
        <dependency>
            <groupId>com.github.jsimone</groupId>
            <artifactId>webapp-runner</artifactId>
            <version>7.0.34.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.github.jsimone</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>7.0.34.0</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

and here is the web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>SYW</display-name>

    <welcome-file-list>
        <welcome-file>login.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/people/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <display-name>TestServlet</display-name>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>com.sywgraph.servlets.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/TestServlet</url-pattern>
    </servlet-mapping>

    <servlet>
        <display-name>Login</display-name>
        <servlet-name>Login</servlet-name>
        <servlet-class>com.sywgraph.servlets.Login</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Login</servlet-name>
        <url-pattern>/Landing</url-pattern>
    </ser

vlet-mapping> For now my app main page opens on http://localhost:8080/spring-hibernate-template/.

Thanks

vlio20
  • 8,955
  • 18
  • 95
  • 180

2 Answers2

1

I was just playing with the exact same thing: EXACT SOLUTION After using eclipse to "run-->run on server", find the server in the server view. (To get to the server view use Window->Show View->Servers). The "open" the server created by right clicking and choosing open. The tab on the bottom is marked "Modules." Click it and edit the "Path". This will update the context path in the tomcat server.xml file. This file could also be edited manually. be sure to stop and restart the server.

NicholasKarl
  • 253
  • 3
  • 12
0

I assume you are using Tomcat? It is the Tomcat configuration that you will need to change to get your application to run from the root path.

Check the answer to this question: Tomcat 6: How to change the ROOT application

You may also need to change the Login servlet mapping in the web.xml to something like this:

<servlet>
    <display-name>Login</display-name>
    <servlet-name>Login</servlet-name>
    <servlet-class>com.sywgraph.servlets.Login</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

On a side note, you are using Spring MVC for some paths, it would make sense to use it for all paths and configure your urls in the spring context or Controller annotations

Community
  • 1
  • 1
cowls
  • 24,013
  • 8
  • 48
  • 78
  • I want to correct myself. I want the root to be `http://localhost:8080/` and not `http://localhost:8080/spring-hibernate-template/` as it now – vlio20 Oct 11 '13 at 13:40
  • The above link should help then. You need to set the app context. The "spring-hibernate-template" part is your current app context – cowls Oct 11 '13 at 13:41
  • Maybe it is related to my applicationContex.xml? – vlio20 Oct 11 '13 at 14:27
  • Nope, definitely a tomcat configuration. Did you read through the linked question? It has 3 suggestions – cowls Oct 11 '13 at 14:41
  • I cant see how it is related to my tomcat. Other apps that were not created threw heroku run perfectly from root path. – vlio20 Oct 11 '13 at 14:58