idea + maven build web projects.

The first step, create a maven project.

 

 

 

 Project directory so roughly, if not manually change this.

In fact, directly run tomcat, can be played.

Look at the output directory.

 

 Do not control, auto-generated

 

 We recommended to engage in this directory. specification

 

 It proved to be web project

 

 

 

 It is strongly recommended such a format.

 

Startup project

Start a project in target / classes directory compiled files.

generated-sources directory does not know, do not control

mavenDemo directory is the path to final output.

If the package, it would then \ target to generate the next mavenDemo.war file

 

 

Remember:! ! ! !

After we packed, maven dependencies will be in mavenDemo \ under WEB-INF \ lib folder. default.

Compile the source code in mavenDemo \ under WEB-INF \ classes folder. It is the default.

 

 

 

 

How will the introduction of third-party lib package inside the bag into the war

<?xml version="1.0" encoding="UTF-8"?>

<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.kakaluote.maven</groupId>
  <artifactId>mavenDemo</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>mavenDemo Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.github.penggle</groupId>
      <artifactId>kaptcha</artifactId>
      <version>2.3.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-recipes</artifactId>
      <version>2.10.0</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>mavenDemo</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!--项目自带的插件开始-->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!--项目自带的插件结束-->

        <!--指定lib包编译的位置,默认就是/webapp/WEB-INF/lib/下 可以不指定  不建议指定。测试没发现变化-->
        <!--<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.6.0</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
              <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib/</extdirs>
            </compilerArguments>
          </configuration>
        </plugin>-->
         <!-- 将其他目录的jar包打包到指定目录   主要配置-->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <webResources>
              <resource>
                <directory>E:/lib</directory>
                <targetPath>WEB-INF/lib/</targetPath>
                <includes>
                  <include>**/*.jar</include>
                </includes>
              </resource>
            </webResources>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <!--<resources>
      <resource>
        <directory>E:/lib</directory>
        <targetPath>WEB-INF/lib/</targetPath>
      </resource>
    </resources>-->

  </build>
</project>

 

 

码云地址

https://gitee.com/lzh1995/mavenWebDemo

Guess you like

Origin www.cnblogs.com/coder-lzh/p/12164317.html