原文:https://blog.csdn.net/sivolin/article/details/46877659
去除[WARNING] Using platform encoding (UTF-8 actually) to copy filter
在POM文件的顶级目录中,加入下面的配置。其实就是设置一下工程的编码格式
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
[maven3 warning] ‘dependencies.dependency.systemPath’ should not point at files within the project directory
systemPath被设计用来讲一些系统库包含进来,它们往往具有固定的路径。当在自己的project中使用这个特性但是指定相对路径如${basedir}/src/lib之类的,就会提示这个。解决方法如下:
- 如果中央仓库有你需要的包,那最好不过了,直接通过制定dependency来自动下载就好。
- 然而有时候你使用的一些第三方包,仓库中是没有的,这个时候,可以使用maven-install-plugin
来将该第三方包安装到本地仓库中即可。步骤如下(这里以spark-liblinear-1.95.jar为例):
首先查看这个包的层次结构,其实就是为了获取它的groupId, artifactId。然后在工程中的POM文件中加入这个包的依赖:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
</plugins>
</build>
然后执行下面的命令即可将第三方包安装到本地仓库中(注意,这里的groupId,artifactId要和上面的依赖中所写的一致,另外,-D选项和后面的参数之间不能有空格):
mvn install:install-file -Dfile=src/lib/spark-liblinear-1.95.jar -DgroupId=tw.edu.ntu.csie -DartifactId=liblinear -Dversion=1.95 -Dpackaging=jar
如果是要部署到自己公司的私有仓库中,可以使用下面的命令(没具体试验过):
mvn deploy:deploy-file -DgroupId=com.bea.xml -DartifactId=jsr173-ri -Dversion=1.0 -Dpackaging=jar -Dfile=[path to file] -Durl=[url] -DrepositoryId=[id]
将项目所有依赖的jar全部打包进最终的项目jar包中
直接使用maven自带的插件进行打包的话,项目依赖的jar不会被打包进最终的项目jar包中,同时,生成的jar包中的META-INF/MENIFEST.MF文件中,也没有指定主类,这样的包无法直接运行的。为了解决这个问题,可以使用maven-shade-plugin插件。在项目POM文件中,添加下面的配置代码(我工程的主类是my.maven.learn.App):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>my.maven.learn.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>