我希望maven能够组合一个由shade-plugin创建的超级jar和一个来自all_files目录的shell脚本。
项目结构如下:
<?php
try {
$connect = new PDO("mysql: host = 'localhost'; dbname = users_details", 'root', '');
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
$connect->exec($sqlQuery);
echo 'Successfully created table.';
}
catch(PDOException $e) {
echo $e->getMessage();
}
?>
jar由projectB的pom文件生成,然后放入outtermost文件夹,准备用shell脚本压缩。原因是shell脚本可以调用jar文件来执行项目。
我希望其他程序员能够轻松解压缩文件并运行shell脚本而无需担心。而且我还需要将maven包装在脚本和罐子里。我不确定如何在着色插件中实现它。
注意:我不想使用assembly-plugin,因为它不能很好地打包相关的jar。
all_files/
mvn_script.sh
projB-shaded.jar
maven_project/
guide/
parent-pom.xml
projA/
pom.xml
projB/
pom.xml
答案 0 :(得分:1)
您不想使用maven-assembly-plugin
来创建超级jar。但是你会想用它来创建那个ZIP。
目前,您的maven-shade-plugin
已绑定到package
阶段。您可以将该执行转移到prepare-package
阶段(因为它实际上准备了您的最终包装)添加maven-assembly-plugin
的执行,并绑定到package
阶段。你的程序集会根据着色的JAR创建一个ZIP(它会在执行了shade插件后存在)和shell脚本。
示例描述符如下:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>your-id</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.build.directory}/projB-shaded.jar</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>/path/to/mvn_script.sh</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
使用以下POM配置:
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- current configuration -->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>assemble</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>/path/to/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
根据Maven standard directory layout,程序集descritor的典型位置位于src/assembly
下。