Thursday, May 15, 2008

Automated Deployment to OC4J in Maven2

Below are example Maven2 Profiles that will deploy/undeploy a WAR to an OC4J Instance. For information on exactly what each parameter does and everything else about working with the admin_client.jar, consult your Oracle Application Server documentation.

Enjoy!

Thanks to Phillip Anderson for this work.


<!-- The base installation directory of OC4J -->
<oc4j.home>C:\JEE\AppServers\oc4j</oc4j.home>

<!-- The string needed to deploy to an OC4J Instance; This would be different for a standalone oc4j instance -->
<oc4j.deployer>deployer:oc4j:opmn://localhost/home</oc4j.deployer>

<!-- The admin userid for OC4J -->
<oc4j.user>oc4jadmin</oc4j.user>

<!-- The password for the OC4J admin user -->
<oc4j.password>admin</oc4j.password>

<profile>
<id>OC4JDeploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${oc4j.home}\j2ee\home\admin_client.jar</argument>
<argument>${oc4j.deployer}</argument>
<argument>${oc4j.user}</argument>
<argument>${oc4j.password}</argument>
<argument>-deploy</argument>
<argument>-file</argument>
<argument>${basedir}\target\${project.build.finalName}.${project.packaging}</argument>
<argument>-deploymentName</argument>
<argument>myWar</argument>
<argument>-bindAllWebApps</argument>
<argument>secure-web-site</argument>
<argument>-contextRoot</argument>
<argument>myWar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>OC4JUndeploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${oc4j.home}\j2ee\home\admin_client.jar</argument>
<argument>${oc4j.deployer}</argument>
<argument>${oc4j.user}</argument>
<argument>${oc4j.password}</argument>
<argument>-undeploy</argument>
<argument>myWar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

3 comments:

Jeff Black said...

This is good stuff. Any thought to contributing this to the cargo project?

robmadole said...

Using ${file.separator} for when you need a "/" or a "\" will make the arguments in the exec plugin section more platform-independent. One of my biggest pet-peeves is Maven scripts that won't work in linux and on my Mac.

Nayan Hajratwala said...

@robmadole - If you just use forward slashes everywhere, Java will convert them to backslashes automatically.