Quantcast
Channel: DevOps tips & tricks
Viewing all articles
Browse latest Browse all 181

Using Maven on Weblogic 12.2.1 with Java EE7

$
0
0
Release notes Weblogic 12.2.1
/whatsnew.htm#NOTES107

The weblogic-maven-plugin plug-in delivered in WebLogic Server 11g Release 1 is deprecated as of release 12.1.2. Oracle recommends that you instead use the WebLogic Server Maven plug-in introduced in version 12.1.2. See "Using the WebLogic Development Maven Plug-in" in Developing Applications for Oracle WebLogic Server for complete documentation.


Configuring the WebLogic Maven Plug-In

Change directory to Maven plugin in WLS12.2.1 installation 
Install the Oracle Maven sync plug-in


[dave@localhost weblogic-12.2.1]$ find . -name   oracle*maven-*.jar
./oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/oracle-maven-sync-12.2.1.jar
[dave@localhost weblogic-12.2.1]$ cd ./oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1
[dave@localhost 12.2.1]$ mvn install:install-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar


Install Oracle Maven jars into local repository


mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/app/weblogic-12.2.1/

Validate Maven artifact are properly installed
mvn help:describe -DgroupId=com.oracle.weblogic -DartifactId=weblogic-maven-plugin -Dversion=12.2.1-0-0

Name: weblogic-maven-plugin
Description: The Oracle WebLogic Server 12.2.1 Maven plugin
Group Id: com.oracle.weblogic
Artifact Id: weblogic-maven-plugin
Version: 12.2.1-0-0
Goal Prefix: weblogic

This plugin has 23 goals:

weblogic:appc
  Description: This goal is a wrapper for the weblogic.appc compiler.

weblogic:create-domain
  Description: Create a domain for WebLogic Server using the default domain
    template. For more complex domain creation use the WLST goal. Note:
    Starting in WLS 12.2.1, there is a single unified version of WLST that
    automatically includes the WLST environment from all products in the
    ORACLE_HOME.

weblogic:deploy
  Description: Deploys an application to WebLogic Server (supports all
    formats WAR, JAR, RAR, EAR, etc.)

weblogic:distribute-app
  Description: Prepares deployment files for deployment by copying deployment
    files to target servers and validating them.

weblogic:install
  Description: Installs WebLogic Server

weblogic:list-apps
  Description: Lists the deployment names for applications and stand-alone
    modules deployed distributed, or installed to the domain

weblogic:purge-tasks
  Description: Flushes out retired deployment tasks

weblogic:redeploy
  Description: Redeploys a running application or part of a running
    application

weblogic:remove-domain
  Description: This class provides basic capabilities to remove a domain
    directory.

weblogic:start-app
  Description: Starts an application

weblogic:start-server
  Description: Starts WebLogic Server.

weblogic:stop-app
  Description: Stops an application

weblogic:stop-server
  Description: This goals run a stop script to stop WebLogic Server.

weblogic:undeploy
  Description: Stops the deployment unit and removes staged files from target
    servers

weblogic:uninstall
  Description: Uninstalls WebLogic Server

weblogic:update-app
  Description: Updates an application's deployment plan by redistributing the
    plan files and reconfiguring the application based on the new plan
    contents.

weblogic:wlst
  Description: This goal is a wrapper for the WLST scripting tool.
    Note: Starting in WLS 12.2.1, there is a single unified version of WLST
    that automatically includes the WLST environment from all products in the
    ORACLE_HOME.

weblogic:wlst-client
  Description: WLST wrapper for Maven that does not require a server install
    for WLST online commands.

weblogic:ws-clientgen
  Description: A Maven goal to generate client web service artifacts from a
    WSDL Note the differences between clientgen Ant task and Maven goal:
    clientgen goal only generates JAXWS web service artifacts, while Ant task
    has JAXRPC as the default. At the moment there is no way to direct
    clientgen goal to also compile and package generated artifacts.
  Deprecated. No reason given

weblogic:ws-jwsc
  Description: This goal builds a JAX-WS web service, generates source code,
    data binding artifacts, deployment descriptors, and so on into an output
    directory.
  Deprecated. No reason given

weblogic:ws-wsdlc
  Description: This goal generates, from an existing WSDL file, a set of
    artifacts that together provide a partial Java implementation of the Web
    Service described by the WSDL file.
  Deprecated. No reason given

weblogic:wsgen
  Description: Reads a JAX-WS service endpoint implementation class and
    generates all of the portable artifacts for a JAX-WS web service.

weblogic:wsimport
  Description: Parses wsdl and binding files and generates Java code needed
    to access it.

For more information, run 'mvn help:describe [...] -Ddetail'

Building Java EE Projects for WebLogic Server with Maven



 Create app from Maven archetype
[dave@localhost weblogic]$ mvn archetype:generate -DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webapp -DarchetypeVersion=12.2.1-0-0 -DgroupId=dave -DartifactId=dave-basic-webapp-project -Dversion=1.0-SNAPSHOT

[INFO] Using property: groupId = dave
[INFO] Using property: artifactId = dave-basic-webapp-project
[INFO] Using property: version = 1.0-SNAPSHOT
[INFO] Using property: package = dave
Confirm properties configuration:
groupId: dave
artifactId: dave-basic-webapp-project
version: 1.0-SNAPSHOT
package: dave
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: basic-webapp:12.2.1-0-0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: dave-basic-webapp-project
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: dave
[INFO] Parameter: packageInPathFormat, Value: dave
[INFO] Parameter: package, Value: dave
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: dave-basic-webapp-project
[INFO] project created from Archetype in dir: /home/dave/git/weblogic/dave-basic-webapp-project
[dave@localhost weblogic]$ find
.
./dave-basic-webapp-project
./dave-basic-webapp-project/pom.xml
./dave-basic-webapp-project/src
./dave-basic-webapp-project/src/main
./dave-basic-webapp-project/src/main/webapp
./dave-basic-webapp-project/src/main/webapp/css
./dave-basic-webapp-project/src/main/webapp/css/bootstrap.css
./dave-basic-webapp-project/src/main/webapp/index.xhtml
./dave-basic-webapp-project/src/main/webapp/WEB-INF
./dave-basic-webapp-project/src/main/webapp/WEB-INF/web.xml
./dave-basic-webapp-project/src/main/webapp/WEB-INF/beans.xml
./dave-basic-webapp-project/src/main/webapp/template.xhtml
./dave-basic-webapp-project/src/main/java
./dave-basic-webapp-project/src/main/java/dave
./dave-basic-webapp-project/src/main/java/dave/AccountBean.java


 Main pom.xml
[dave@localhost dave-basic-webapp-project]$ more pom.xml 
<?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>
  <groupId>dave</groupId>
  <artifactId>dave-basic-webapp-project</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>basicWebapp</name>
[dave@localhost dave-basic-webapp-project]$ more pom.xml
<?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>
  <groupId>dave</groupId>
  <artifactId>dave-basic-webapp-project</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>basicWebapp</name>
 
  <parent>
    <groupId>com.oracle.weblogic.archetype</groupId>
    <artifactId>wls-common</artifactId>
    <version>12.2.1-0-0</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>6.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>basicWebapp</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.oracle.weblogic</groupId>
        <artifactId>weblogic-maven-plugin</artifactId>
        <version>12.2.1-0-0</version>
        <!--
        You can find and redefine the following variables in the parent pom file arccording to your environment.
 
        oracleMiddlewareHome
        oracleServerUrl
        oracleUsername
        oraclePassword
        oracleServerName
        -->
        <configuration>
          <middlewareHome>${oracleMiddlewareHome}</middlewareHome>
        </configuration>
        <executions>
          <!--Deploy the application to the server-->
          <execution>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <!--The admin URL where the app is deployed. Here use the plugin's default value t3://localhost:7001-->
              <!--adminurl>${oracleServerUrl}</adminurl-->
              <user>${oracleUsername}</user>
              <password>${oraclePassword}</password>
              <!--The location of the file or directory to be deployed-->
              <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
              <!--The target servers where the application is deployed. Here use the plugin's default value AdminServer-->
              <!--targets>${oracleServerName}</targets-->
              <verbose>true</verbose>
              <name>${project.build.finalName}</name>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>



mvn compile

mvn package



mvn package


INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-project] in [/home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/dave/git/weblogic/dave-basic-webapp-project/src/main/webapp]
[INFO] Webapp assembled in [69 msecs]
[INFO] Building war: /home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp.war
[INFO] WEB-INF/web.xml already added, skipping




Edit  in pom.xml ( or settings.xml ) weblogic username and password to be able to deploy
ERROR] Failed to execute goal com.oracle.weblogic:weblogic-maven-plugin:12.2.1-0-0:deploy (default) on project dave-basic-webapp-project: org.apache.maven.plugin.MojoExecutionException: user/password or userConfigFile/userKeyFile must be specified

To deploy the deployment archive using Maven, use the following command:

mvn pre-integration-test


[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-project] in [/home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/dave/git/weblogic/dave-basic-webapp-project/src/main/webapp]
[INFO] Webapp assembled in [31 msecs]
[INFO] Building war: /home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- weblogic-maven-plugin:12.2.1-0-0:deploy (default) @ dave-basic-webapp-project ---
[INFO] Command flags are: -noexit -deploy -username weblogic -password ******* -name basicWebapp -source /home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp.war -verbose -adminurl t3://localhost:7001
weblogic.Deployer invoked with options:  -noexit -deploy -username weblogic -name basicWebapp -source /home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp.war -verbose -adminurl t3://localhost:7001
<Jan 17, 2016 12:52:54 PM CET> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, basicWebapp [archive: /home/dave/git/weblogic/dave-basic-webapp-project/target/basicWebapp.war], to configured targets.>
Task 0 initiated: [Deployer:149026]deploy application basicWebapp on AdminServer.
Task 0 completed: [Deployer:149026]deploy application basicWebapp on AdminServer.
Target state: deploy completed on Server AdminServer


Start Weblogic console http://localhost:7001/console

Check the the WebApp Context Root: in Deployments

Start application in the browser using http://localhost:7001/basicWebapp/


If you Maven repository issues add artifacts into local Maven repository - see the HOWTO here for details http://middlewaremagic.com/weblogic/?p=8294

[dave@localhost 12.2.1]$ export M2_REPO=/home/dave/.m2/repository
[dave@localhost 12.2.1]$ mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar -Durl=file://${M2_REPO}

dave@localhost 12.2.1]$ mvn com.oracle.maven:oracle-maven-sync:12.2.1-0-0:push -Doracle-maven-sync.oracleHome=$MW_HOME -DtestingOnly=false

mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml





Viewing all articles
Browse latest Browse all 181

Trending Articles