5

UPDATE - July 2021:

While the accepted answer using the dependency plugin was the best solution at the time, the answer from @ltlBeBoy leverages the 'copyDependencies' support since added to liberty-maven-plugin. Using 'copyDependencies' is usually a better solution, since it is integrated into the "dev mode" loop and less verbose (at the expense of supporting fewer options than the dependency plugin).

ORIGINAL QUESTION

I need to copy derby.jar into Open Liberty shared directory ${project.build.directory}/liberty/wlp/usr/shared/resources/. I have the following setup in the pom.xml file:

<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>

and the part for configuring open liberty

<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>

With this setup I have to execute mvn package goal twice. It looks like that when liberty-maven-plugin is executed the ${project.build.directory}/liberty/wlp/usr/shared/resources/ folder is removed if there is no liberty server under liberty/wlp/.

Maven LOG:

[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. 

Can someone please help me with this?

Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
Anton Balaniuc
  • 10,889
  • 1
  • 35
  • 53
  • Is it necessary to execute both plugins in the `package` phase? – J Fabian Meier Sep 22 '19 at 17:10
  • @JFMeier even if I move plugins to different phases, `liberty-maven-plugin:create-server` still removes `${project.build.directory}/liberty/wlp/usr/shared/resources/` directory created by `copy-dependencies` – Anton Balaniuc Sep 22 '19 at 18:24
  • 1
    And copying after `create-server` is too late? – J Fabian Meier Sep 22 '19 at 18:33
  • @JFMeier, you are wright, I solved by adding additional execution for `liberty-maven-plugin`, so now I have the following order `liberty-maven-plugin:create-serverve` -> `maven-dependency-plugin:copy-derby-dependency` and finally `liberty-maven-plugin:install&package` – Anton Balaniuc Sep 22 '19 at 21:15
  • 2
    Starting from [version 3.3](https://github.com/OpenLiberty/ci.maven/releases/tag/liberty-maven-3.3) of the Liberty Maven Plug-in there is a copyDependencies parameter. Se my answer [here](https://stackoverflow.com/a/68369132/5223047). – ltlBeBoy Jul 13 '21 at 20:48
  • @ScottKurz Done. I was worried about "duplicate content"... – ltlBeBoy Jul 27 '21 at 14:53

2 Answers2

5

Here's an example from the Session Cache guide from OpenLiberty.io showing how this can be done. The example is getting a hazelcast.jar, but it could be used for any jar hosted in maven.

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>
mswatosh
  • 466
  • 2
  • 8
  • While this was the best solution at the time, the answer from @ltlBeBoy leverages the 'copyDependencies' support added to liberty-maven-plugin. This is usually a better solution, since it is integrated into the "dev mode" loop and less verbose (at the expense of supporting fewer options than the dependency plugin). – Scott Kurz Jul 27 '21 at 15:11
4

As already stated in my other answer, starting from version 3.3 of the Liberty Maven Plug-in there is a copyDependencies parameter:

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>
...

See documentation for further details.

Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
ltlBeBoy
  • 1,242
  • 16
  • 23
  • Can I make a suggestion? It's generally better to include the `` as a child of the liberty-maven-plugin `` rather than configuring only the execution, which is less flexible. I might edit this to make this change, if you don't mind. – Scott Kurz Jul 27 '21 at 15:10
  • 1
    @ScottKurz OK, would be great if you can improve the answer. You are the "pro". ;-) – ltlBeBoy Jul 27 '21 at 15:14