Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mvn install with packageType=jar & include=runnable not installing the runnable JAR #1239

Closed
tomcruise81 opened this issue Sep 9, 2021 · 24 comments · Fixed by #1244
Closed
Assignees
Labels

Comments

@tomcruise81
Copy link

When using <packaging>liberty-assembly</packaging>, the Maven install phase seems to ignore runnable JARs.

[INFO] --- liberty-maven-plugin:3.3.4:package (package-server) @ openliberty-openjdk-uber-jar ---
...
[INFO] CWWKM2136I: Package file location is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar.
[INFO] CWWKM2001I: Invoke command is ["<WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\bin\server.bat", package, defaultServer, --archive="<WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar", --include=all,runnable].
...
[INFO] Server defaultServer package complete in <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar.
[INFO] 
...
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) @ openliberty-openjdk-uber-jar ---
[INFO] Installing <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar to <WORKSTATION_PATH>\.m2\repository\<GROUP_PATH>\openliberty-openjdk-uber-jar\0.0.0-SNAPSHOT\openliberty-openjdk-uber-jar-0.0.0-SNAPSHOT.zip
[INFO] Installing <WORKSTATION_PATH>\<WORKSPACE_PATH>\pom.xml to <WORKSTATION_PATH>\.m2\repository\<GROUP_PATH>\openliberty-openjdk-uber-jar\0.0.0-SNAPSHOT\openliberty-openjdk-uber-jar-0.0.0-SNAPSHOT.pom

Note at the end that the maven-install-plugin is treating the runnable .jar file as a .zip:

Installing <WORKSTATION_PATH><WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar to <WORKSTATION_PATH>.m2\repository<GROUP_PATH>\openliberty-openjdk-uber-jar\0.0.0-SNAPSHOT\openliberty-openjdk-uber-jar-0.0.0-SNAPSHOT.zip

@cherylking
Copy link
Member

cherylking commented Sep 9, 2021

@tomcruise81 To get a runnable jar, you should use the package goal with include set to runnable. The liberty-assembly always creates a zip as you discovered. The <packaging> should be set to the type of the application being built and deployed to the packaged server. See more documentation here: https://github.com/OpenLiberty/ci.maven/blob/main/docs/package.md#package

@tomcruise81
Copy link
Author

tomcruise81 commented Sep 13, 2021

From https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#a-build-lifecycle-is-made-up-of-phases, we understand that the package goal is intended to:

take the compiled code and package it in its distributable format, such as a JAR.

To ensure that this plugin operates that way, we have our pom configured as such:

            <!-- Enable liberty-maven plugin -->
            <plugin>
                <groupId>io.openliberty.tools</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>3.3.4</version>
                <!-- This is necessary to allow for <packaging>liberty-assembly</packaging> -->
                <extensions>true</extensions>
                <configuration>
                    <looseApplication>true</looseApplication>
                    <deployPackages>all</deployPackages>
                    <assemblyArtifact>
                        <groupId>io.openliberty</groupId>
                        <artifactId>openliberty-kernel</artifactId>
                        <version>${openliberty.runtime.version}</version>
                        <type>zip</type>
                    </assemblyArtifact>
                </configuration>
                <!-- This causes mvn package to create a runnable JAR file -->
                <executions>
                    <execution>
                        <id>package-server</id>
                        <phase>package</phase>
                        <goals>
                            <goal>package</goal>
                        </goals>
                        <configuration>
                            <packageType>jar</packageType>
                            <include>all,runnable</include>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

so that during the default mvn package phase, Maven will delegate to your package goal with the appropriate packageType and include configurations.

However, beyond that, we utilize the other standard Maven phases specified at https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#a-build-lifecycle-is-made-up-of-phases, including:

  • install - "install the package into the local repository, for use as a dependency in other projects locally"
  • deploy - "done in the build environment, copies the final package to the remote repository for sharing with other developers and projects."

We don't call mvn package directly, since it's automatically called via mvn install. Ultimately, we use the deploy phase to copy the artifacts to a remote Nexus instance. But in preparation for that, we use the install phase to get everything prepared for that eventual deployment,

@cherylking
Copy link
Member

cherylking commented Sep 13, 2021

@tomcruise81 From your previous comment, I wasn't sure if there was a question or outstanding issue? Were you able to get the package goal to generate the runnable jar that you wanted? If you are still using packaging liberty-assembly, I don't think that is compatible with producing a runnable jar. Were you wanting the produced zip file to contain the runnable jar?

@tomcruise81
Copy link
Author

The Maven install phase seems to ignore the runnable JARs. So it's an outstanding issue.

This plugin generates the runnable JAR, but doesn't convey to the rest of Maven that it ever generated that runnable JAR. So mvn install and mvn deploy know nothing about it.

@tomcruise81
Copy link
Author

@cherylking - are you saying that I shouldn't be using liberty-assembly to package a runnable JAR? I was under the impression (based on https://github.com/OpenLiberty/ci.maven#liberty-assembly) that liberty-assembly was the only supported packaging type.

Is there a mechanism for creating a runnable JAR via the default packaging type?

@cherylking
Copy link
Member

@cherylking - are you saying that I shouldn't be using liberty-assembly to package a runnable JAR? I was under the impression (based on https://github.com/OpenLiberty/ci.maven#liberty-assembly) that liberty-assembly was the only supported packaging type.

Is there a mechanism for creating a runnable JAR via the default packaging type?

That is exactly what I was saying. Usually the packaging type would be war or ear and then you use the package goal with include="runnable" to get a runnable jar. But that runnable jar is not the installed artifact (the ear or war is the installed artifact). So I think it still does not get you everything you want?

@tomcruise81
Copy link
Author

If I try setting <packaging>jar</packaging>, the resultant JAR file is only about 11MB, and doesn't contain everything (it's missing the necessary "features") it needs to make it an uber JAR.

@cherylking
Copy link
Member

cherylking commented Sep 13, 2021

@tomcruise81 Did you create the Liberty server and install the features before calling package? The liberty-assembly does a lot of those steps for you, and I presume is why you were using it in the first place.

This is what is defined in the liberty-assembly lifecycle:

                            <prepare-package>
                                :liberty-maven-plugin:install-server,
                                io.openliberty.tools:liberty-maven-plugin:create,
                                io.openliberty.tools:liberty-maven-plugin:install-feature,
                            </prepare-package>
                            <package>
                                io.openliberty.tools:liberty-maven-plugin:deploy,
                                io.openliberty.tools:liberty-maven-plugin:package
                            </package>
                            `

@cherylking
Copy link
Member

cherylking commented Sep 13, 2021

If I try setting <packaging>jar</packaging>, the resultant JAR file is only about 11MB, and doesn't contain everything (it's missing the necessary "features") it needs to make it an uber JAR.

Is this a SpringBoot application? If not, the packaging type for the pom.xml should be war or ear. The packageType for the package goal should be jar.

@tomcruise81
Copy link
Author

tomcruise81 commented Sep 13, 2021

It is not a SpringBoot application. However, the intent of making it an uber JAR is to allow it to function in a fashion similar to SpringBoot - i.e. to run in an isolated fashion on a distinct JVM/JDK without a prior Liberty installation. The expectation is that it should be able to run on a clean VM / container that solely contains a JVM/JDK simply by calling java -jar liberty-uber-jar-file.jar. This means that the runnable uber JAR is expected to include the features and anything else that it would need to be able to run.

This seems consistent with https://openliberty.io/guides/getting-started.html#running-the-application-from-a-minimal-runnable-jar.

As such, I'm not calling other goals. My expectation is that I should be able to just call mvn clean package or mvn clean install (install will trigger a call to the package phase), and:

  1. a fully runnable uber JAR file should have been created
  2. that fully runnable uber JAR file should be seen by other plugins / phases / goals as a generated artifact so that:
    1. It can be installed (not to a Liberty server, but to the local Maven repository) locally via the mvn install goal
    2. It can be deployed to a remote repository via the mvn deploy goal

@cherylking
Copy link
Member

cherylking commented Sep 13, 2021

@tomcruise81 Thanks for the explanation. I understand your use case now.

Two points -

  1. the package goal is not an all inclusive goal with a lifecycle. It does not create and set up the Liberty server for you. The examples shown in the package goal documentation point to an already existing Liberty server where the application is deployed. Therefore, at a minimum you must create the Liberty server, install-feature (the features will get installed for you if you have them configured in a server.xml file in the src/main/liberty/config folder) and deploy the application (ear or war) before trying to package the server as a runnable jar.

  2. I have found an apparently undocumented config parameter attach which would set the artifact to the runnable jar produced by the package goal: <attach>true</attach>

Let me know if following the above steps does not work as I have documented.

On a side note, you are not the first person who has expressed the desire for the package goal to automatically do everything for you. See issue #667.

@tomcruise81
Copy link
Author

I've tried changing to:

<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    ....
    <packaging>jar</packaging>
    ...

    <build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
             ...

            <!-- Enable liberty-maven plugin -->
            <plugin>
                <groupId>io.openliberty.tools</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>3.3.4</version>
                <!-- This is necessary to allow for <packaging>liberty-assembly</packaging> -->
                <!-- <extensions>true</extensions> -->
                <configuration>
                    <looseApplication>true</looseApplication>
                    <deployPackages>all</deployPackages>
                    <!--
                    <assemblyArtifact>
                        <groupId>io.openliberty</groupId>
                        <artifactId>openliberty-kernel</artifactId>
                        <version>${openliberty.runtime.version}</version>
                        <type>zip</type>
                    </assemblyArtifact>
                    -->
                </configuration>
                <!-- This causes mvn package to create a runnable JAR file -->
                <executions>
                    <execution>
                        <id>prepare-package</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>install-server</goal>
                            <goal>create</goal>
                            <goal>install-feature</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>package</id>
                        <phase>package</phase>
                        <goals>
                            <!-- Can't use deploy goal as it isn't supported for jar packaging -->
                            <!-- <goal>deploy</goal> -->
                            <goal>package</goal>
                        </goals>
                        <configuration>
                            <packageType>jar</packageType>
                            <include>all,runnable</include>
                            <attach>true</attach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I end up with the following in mvn clean package -X output:

[INFO] --- liberty-maven-plugin:3.3.4:package (package) @ openliberty-openjdk-uber-jar ---
[DEBUG] Configuring mojo io.openliberty.tools:liberty-maven-plugin:3.3.4:package from plugin realm ClassRealm[plugin>io.openliberty.tools:liberty-maven-plugin:3.3.4, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@6e5e91e4]
[DEBUG] (org.codehaus.mojo.pluginsupport.logging.Logging) Initialized
[DEBUG] Configuring mojo 'io.openliberty.tools:liberty-maven-plugin:3.3.4:package' with basic configurator -->
[DEBUG]   (f) artifactRepository =       id: local
      url: file:///C:/Users/668525/.m2/repository/
   layout: default
snapshots: [enabled => true, update => always]
 releases: [enabled => true, update => always]

[DEBUG]   (f) assemblyArtifact = null:null:null:null:jar
[DEBUG]   (f) assemblyInstallDirectory = <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty
[DEBUG]   (f) attach = true
[DEBUG]   (f) configDirectory = <WORKSTATION_PATH>\<WORKSPACE_PATH>\src\main\liberty\config
[DEBUG]   (f) include = all,runnable
[DEBUG]   (f) isInstall = true
[DEBUG]   (f) libertyRuntimeVersion = 21.0.0.9
[DEBUG]   (f) mergeServerEnv = false
[DEBUG]   (f) packageType = jar
[DEBUG]   (f) project = MavenProject: <PROJECT_ID>:openliberty-openjdk-uber-jar:0.0.0-SNAPSHOT @ <WORKSTATION_PATH>\<WORKSPACE_PATH>\pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: <PROJECT_ID>:openliberty-openjdk-uber-jar:0.0.0-SNAPSHOT @ <WORKSTATION_PATH>\<WORKSPACE_PATH>\pom.xml]
[DEBUG]   (f) refresh = false
[DEBUG]   (f) repoSession = org.eclipse.aether.DefaultRepositorySystemSession@3d2b13b1
[DEBUG]   (f) repositories = [ssaNexus (<NEXUS_REPO_URL>, default, releases+snapshots)]
[DEBUG]   (f) serverName = defaultServer
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@839df62
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@64c8fcfb
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipLibertyPackage = false
[DEBUG] -- end configuration --
[DEBUG] Defaulting runtimeArtifact group id to 'io.openliberty'
[DEBUG] Defaulting runtimeArtifact artifact id to 'openliberty-kernel'
[INFO] The liberty.runtime.version property value 21.0.0.9 is used for the runtimeArtifact version.
[DEBUG] io.openliberty:openliberty-kernel:21.0.0.9 is resolved from project repositories.
[INFO] CWWKM2102I: Using artifact based assembly archive : io.openliberty:openliberty-kernel:null:21.0.0.9:zip.
[DEBUG] CWWKM2104I: Discovering serverHome variable...
[INFO] CWWKM2102I: Using installDirectory : <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp.
[INFO] CWWKM2102I: Using serverName : defaultServer.
[INFO] CWWKM2102I: Using serverDirectory : <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\usr\servers\defaultServer.
[INFO] CWWKM2112I: Re-using previously installed assembly.
[INFO] CWWKM2134I: Packaging server defaultServer.
[INFO] (org.codehaus.mojo.pluginsupport.ant.AntHelper) Copying 1 file to <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\usr\servers\defaultServer
[DEBUG] (org.codehaus.mojo.pluginsupport.ant.AntHelper) Copying <WORKSTATION_PATH>\<WORKSPACE_PATH>\src\main\liberty\config\server.xml to <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\usr\servers\defaultServer\server.xml
[INFO] CWWKM2144I: Update server configuration file server.xml from <WORKSTATION_PATH>\<WORKSPACE_PATH>\src\main\liberty\config\server.xml.
[INFO] CWWKM2136I: Package file location is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar.
[DEBUG] (org.codehaus.mojo.pluginsupport.ant.AntHelper) CWWKM2001I: installDir is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp.
[DEBUG] (org.codehaus.mojo.pluginsupport.ant.AntHelper) CWWKM2001I: userDir is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\usr.
[DEBUG] (org.codehaus.mojo.pluginsupport.ant.AntHelper) CWWKM2001I: server.config.dir is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\usr\servers\defaultServer.
[DEBUG] (org.codehaus.mojo.pluginsupport.ant.AntHelper) CWWKM2001I: outputDir is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty-alt-output-dir.
[DEBUG] (org.codehaus.mojo.pluginsupport.ant.AntHelper) CWWKM2001I: server.output.dir is <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty-alt-output-dir\defaultServer.
[INFO] (org.codehaus.mojo.pluginsupport.ant.AntHelper) CWWKM2001I: Invoke command is ["<WORKSTATION_PATH>\<WORKSPACE_PATH>\target\liberty\wlp\bin\server.bat", package, defaultServer, --archive="<WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar", --include=all,runnable].
[INFO] (org.codehaus.mojo.pluginsupport.ant.AntHelper) Packaging server defaultServer.
[INFO] (org.codehaus.mojo.pluginsupport.ant.AntHelper) Server defaultServer package complete in <WORKSTATION_PATH>\<WORKSPACE_PATH>\target\openliberty-openjdk-uber-jar.jar.
[DEBUG] (org.codehaus.mojo.pluginsupport.logging.Logging) Resetting
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:57 min
[INFO] Finished at: 2021-09-13T14:35:45-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.openliberty.tools:liberty-maven-plugin:3.3.4:package (package) on project openliberty-openjdk-uber-jar: packageType must match project packaging type. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.openliberty.tools:liberty-maven-plugin:3.3.4:package (package) on project openliberty-openjdk-uber-jar: packageType must match project packaging type.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: packageType must match project packaging type.
    at org.codehaus.mojo.pluginsupport.MojoSupport.execute (MojoSupport.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: packageType must match project packaging type.
    at io.openliberty.tools.maven.server.PackageServerMojo.doExecute (PackageServerMojo.java:166)
    at org.codehaus.mojo.pluginsupport.MojoSupport.execute (MojoSupport.java:122)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Of note:

[DEBUG]   (f) assemblyArtifact = null:null:null:null:jar
...
[DEBUG]   (f) packageType = jar
...
Caused by: org.apache.maven.plugin.MojoExecutionException: packageType must match project packaging type.
    at io.openliberty.tools.maven.server.PackageServerMojo.doExecute (PackageServerMojo.java:166)

Looking at that code in the plugin, I'm not seeing why there'd be an issue with the comparison...

@cherylking
Copy link
Member

@tomcruise81 Can you try removing the <packaging>jar</packaging> line from your pom.xml and try again? I think you have hit a bug at this line of code, where it should be using an equals() method, not a != comparison.

https://github.com/OpenLiberty/ci.maven/blob/main/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PackageServerMojo.java#L165

@tomcruise81
Copy link
Author

tomcruise81 commented Sep 13, 2021

That made some progress. However, using the default packaging (i.e. jar), I'm precluded from using the deploy goal of this plugin due to

protected boolean isSupportedType(String type) {
boolean supported = false;
switch (type) {
case "ear":
case "war":
case "rar":
case "eba":
case "esa":
case "liberty-assembly":
supported = true;
break;
default:
break;
}
return supported;
}
public static boolean isSupportedLooseAppType(String type) {
boolean supported = false;
switch (type) {
case "ear":
case "war":
case "liberty-assembly":
supported = true;
break;
default:
break;
}
return supported;
}

So at this point:

  • I can create a runnable uber JAR
  • the runnable uber JAR doesn't include the application code

@cherylking
Copy link
Member

cherylking commented Sep 13, 2021

Ok, so typically the <packaging> type would be ear or war. And that ear/war is what would get deployed to the Liberty server that you end up packaging. The attach config parameter requires the packaging and packageType to match however in order to set that as the installed artifact (not sure why...predates my time on this plugin). Might need a multi-module approach to this. Let me think on this and try some different scenarios.

@cherylking
Copy link
Member

cherylking commented Sep 14, 2021

@tomcruise81 I set up a multi-module project locally with two sub modules - one for building the war application, creating the Liberty server, installing the features and deploying the application - and another for packaging the Liberty server. Both the war file and the runnable jar file ended up in the .m2 repo after running mvn clean install on the main module. Here are the pertinent parts of the pom.xml files:

Directory package-file-multi-module pom.xml

...
    <artifactId>multi-module-package</artifactId>
    <packaging>pom</packaging>
...
<modules>
        <module>deploy-app</module>
        <module>make-package</module>
    </modules>
...

Directory deploy-app pom.xml (under directory package-file-multi-module)

...
    <artifactId>my-war</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
...
            <plugin>
                <groupId>io.openliberty.tools</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>3.4</version>
                <configuration>
                    <runtimeArtifact>
                        <groupId>io.openliberty</groupId>
                        <artifactId>openliberty-kernel</artifactId>
                        <version>21.0.0.6</version>
                        <type>zip</type>
                    </runtimeArtifact>
                    <serverName>myTestServer</serverName>
                    <appsDirectory>apps</appsDirectory>
                    <deployPackages>project</deployPackages>
                    <stripVersion>true</stripVersion>
                    <looseApplication>false</looseApplication>
                </configuration>
                <executions>
                    <execution>
                        <id>create-and-setup-liberty-server</id>
                        <phase>install</phase>
                        <goals>
                            <goal>create</goal>
                            <goal>install-feature</goal>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
...

Note: I had a server.xml in src/main/liberty/config with the necessary features for the war application and the <application> element which is required when deploying an app to the apps directory.

Directory make-package pom.xml (under directory package-file-multi-module)

...
    <artifactId>liberty-package-with-war</artifactId>
...
            <plugin>
                <groupId>io.openliberty.tools</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>3.4</version>
                <extensions>true</extensions>
                <configuration>
                    <installDirectory>../deploy-app/target/liberty/wlp</installDirectory>
                    <serverName>myTestServer</serverName>
                    <include>all,runnable</include>
                    <packageType>jar</packageType>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
              </executions>
            </plugin>
...

Note: I did not include a <packaging> element since we found that bug in the PackageServerMojo, but it should typically be set to jar in this case.

Let me know if you get this working. I will use this issue to fix the bug in PackageServerMojo, but want to make sure you do not run into any other issues first.

@tomcruise81
Copy link
Author

tomcruise81 commented Sep 14, 2021

@cherylking - thanks for continuing to dig into this!

How does that liberty-package-with-war actually reference the WAR? The module names in your parent POM don't correspond to your sub-POMs. Is there something that I'm missing?

@cherylking
Copy link
Member

@tomcruise81 The module names in the main module refer to the directory names for the sub-modules. The artifactId in the sub modules can be anything. The make-package sub-module in my example has an artifactId of liberty-package-with-war and that will be the artifactId in the .m2 repo.

@cherylking
Copy link
Member

So my directory structure was:

package-file-multi-module
-- deploy-app
-- make-package

@tomcruise81
Copy link
Author

Sorry, thanks for clarifying. I don't do much with multi-module Maven.

@tomcruise81
Copy link
Author

I've gone ahead and created https://github.com/tomcruise81/openliberty-uber-jar to give a complete example (based off of all of your help @cherylking - thank you once again) of how to accomplish this.

It'd truly be fantastic if this could be accomplished with a single module. But as I have a path forward, I'm off to more pressing matters. Thanks again!

@cherylking
Copy link
Member

@tomcruise81 Glad you were able to get it working. I'm going to reopen this issue to fix the bug in PackageServerMojo.

@cherylking cherylking reopened this Sep 15, 2021
@cherylking cherylking added the bug label Sep 15, 2021
@cherylking cherylking self-assigned this Sep 15, 2021
@tomcruise81
Copy link
Author

Thanks!

Should "jar" also be added to

protected boolean isSupportedType(String type) {
boolean supported = false;
switch (type) {
case "ear":
case "war":
case "rar":
case "eba":
case "esa":
case "liberty-assembly":
supported = true;
break;
default:
break;
}
return supported;
}
public static boolean isSupportedLooseAppType(String type) {
boolean supported = false;
switch (type) {
case "ear":
case "war":
case "liberty-assembly":
supported = true;
break;
default:
break;
}
return supported;
}
to facilitate moving away from multi-module and potentially allowing a simpler approach to this?

@cherylking
Copy link
Member

cherylking commented Sep 15, 2021

Thanks!

Should "jar" also be added to

protected boolean isSupportedType(String type) {
boolean supported = false;
switch (type) {
case "ear":
case "war":
case "rar":
case "eba":
case "esa":
case "liberty-assembly":
supported = true;
break;
default:
break;
}
return supported;
}
public static boolean isSupportedLooseAppType(String type) {
boolean supported = false;
switch (type) {
case "ear":
case "war":
case "liberty-assembly":
supported = true;
break;
default:
break;
}
return supported;
}

to facilitate moving away from multi-module and potentially allowing a simpler approach to this?

I don't think it is as simple as that. When building a war/ear, there are other plugins involved. I'm not sure changing the project artifact from the produced war/ear to the packaged jar would be ok (unintended side affects). Also, how would the war/ear get built and deployed to Liberty if the <packaging>jar</packaging> was specified? I think packaging the Liberty server as a runnable jar is intended to be a separate step (separate module) from creating and deploying the application to a Liberty server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants