How can I build WAR with Maven in Eclipse?

后端 未结 3 1855
南笙
南笙 2020-12-14 10:35

I have project that I\'m now starting as Maven project, but for some reason it is not working. Here is my pom.xml:



        
相关标签:
3条回答
  • 2020-12-14 10:59

    Actually, your POM looks a bit weird:

    • it is missing the right packaging for a webapp project.
    • the maven war plugin configuration doesn't look right, you just don't need the extra stuff you added.

    Here is what a minimal pom looks like:

    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.app</groupId>
      <artifactId>my-webapp</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      <build>
        <finalName>my-webapp</finalName>
      </build>
    </project>
    

    So either modify it and update the project configuration (right-click on your project then Maven > Update Project Configuration).

    Or just start over and create your project using the maven-archetype-webapp. You can do this from Eclipse: New > Project... > Maven Project, then select the maven-archetype-webapp in the wizzard and follow the seps.

    Or from the command line:

    mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
    
    0 讨论(0)
  • 2020-12-14 11:06

    I suggest use m2eclipse. It's a one click operation using the Eclipse plugin.

    0 讨论(0)
  • 2020-12-14 11:13

    for instance, I see

    <packaging>war</packaging>
    

    missing in your pom, you should have a look at how the maven-war-plugin is used.

    0 讨论(0)
提交回复
热议问题