zoukankan      html  css  js  c++  java
  • maven 常用配置

    maven 常用配置:

    关于pom文件的配置问题,为了省得每次去网上找,把一些常用的配置记下来。

    Maven 构建,本地Jar包的依懒问题

    一般Maven会从官方仓库或公司仓库下载依懒包。如果是无法下载的本地jar包。可以用以下两种方式来配置

    方法1:<scope>system</scope>显式提供包含依赖的jar,Maven不会在Repository中查找它。

    <dependency>
    
    <groupId>org.apache</groupId>
    
    <artifactId>XXX</artifactId>
    
    <version>1.0</version>
    
    <scope>system</scope>
    
    <systemPath>${basedir}libXXX.jar</systemPath>
    
    </dependency>

    方法2:maven-compiler-plugin 配置exdirs。

    <plugin>
    
    <artifactId>maven-compiler-plugin</artifactId>
    
      <configuration>
    
        <encoding>UTF-8</encoding>
    
        <compilerArguments>
    
          <extdirs>${basedir}lib</extdirs>
    
        </compilerArguments>
    
      </configuration>
    
    </plugin>

    Maven 构建可运行的Jar 包

    为了构建可运行的jar包,需要把依懒包一起打包。下面整理出了两种方式。

    方法1:把依懒和项目代码放在一起打包。

         <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.rihai.sparktest2.WordCount</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

    方法2:分两步走。第一步,把所有依懒放在一个文件夹里。第二步,项目打包,指定main函数, 指定引用的classpath 为前面的依懒包目录。

                
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.rihai.sparktest2.WordCount</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>
                                    ${project.build.directory}lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
  • 相关阅读:
    Python tkinter 实现简单登陆注册 基于B/S三层体系结构,实现用户身份验证
    Python3连接MySQL数据库实战
    Python3 报错'latin-1' codec can't encode character 解决方案
    python 操作excle 之第三方库 openpyxl学习
    对象的深拷贝和浅拷贝
    手机wap站全屏展示隐藏地址栏和状态栏代码
    JS调用App方法及App调用JS方法
    Vue里给v-html元素添加样式
    为什么JavaScript中移动端使用ontouchend无法获取touches数组
    什么是并发和并行
  • 原文地址:https://www.cnblogs.com/zrhai/p/5828947.html
Copyright © 2011-2022 走看看