Topic
7 replies Latest Post - ‏2013-12-17T21:48:34Z by emil_prager
huahsin68
huahsin68
12 Posts
ACCEPTED ANSWER

Pinned topic how to deploy and start server with Maven in Eclipse?

‏2013-08-26T07:02:39Z |

I am developing a web application using WAS Liberty Profile together with Eclipse IDE. I was inspire by MAVEN and trying to use it with Liberty Profile. But I'm running out of clue how could I package the WAR and then deploy it over Eclipse's local Liberty Profile for debugging purpose.

I have been trying out liberty:package-server, liberty:deploy, liberty:start-server, but none of them success. I have read through the documentation on using MAVEN with Liberty Profile, but it doesn't really help. Currently I'm using standard maven goal, install, to install the web application in local m2 repository and then point that application in server.xml like below which I feel it is a redundant work because the motive behind MAVEN is to perform compilation and deployment process in single step.

Configuration in server.xml

<application id="SpringSecurity4" location="C:\Documents and Settings\huahsin68\.m2\repository\org\huahsin\MyApp\0.0.1-SNAPSHOT\MyApp-0.0.1-SNAPSHOT.war" name="MyApp" type="war"/>

This is my POM configuration on Liberty Profile goal

<plugin>
    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
       <serverHome>C:\Documents and Settings\huahsin68\Tool\WAS Liberty Profile</serverHome>
       <serverName>LP1</serverName>
    </configuration>
   
    <execution>
       <id>package-server</id>
       <phase>package</phase>
       <goals>
          <goal>package-server</goal>
       </goals>
       <configuration>
          <installDirectory>${project.build.directory} \liberty</installDirectory>
       </configuration>
    </execution>
   
    <execution>
       <id>deploy-app</id>
       <phase>pre-integration-test</phase>
       <goals>
          <goal>deploy</goal>
       </goals>
       <configuration>
           <appArchive>MyApp-0.0.1-SNAPSHOT.war</appArchive>
       </configuration>
    </execution>
    <execution>
       <id>start-server</id>
       <phase>pre-integration-test</phase>
       <goals>
          <goal>start-server</goal>
       </goals>
       <configuration>
          <verifyTimeout>200</verifyTimeout>
          <configFile>C:\Documents and Settings\huahsin68\Tool\WAS Liberty Profile\usr\servers\LP1\server.xml</configFile>
       </configuration>
    </execution>
 </executions>
</plugin>

Does anyone have any experience in using MAVEN together with Liberty Profile? Mind to share some light how it could be done?

  • rsanchezh
    rsanchezh
    26 Posts
    ACCEPTED ANSWER

    Re: how to deploy and start server with Maven in Eclipse?

    ‏2013-08-26T18:40:16Z  in response to huahsin68

    Hello,

    Do you see an error during the build when executing the liberty plugin goals? Or they do nor run at all?

    If you are trying to start liberty and deploy the web application while building the web application, I did some testing, and was able to do it, following these steps:

    1. I configured the maven repository, in my case, I configured it in the settings.xml. Did you configure the repository as explained in this link? http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.wlp.nd.doc%2Fae%2Ftwlp_dev_maven.html

    2. I configured the plugin com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin in the pom.xml of my web project to start the default server and deploy the packaged war file in the target directory (this is a very basic configuration, you might need to do some changes):

    <!-- Enable liberty-maven-plugin -->
                <plugin>
                    <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
                    <artifactId>liberty-maven-plugin</artifactId>
                    <version>1.0</version>
                    <!-- Specify configuration, executions for liberty-maven-plugin -->
                    <executions>
                        <execution>
                            <id>start-server</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>start-server</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>deploy-app</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                            <configuration>
                                <appArchive>${project.build.directory}/${project.build.finalName}.${project.packaging}</appArchive>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <serverHome>C:\Liberty855</serverHome>
                        <serverName>defaultServer</serverName>
                    </configuration>
                </plugin>

    (note that I put the start server goal before the deploy goal, and in your POM, you specified the start goal after the deploy)

    3. Then I ran mvn verify, which includes the phase pre-integration-test in which the goals are defined. Which goal did you use when running your build?

    4. I verified that the server was started and the application deployed.

    Hope this helps

    • huahsin68
      huahsin68
      12 Posts
      ACCEPTED ANSWER

      Re: how to deploy and start server with Maven in Eclipse?

      ‏2013-08-28T01:04:25Z  in response to rsanchezh

      I am sure I have everything setup properly. It doesn't really matter on how the maven goal sequence is order because it was govern by the Maven build life cycle. I notice that your server home is pointing to a location where the directory name is without any space. Thus I extract wlp in a brand new location, say D:\tool\wlp with Maven goal liberty:create-server liberty:start-server liberty:deploy

      Now I have this Maven output:

      [INFO] Scanning for projects...
      [WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
      [WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0
      [WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
      [WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0
      [INFO]                                                                         
      [INFO] ------------------------------------------------------------------------
      [INFO] Building SpringSecurity4 0.0.1-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
      [WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0
      [WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
      [WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0
      [INFO] 
      [INFO] --- liberty-maven-plugin:1.0:start-server (default-cli) @ SpringSecurity4 ---
      [WARNING] The POM for com.ibm.websphere.wlp.ant:wlp-anttasks:jar:1.0 is missing, no dependency information available
      [INFO] CWWKM2102I: Using pre-installed assembly : D:\tool\wlp.
      [INFO] CWWKM2102I: Using serverName : LP1.
      [INFO] CWWKM2107I: Installation type is pre-existing; skipping installation.
      [INFO] CWWKM2001I: installDir is D:\tool\wlp.
      [INFO] CWWKM2001I: ConfigDir is D:\tool\wlp\usr\servers\LP1.
      [INFO] CWWKM2001I: OutputDir is D:\tool\wlp\usr\servers\LP1.
      [INFO] CWWKM2001I: Invoke command is [D:\tool\wlp\bin\server.bat, start, LP1, --clean].
      [INFO] Starting server LP1.
      [INFO] Server LP1 start failed. Check server logs for details.
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 3.984s
      [INFO] Finished at: Wed Aug 28 08:51:55 SGT 2013
      [INFO] Final Memory: 7M/19M
      [INFO] ------------------------------------------------------------------------
      [ERROR] Failed to execute goal com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin:1.0:start-server (default-cli) on project SpringSecurity4: CWWKM2002E: Failed to invoke [D:\tool\wlp\bin\server.bat, start, LP1, --clean]. RC= 22 but expected=0. -> [Help 1]
      [ERROR] 
      [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
      [ERROR] Re-run Maven using the -X switch to enable full debug logging.
      [ERROR] 
      [ERROR] For more information about the errors and possible solutions, please read the following articles:
      And this is the server log:
       
      arg0=LP1
      arg1=--status:start
      exit=22
       
                         Command:  "C:\Documents and Settings\kok.hoe.loh\Tool\jdk1.6.0_30\jre\bin\java" -XX:MaxPermSize=256m  "-javaagent:D:\tool\wlp\bin\tools\ws-javaagent.jar" -jar "D:\tool\wlp\bin\tools\ws-server.jar" --batch-file start LP1 --clean
                       Java home:  C:\Documents and Settings\kok.hoe.loh\Tool\jdk1.6.0_30\jre
                    Install root:  D:/tool/wlp/
                System libraries:  D:/tool/wlp/lib/
                       User root:  D:/tool/wlp/usr/
                   Server config:  D:/tool/wlp/usr/servers/LP1/
                   Server output:  D:/tool/wlp/usr/servers/LP1/
      This seems to me that the server is not able to start due to the exit=22. What is exit=22 mean?
    • emil_prager
      emil_prager
      2 Posts
      ACCEPTED ANSWER

      Re: how to deploy and start server with Maven in Eclipse?

      ‏2013-12-16T14:39:34Z  in response to rsanchezh

      Hi, Roberto,

      I've modifed the pom.xml to be like yours (which is pretty different from the suggestion made by the snippet from the Liberty profile: Maven goal - liberty:start-server page).

      However, I still have the following error:

      [INFO] ------------------------------------------------------------------------
      [ERROR] Failed to execute goal com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin:1.1:start-server (start-server) on project SimpleEnterpriseAppSampleMave
      n-ear: CWWKM2103E: No server assembly specified: specify either Maven coordinates in assemblyArtifact or a file in assemblyArchive -> [Help 1]
      org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin:1.1:start-server (start-
      server) on project SimpleEnterpriseAppSampleMaven-ear: CWWKM2103E: No server assembly specified: specify either Maven coordinates in assemblyArtifact or a file
      in assemblyArchive
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)

      [INFO] ------------------------------------------------------------------------

      [ERROR] Failed to execute goal com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin:1.1:start-server (start-server) on project SimpleEnterpriseAppSampleMaven-ear: CWWKM2103E: No server assembly specified: specify either Maven coordinates in assemblyArtifact or a file in assemblyArchive -> [Help 1]

      org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.ibm.websphere.wlp.maven.plugins:liberty-maven-plugin:1.1:start-server (start-server) on project SimpleEnterpriseAppSampleMaven-ear: CWWKM2103E: No server assembly specified: specify either Maven coordinates in assemblyArtifact or a file in assemblyArchive

              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)

      [...]

       

      Even after:

      • wanting just to start the server and not to deploy the application, too (commenting the deploy-app execution)
      • and/or trying that again using a simpler sample project (the one quoted in the stacktrace above),
      • and/or using a newer version of the plugin (1.1) -- as one can see in the stacktrace fragment above,

      I still encounter this error.

      Do you have any clue?

      Thank you!


      PS: BTW, I had better results using the Ant tasks.

      • rsanchezh
        rsanchezh
        26 Posts
        ACCEPTED ANSWER

        Re: how to deploy and start server with Maven in Eclipse?

        ‏2013-12-16T15:21:26Z  in response to emil_prager

        Hello Emil,

        Did you specify the serverHome and serverName parameters in the configuration section of the liberty-maven-plugin plugin? Can you share the section of your pom in which you configure the liberty-maven-plugin plugin?

  • huahsin68
    huahsin68
    12 Posts
    ACCEPTED ANSWER

    Re: how to deploy and start server with Maven in Eclipse?

    ‏2013-12-17T08:24:08Z  in response to huahsin68

    Hey guys,

    Sorry for my late reply. I just receive the solution on this problem on weekend, due my busy schedule, I'm late. Anyhow, in order to launch Liberty Profile in Eclipse, I only need to set this goal > liberty:start-server, I don't even need to package or deploy. For the rest of the details configuration, please head to the answer published in stackoverflow.com.

    Cheers :o)

    • emil_prager
      emil_prager
      2 Posts
      ACCEPTED ANSWER

      Re: how to deploy and start server with Maven in Eclipse?

      ‏2013-12-17T21:48:34Z  in response to huahsin68

      Hi, all!

      @huahsin68: Sorry, my mistake! I intervened in this thread although my real problem/goal was a different one than yours.
      It's a difference of perspectives: mine was a CLI-centric/automated (Continuous Integration) approach, while yours was an IDE-centric one (as the title of this topic suggests).
      It's not a big deal to start/stop and/or [re-]deploy the app to a Liberty profile using Eclipse, but the process is quite different from what happens in a more realistic scenario.
      Thus:

      • there (in a scenario closer to a test/staging/production environment), an ear file should be (manually or automatically) produced and deployed to a server (to be more specific, probably to the dropins/ directory), while
      • here, a custom xml file descriptor is created in the apps/ dir, describing the "exploded" content of the ear from its "sources" (i.e. origins), e.g. something like:
        <?xml version="1.0" encoding="UTF-8"?>
        <archive>
            <archive targetInArchive="/your-componentX-impl-module-1.1.14-SNAPSHOT.jar">
                <dir sourceOnDisk="${your-working-copy-location}/${your-project-name}/${componentX-name}/impl/src/main/resources" targetInArchive="/" />
                <dir sourceOnDisk="${your-working-copy-location}/${your-project-name}/${componentX-name}/impl/target/classes" targetInArchive="/" />
            </archive>
            <archive targetInArchive="/lib/your-component-X-api-module-1.1.0-SNAPSHOT.jar">
                <dir sourceOnDisk="${your-working-copy-location}/${your-project-name}/${componentX-name}/api/target/classes" targetInArchive="/" />
            </archive>
            
            <!-- 
            [...]
            other components/modules
            [...]
            -->
            
            <file sourceOnDisk="$M2_REPO/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar" targetInArchive="/lib/slf4j-log4j12-1.7.5.jar"/>
            <!-- 
            [...]
            other 3rd libraries, specs etc.
            [...]
            -->
        </archive>
        
        This is very useful/convenient from the developer p.o.v. (as it assures fast code hot swap), but not necessarily from the continuous integration (CI) / automation p.o.v., where a real ear should be produced/deployed, integration/regression tests ran etc.
        And that was my need!

      PS: related to your remark that:

      >>> [...] It doesn't really matter on how the maven goal sequence is order because it was govern by the Maven build life cycle.

      it is true (and not), because the 2 executions were having the same <phase> (i.e. pre-integration-test); thus, their order is (most probably) the one specified there.


      @Roberto: I've tried (also) with exactly the same pom fragments as the ones quoted in your excerpt. I'll be back a little later --- this kind of CI/automation is very useful, but for the time being is more like a "nice-to-have". I hope I'll have more time to try it in the next days --- then I'll come back with more concrete snippets/poms etc.

      Thank you all!

      Regards,
      -- Emil