• idea+maven构建web项目。


    第一步,创建maven项目。

     项目目录大致这样,如果不是这样手动改成这样。

    其实这样,直接跑tomcat,就可以起了。

    看下输出目录。

     不用管,自动生成的

     建议用这个目录搞。规范

     证明是web项目

     

     强烈建议这样的格式。

    启动项目

    一启动项目,就在  target/classes  目录编译文件。

    generated-sources目录不知道,不用管

    mavenDemo目录是最后输出的路径。

    如果打包的话,就会再 arget下 生成一个 mavenDemo.war 文件

    切记:!!!!

    我们打包之后,maven的依赖包都会在  mavenDemoWEB-INFlib  文件夹下。默认的。

    编译的源码都在mavenDemoWEB-INFclasses  文件夹下。也是默认的。

    如何将第三方引入的lib包打进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

  • 相关阅读:
    RootMotionComputer 根运动计算机
    tar压缩解压缩命令详解
    解决有关flask-socketio中服务端和客户端回调函数callback参数的问题
    flask-sqlalchemy中Datetime的创建时间、修改时间,default,server_default,onupdate
    sqlalchemy和flask-sqlalchemy的几种分页方法
    Flask路由报错:raise FormDataRoutingRedirect(request)
    解决Python自带的json不能序列化data,datetime类型数据问题
    Python中将字典转换为有序列表、无序列表的方法
    flask-sqlalchemy 一对一,一对多,多对多操作
    python2 UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not in range(128)
  • 原文地址:https://www.cnblogs.com/coder-lzh/p/12164317.html
Copyright © 2020-2023  润新知