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

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 -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 \ \
    -DarchetypeArtifactId=basic-webapp \
    -DarchetypeVersion=12.1.2-0-0 \
    -DgroupId=org.mycompany \
    -DartifactId=my-basic-webapp-project \

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:


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"?>
  <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=""
        JavaHome="C:\apps\jdk7" JavaVersion="1.7.0" JavaVendor="@JAVA_VENDOR@">
        <component name="WebLogic Server" version="">
          <component name="Server"/>
          <component name="Server Examples"/>

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.