楔子
Maven下Scala和Java混合打包 ,相关配置文件当独提取出来,依赖的jar包也使用meavn拷贝到一个lib目录下
效果
打包命令
mvn clean scala:compile compile package
-- 下面这个 比上面多 dependency:copy-dependencies -DoutputDirectory=target/lib 表示吧依赖的jar 打包到 lib目录下
mvn clean scala:compile dependency:copy-dependencies -DoutputDirectory=target/lib compile package
拷贝依赖的jar到lib目录
mvn dependency:copy-dependencies -DoutputDirectory=target/lib
打包 配置文件 ${project.build.directory}/config 说明
<targetPath>${project.build.directory}/config</targetPath>
如果启用 <targetPath>${project.build.directory}/config</targetPath>那么,打包之后 jar包不会包含这些配置文件,配置文件会出现在 target\config 目录下
pom文件
<properties>
<project.build.sourceEncoding>UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8
</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8
</maven.compiler.encoding>
<joda-time.version>2.9.9
</joda-time.version>
</properties>
<dependencies>
<dependency>
<groupId>joda-time
</groupId>
<artifactId>joda-time
</artifactId>
<version>${joda-time.version}
</version>
</dependency>
<dependency>
<groupId>commons-io
</groupId>
<artifactId>commons-io
</artifactId>
<version>2.6
</version>
</dependency>
<dependency>
<groupId>org.scala-lang
</groupId>
<artifactId>scala-library
</artifactId>
<version>2.11.12
</version>
</dependency>
<dependency>
<groupId>org.scala-lang
</groupId>
<artifactId>scala-compiler
</artifactId>
<version>2.11.12
</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java
</directory>
<includes>
<include>**/*.xml
</include>
</includes>
</resource>
<resource>
<directory>src/main/resources
</directory>
<includes>
<include>**/*.properties
</include>
<include>**/*.xml
</include>
<include>**/**
</include>
</includes>
<targetPath>${project.build.directory}/config
</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-compiler-plugin
</artifactId>
<version>3.6.1
</version>
<configuration>
<source>1.8
</source>
<target>1.8
</target>
<encoding>UTF-8
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-jar-plugin
</artifactId>
<version>3.0.2
</version>
<configuration>
<archive>
<manifest>
<addClasspath>true
</addClasspath>
<classpathPrefix>lib/
</classpathPrefix>
<mainClass>com.zhuzi.DemoApp
</mainClass>
</manifest>
<manifestEntries>
<Class-Path>config/
</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven
</groupId>
<artifactId>scala-maven-plugin
</artifactId>
<version>3.1.0
</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-dependency-plugin
</artifactId>
<version>3.0.1
</version>
<executions>
<execution>
<phase>package
</phase>
<goals>
<goal>copy-dependencies
</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-resources-plugin
</artifactId>
<version>3.1.0
</version>
<configuration>
<encoding>${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>nexus-aliyun
</id>
<name>Nexus aliyun
</name>
<url>http://maven.aliyun.com/nexus/content/groups/public
</url>
<releases>
<enabled>true
</enabled>
<updatePolicy>always
</updatePolicy>
</releases>
<snapshots>
<enabled>true
</enabled>
<updatePolicy>always
</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
参考
https://www.jianshu.com/p/9aecdfd23594 java -cp https://www.cnblogs.com/people/p/3176761.html
使用maven给spring项目打可直接运行的jar包(配置文件内置外置的打法)https://www.cnblogs.com/hdwang/p/5418747.html