Tuesday, March 4, 2014

WebLogic Classloader Analysis Tool

The WebLogic Server has a built-in webapp called Classloader Analysis Tool, and you may access it through http://localhost:7001/wls-cat

You need to login with same user as you configured for the /console webapp. With the CAT, you may check what classes are loaded by your application in the server. This is extremely handy if your app is loading jar that's already loaded by the server. For example, if you include your own Apache commons-lang.jar in a webapp and deploy it, you will see that org.apache.commons.lang.time.DateUtils is not from your webapp!



If you ever get an error saying DateUtils#addDay() doesn't exist or signature not match, then likely you are using different version than the one comes with WLS. In this case, you will need to add "WEB-INF/weblogic.xml" that change classloading behavior. Like this:

<weblogic-web-app>
    <container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
</weblogic-web-app>


Another cool thing you can use this webapp to check is resources packaged inside any jars.  For resource file, you must use # prefix to it. For example try look up #log4j.properties and you will see where it's loading from.

You may read more about this tool and related material here: http://docs.oracle.com/cd/E24329_01/web.1211/e24368/classloading.htm

Wednesday, February 26, 2014

Generating a war file from a plain IntelliJ web project

Sometimes you just want to create a quick web project in IntelliJ IDEA, and you would use their wizard and with web or Java EE module as starter project. But these projects will not have Ant nor Maven script generated for you automatically, and the IDEA Build would only compile your classes. So if you want an war file generated, try the following:

1) Menu: File > Project Structure > Artifacts
2) Click the green + icon and create a "Web Application: Archive", then OK
3) Menu: Build > Build Artifacts ... > Web: war

By default it should generate it under your <project>/out/artifacts/web_war.war


Note that IntelliJ also allows you to setup "Web Application: Exploded" artifact, which great for development that run and deploy to an application server within your IDE.

Saturday, February 22, 2014

Developing Java EE applications with Maven and WebLogic 12c

The WebLogic Server 12c has very nice support for Maven now. The doc for this is kinda hidden though, so here is a direct link http://docs.oracle.com/middleware/1212/core/MAVEN

To summarize the doc, Oracle did not provide a public Maven repository manager hosting for their server artifacts. However they do now provide a tool for you to create and populate your own. You can setup either your local repository (if you are working mostly on your own in a single computer), or you may deploy them into your own internal Maven repository manager such as Archiva or Nexus.

Here I would show how the local repository is done. First step is use a maven plugin provided by WLS to populate the repository. I am using a MacOSX for this demo and my WLS is installed in $HOME/apps/wls12120. If you are on Windows, you may install it under C:/apps/wls12120.

$ cd $HOME/apps/wls12120/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.1.2/

$ mvn install:install-file -DpomFile=oracle-maven-sync.12.1.2.pom -Dfile=oracle-maven-sync.12.1.2.jar

$ mvn com.oracle.maven:oracle-maven-sync:push -Doracle-maven-sync.oracleHome=$HOME/apps/wls12120 -Doracle-maven-sync.testingOnly=false

The artifacts are placed under your local $HOME/.m2/repository/com/oracle. Now you may use Maven to build Java EE application with these WebLogic artifact as dependencies. Not only these are available, the push also populated some additional maven plugins that helps development more easy. For example, you can generate a template project using their archetype plugin.

$ cd $HOME
$ mvn archetype:generate \
    -DarchetypeGroupId=com.oracle.weblogic.archetype \
    -DarchetypeArtifactId=basic-webapp \
    -DarchetypeVersion=12.1.2-0-0 \
    -DgroupId=org.mycompany \
    -DartifactId=my-basic-webapp-project \
    -Dversion=1.0-SNAPSHOT

Type 'Y' to confirm to finish. Notice that pom.xml it generated; it is using the "javax:javaee-web-api:6.0:provided" dependency. This is working because we setup the repository earlier. Now you may build it. 

$ cd my-basic-webapp-project
$ mvn package

After this build you should have the war file under the target directory. You may manually copy and deploy this into your WebLogic server domain. Or you may continue to configure the maven pom to do this all with maven. Here is how I do it. Edit the my-basic-webapp-project/pom.xml file and replace the weblogic-maven-plugin plugin like this:

      <plugin>
        <groupId>com.oracle.weblogic</groupId> 
        <artifactId>weblogic-maven-plugin</artifactId> 
        <version>12.1.2-0-0</version> 
        <configuration> 
          <middlewareHome>${oracleMiddlewareHome}</middlewareHome>
          <adminurl>${oracleServerUrl}</adminurl>
          <user>${oracleUsername}</user> 
          <password>${oraclePassword}</password>
          <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
          <targets>${oracleServerName}</targets>
          <verbose>true</verbose> 
          <name>${project.build.finalName}</name>
        </configuration>
      </plugin>  

With this change, you may deploy the webapp into WebLogic server (well, assuming you already started your "mydomain" with "myserver" server running locally. See my previous blog for instructions)

$ cd my-basic-webapp-project
$ mvn weblogic:deploy -DoracleMiddlewareHome=$HOME/apps/wls12120 -DoracleServerName=myserver -DoracleUsername=admin -DoraclePassword=admin123

After the "BUILD SUCCESS" message, you may visit the http://localhost:7001/basicWebapp URL.

Revisit the WLS doc again and you will find that they also provide other project templates (Maven calls these archetypes) for building EJB, MDB, or WebService projects. These should help you get your EE projects started quickly. 

Sunday, February 2, 2014

Using Intellij IDEA 12 for WebLogic Server 12c

If you want to explore the latest EE features, you would need WebLogic Server 12c. However if you still have the IDEA 12 Ultimate edition, you will quickly find that it only supports up to WebLogic Server 11g (10.x)! However you can still make your IDEA 12 U to work with WLS 12c, and all you need is an extra "registry.xml" file under WLS home directory (eg: C:/apps/wls12120/registry.xml). This file will allow the IDEA to pickup and recognize your latest WLS 12c installation.

<?xml version="1.0" encoding="UTF-8"?>
<bea-product-information>
  <host home="C:\apps\wls12120" name="${env.HOST}">
    <product format="1.0" name="WebLogic Platform">
      <release level="12.0"
        ServicePackLevel="6" PatchLevel="0"
        Status="installed" BeaProgramGroup="BEA WebLogic Platform 12.0" StartMenu=""
        InstallTime="@INSTALL_TIME@"
        InstallDir="
C:\apps\wls12120\wlserver"
        JavaHome="C:\apps\jdk7" JavaVersion="1.7.0" JavaVendor="@JAVA_VENDOR@">
        <component name="WebLogic Server" version="12.1.2.0">
          <component name="Server"/>
          <component name="Server Examples"/>
        </component>
     </release>
    </product>
 </host>
</bea-product-information>


I have learned this from reading the IntelliJ forum. Also note that the latest IDEA 13 will support WebLogic Server 12c out of the box now.
 

Saturday, February 1, 2014

Getting started with Intellij IDEA and WebLogic Server

Before starting, you would need the Ultimate version of IDEA to run WebLogic Server (yes, the paid version or the 30 days trial). The Community edition of IDEA will not support Application Server deployment.

I also assume you have already setup WebLogic Server and a user domain as per my previous blog instructions. So now let's setup the IDE to boost your development.

  1. Create a simple HelloWorld web application in IDEA.
  2. For your HelloWorld, you can go into the Project Settings > Artifacts, and add "web:war exploded" entry for your application. You will add this into your app server later.
  3. Ensure you have added the Application Server Views plugin with WebLogic Server. (It's under Settings > IDE Settings > Application Server)
    1. Click + and enter Name: WebLogic 12.1.2
    2. WebLogic Home: C:\apps\wls12120
  4. Back to your editor, select Menu: Run > Edit Configuration
    1. Click + and add "WebLogic Server" > Local
    2. Name: WLS
    3. On Server tab, ensure DomainPath is set: C:\apps\wls12120\mydomain
    4. On Deployment tab, select "web:war exploded" for your HelloWorld project.
    5. Click OK
  5. Now Menu: Run > "Run WLS"
Your WebLogic Server should now start and running your web application inside. You may visit the browser on http://localhost:7001/web_war_exploded

Some goodies with Intellij IDEA and WLS are:
  • Redeploy WAR only without restarting server
  • Deploy application in exploded mode and have IDE auto make and sync
  • Debug application with server running within IDE
  • Full control on server settings 

NOTE: As noted in previous blog, if you do not set MW_HOME as system variable, then you must add this in IDEA's Run Configuration. Or you edit your "mydomain/bin/startWebLogic.cmd" and "stopWebLogic.cmd" scripts directly.

Friday, January 31, 2014

Getting started with WebLogic Server


Here are some quick tips on how to get started with WebLogic Server on Windows OS:

1. Download wls1212.zip from http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html
2. Unzip it under C:\apps\wls12120
3. set MW_HOME=C:\apps\wls12120
4. set JAVA_HOME=C:\apps\jdk1.7.0_51
5. cd C:\apps\wls12120
6. configure.cmd
7. mkdir user_projects\domains\mydomain
8. cd
user_projects\domains\mydomain
9. %JAVA_HOME%\bin\java -Xmx1024m -XX:MaxPermSize=256m weblogic.Server

By default, the last step should create a domain with all the nessary files in your current working directory. It will also prompt you to create a config.xml (enter 'y' to continue) and then prompting for a username and password to manage the server. Optionally you may also setup username/password part by using additional sys props like this:
-Dweblogic.management.username=weblogic -Dweblogic.management.password=Welcome1

Use CTRL+C to stop the server. The next time you start, you can just invoke "mydomain\bin\startWebLogic.cmd"

TIPS1: If you omit -Xmx1024m -XX:MaxPermSize=256m you will likely can start the server but as soon as you activate the /console webapp, you will run into out of memory issue.

TIPS2: If you have access, try to add Windows Environment variables for MW_HOME and JAVA_HOME into your system. If not, then you can easily add it into "mydomain\bin\setDomainEnv.cmd" as well (it's generated so you can edit all you like.) Without these two variables, you will likely get a class not found error.

TIPS3: The default server name created by this initial setup is called myserver. If you like to name it something else, then add sys props such as this: -Dweblogic.Name=admin-server 

TIPS4: To change the domain name from mydomain to something else, use: -Dweblogic.Domain=dev-domain

TIPS5: The default admin server listening port is 7001. To change this, use: -Dweblogic.ListenPort=7002