Winte Winte
Winte Winte

Reputation: 763

How to properly run a maven web project in IDEA?

I'm a novice in using maven and idea. I passed throught all intuitive steps to run web project but have got 404 page (this application works well if I use as a simple web project in Idea). The pom file is below:

<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.home.myapp</groupId>
 <artifactId>MyApp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>MyApp</name>
  <url>http://maven.apache.org</url>
  <properties>
<spring.version>3.1.1.RELEASE</spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
  <dependencies>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</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-jdbc</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-webmvc</artifactId> 
    <version>${spring.version}</version> 
</dependency> 
<dependency>    
    <groupId>commons-logging</groupId>  
    <artifactId>commons-logging</artifactId>  
    <version>1.1.1</version>  
</dependency>
<dependency>    
    <groupId>commons-io</groupId>  
    <artifactId>commons-io</artifactId>  
    <version>2.3</version>  
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
  </dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
  </dependencies>
  <build>
  <pluginManagement>
  <plugins>
      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>tomcat-maven-plugin</artifactId>
          <configuration>
                  <server>apache-tomcat-7.0.25</server>
                  <url>http://localhost:8080/manager</url>
                  <path>/</path>
              </configuration>
          </plugin>
      </plugins>
  </pluginManagement>

Could you please tell me the my fault or suggest a article where I can find the explanation of this?

Upvotes: 0

Views: 2229

Answers (3)

Tinman
Tinman

Reputation: 786

Not so sure about idea, but typically a web project will have packaging type of war, rather than jar.

Also research the maven war plugin so you know which files to add and into which folders.

You could research this by creating a sample app by using a maven archetype. Then use a tool to compare the sample source and your own.

Upvotes: 1

Assen Kolov
Assen Kolov

Reputation: 4403

As others mentioned, yo need a war packaging. To be sure, start your project with a maven archetype, see http://maven.apache.org/guides/mini/guide-webapp.html

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp

Make sure you can build a war:

mvn clean install

Now import your project in IDEA: File, New Project, Import Project from external Model, Maven, select your pom.xml.

Upvotes: 1

Vyacheslav Sermyazhko
Vyacheslav Sermyazhko

Reputation: 359

If you have 404 I guess the problem is with URL you try to access to your app.

Nonetheless check the content of your artifact and libs (Ctrl+Shift+Alt+s). Also, try to add such maven plugins as maven-compiler-plugin and maven-war-plugin to your pom.xml.

Upvotes: 0

Related Questions