How to deploy to WebSphere Liberty apps directory from WebSphere Liberty Maven plugin?

2k Views Asked by At

I have a application running in WebSphere liberty. Through mvn install command I need to deploy my application to liberty apps directory as I am not using dropins directory.

Bellow is the working maven plugin code from which I can deploy to dropins directory.

        <plugin>
            <groupId>net.wasdev.wlp.maven.plugins</groupId>
            <artifactId>liberty-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>start-server</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start-server</goal>
                    </goals>
                    <configuration>
                        <verifyTimeout>60</verifyTimeout>
                    </configuration>
                </execution>
                <execution>
                    <id>deploy</id>
                    <phase>install</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <serverHome>${wlp.dir}</serverHome>
                <serverName>${server}</serverName>
                <appArtifact>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>${project.artifactId}</artifactId>
                    <version>${project.version}</version>
                    <type>${project.packaging}</type>
                </appArtifact>
                <appDeployName>${project.artifactId}.${project.packaging}</appDeployName>
            </configuration>
        </plugin>

I couldn't find anywhere what configuration need to be added/change to deploy application directly to apps directory. Can someone please let me know what is missing here?

2

There are 2 best solutions below

0
On

You can also try the current 2.0-SNAPSHOT version of the plugin. Just include the parent pom and a little piece of configuration for the plugin. Version 2.0 will be released in early June.

If you don't want to include the parent pom, you can just copy the <pluginManagement/> section from the parent pom which contains the binding of the liberty-maven-plugin goals to the Maven default build lifecycle. See https://github.com/WASdev/ci.maven/blob/master/docs/parent-pom.md

<parent>
    <groupId>net.wasdev.wlp.maven.parent</groupId>
    <artifactId>liberty-maven-app-parent</artifactId>
    <version>2.0-SNAPSHOT</version>
</parent>

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/
        </url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/
        </url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
         </snapshots>
    </pluginRepository>
</pluginRepositories>

...

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        ...
        <plugin>
            <groupId>net.wasdev.wlp.maven.plugins</groupId>
            <artifactId>liberty-maven-plugin</artifactId>
            <version>2.0-SNAPSHOT</version>
            <configuration>
                <assemblyArtifact>
                    <groupId>com.ibm.websphere.appserver.runtime</groupId>
                    <artifactId>wlp-webProfile7</artifactId>
                    <version>17.0.0.1</version>
                    <type>zip</type>
                </assemblyArtifact>
                <serverName>${project.artifactId}Server</serverName>
                <configFile>src/main/liberty/config/server.xml</configFile>
            </configuration>
        </plugin>
    </plugins>

    ...
</build>
0
On

Adding install-apps execution step instead deploy(deploy execution step will deploy application to dropins folder only) step will resolve the issue. Version had to be updated to 1.3 which is the latest as of now

Ref : https://github.com/WASdev/ci.maven/blob/master/docs/install-apps.md

Full maven plugin code will be as bellow

<plugin>
        <groupId>net.wasdev.wlp.maven.plugins</groupId>
        <artifactId>liberty-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
            <execution>
                <id>start-server</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>start-server</goal>
                </goals>
                <configuration>
                    <verifyTimeout>60</verifyTimeout>
                </configuration>
            </execution>
            <execution>
                <id>install-apps</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>install-apps</goal>
                </goals>
                <configuration>
                    <appsDirectory>apps</appsDirectory>
                    <installAppPackages>project</installAppPackages>
                </configuration>
            </execution>
        </executions>
        <configuration>
            <serverHome>${wlp.dir}</serverHome>
            <serverName>${server}</serverName>
            <appArtifact>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
                <type>${project.packaging}</type>
            </appArtifact>
            <appDeployName>${project.artifactId}.${project.packaging}</appDeployName>
        </configuration>
    </plugin>