最新情况-2021年7月:
虽然使用依赖插件的公认答案是当时最好的解决方案,但@ltlBeBoy的答案利用了“copyDependencies”支持,因为它添加到了from plugin中。使用'copyDependencies‘通常是一个更好的解决方案,因为它被集成到"dev模式“循环中,并且更少冗长(代价是支持比依赖插件更少的选项)。
原始问题
我需要将derby.jar复制到开放自由共享目录${project.build.directory}/liberty/wlp/usr/shared/resources/中。在pom.xml文件中有以下设置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-derby-dependency</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>derby</includeArtifactIds>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>以及配置开放自由的部分
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>${openliberty.maven.version}</version>
<executions>
<execution>
<id>package-server</id>
<phase>package</phase>
<goals>
<goal>create-server</goal>
<goal>install-apps</goal>
<goal>package-server</goal>
</goals>
<configuration>
<outputDirectory>target/wlp-package</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>${openliberty.version}</version>
<type>zip</type>
</assemblyArtifact>
<configFile>src/main/liberty/config/server.xml</configFile>
<appArchive>${project.build.directory}/${final.name}.war</appArchive>
<packageFile>${project.build.directory}/${final.name}.jar</packageFile>
<include>runnable</include>
<serverName>${final.name}</serverName>
<installAppPackages>project</installAppPackages>
<configDirectory>${project.basedir}/src/main/liberty/server</configDirectory>
<bootstrapProperties>
<project.name>${final.name}</project.name>
<jwt.issuer>https://server.example.com</jwt.issuer>
</bootstrapProperties>
</configuration>
</plugin>使用此设置,我必须执行两次mvn package目标。看起来,在执行liberty-maven-plugin时,如果liberty/wlp/下没有空闲服务器,则删除${project.build.directory}/liberty/wlp/usr/shared/resources/文件夹。
Maven日志:
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (copy-derby-dependency) @ account ---
[INFO] Copying derby-10.15.1.3.jar to /Users/anton/github/account/target/liberty/wlp/usr/shared/resources/derby-10.15.1.3.jar
and after it
[INFO] --- liberty-maven-plugin:2.2:create-server (package-server) @ account ---
[INFO] CWWKM2110I: Uninstalling: /Users/anton/github/account/target/liberty/wlp. 有人能帮我吗?
发布于 2019-09-23 15:26:01
下面是来自OpenLiberty.io的会话缓存指南中的一个示例,展示了如何做到这一点。这个例子是获取一个hazelcast.jar,但是它可以用于maven中的任何jar。
https://github.com/OpenLiberty/guide-sessions/blob/master/finish/pom.xml
<!-- package hazelcast.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources</outputDirectory>
<destFileName>hazelcast.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>发布于 2021-07-27 14:50:21
正如我的其他答案中已经指出的,从自由Maven插件的3.3版开始,有一个copyDependencies参数:
pom.xml
<plugins>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3.4</version>
<configuration>
<!-- Usually best to add configuration at the plugin level rather than trying to configure particular executions -->
<copyDependencies>
<dependencyGroup>
<!-- Relative to server config directory -->
<location>lib/global/jdbc</location>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
</dependencyGroup>
</copyDependencies>
</configuration>
...server.xml
...
<!-- Derby Library Configuration -->
<library id="derbyJDBCLib">
<fileset dir="${server.config.dir}/lib/global/jdbc" includes="derby*.jar"/>
</library>
...有关更多细节,请参见文档。
https://stackoverflow.com/questions/58051063
复制相似问题