1

I have recently tried to build up web-app using Spring MVC. I did it with Maven by this:

mvn archetype:generate 
-DgroupId={package} 
-DartifactId={project name}
-DarchetypeArtifactId=maven-archetype-webapp 
-DinteractiveMode=false

At first glance, it looks Ok. This project is based on Java EE 6 because I am using Tomcat 7 version. It is also based on:

  • JDK 1.7
  • NetBeans IDE 7.3.1
  • Spring MVC Framework 3.0.0.RELEASE
  • web.xml described with dispatcher version 3.0 (also tried with 2.5)

And all the result is: Tomcat is failing to find it. It looks like my project is invisible. I tried to run it trough maven like this: mvn tomcat:run, but it is just build it!

I do not know how to fix it, and it is starting to annoying me because of this madness.

Any ideas how to make project visible to mr.Tomcat?

Thanks

[Pom.xml]

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.spring</groupId>
    <artifactId>Springmvc</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Springmvc</name>

    <properties>
        <spring.version>3.0.5.RELEASE</spring.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

                <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
solvator
  • 371
  • 1
  • 6
  • 12

1 Answers1

2

You have to add the Tomcat plugin dependency to call mvn tomcat:run. Try add this to your pom.xml:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
</plugin>

After this, try run mvn tomcat:run again.

Further information:

http://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html

Diogo Moreira
  • 1,082
  • 2
  • 9
  • 24
  • Also, just now I notice that i get warning in netbeans: Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true') – solvator Jan 08 '14 at 17:24
  • Take a look http://stackoverflow.com/questions/5351948/webxml-attribute-is-required-error-in-maven – Diogo Moreira Jan 08 '14 at 17:34
  • Now I am getting exception, that 8080 port is already in use. Trying to solve this.. – solvator Jan 08 '14 at 17:39
  • You could change the Tomcat port in the plugin configuration: http://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html. Try to place it in 9090 port. – Diogo Moreira Jan 08 '14 at 17:40
  • I tried with 9090 in tomcat plugin, but still it refers to 8080.... – solvator Jan 08 '14 at 17:44
  • Ok now, it refers to 9090 when i type tomcat7:run. But it stops at message "create webapp with contextPath:/MyProject" and it just does nothing – solvator Jan 08 '14 at 17:54
  • Ohhh yeaaa. It works!!! If I could, I would give you all my rep to you. The two day nightmare is finally over! – solvator Jan 08 '14 at 18:03