Wednesday 27 August 2008

Update on Weblogic with Tuscany

Wow, it's been a while!

Anyway, I've had a few people mailing me through the Tuscany mailing list to ask Weblogic specific questions, this one comes up most frequently:

java.lang.LinkageError: loader constraints violated when linking
javax/xml/namespace/QName class

Basically, to cut a very very long story short, this is to do with the way Weblogic handles it's ClassLoaders - as this class has already been loaded by the initialisation of the Server in the core ClassLoader it will complain whenever it is attempted to be loaded again from an alternative source which doesn't match the original (if you search the web you'll find a number of references to this!)

So the solution is actually pretty simple - use Weblogic's XML Libraries and parsers. In one of Tuscany 1.3.1 webapps I add the following xml to exclude all of the dependencies that bring in XML libraries:

  <dependency>
   <groupId>org.apache.woden</groupId>
   <artifactId>woden</artifactId>
   <version>1.0-incubating-M7b</version>
   <scope>provided</scope>
  </dependency>

  <dependency>
   <groupId>xalan</groupId>
   <artifactId>xalan</artifactId>
   <version>2.7.0</version>
   <scope>provided</scope>
  </dependency>

  <dependency>
   <groupId>xerces</groupId>
   <artifactId>xercesImpl</artifactId>
   <version>2.8.1</version>
   <scope>provided</scope>
  </dependency>

  <dependency>
   <groupId>xml-apis</groupId>
   <artifactId>xml-apis</artifactId>
   <version>1.3.03</version>
   <scope>provided</scope>
  </dependency>


Once that's in, you should be ready to go!

Thursday 14 February 2008

Jetty with Maven

One of the things that Maven always promised to deliver was a dramatic reduction of development time and more uniform development patterns. The jetty plugin from mortbay really does deliver on these promises - it is one of those plugins that really make me sit back and go "why didn't anyone do this sooner".

Basically, for when your developing a webapp and need a quick test of it, then jetty comes to the rescue. Simply drop the following configuration into your webapp's pom.xml:

<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
Then from the command line run:
  mvn jetty:run
This will start up jetty and run from the target/${build.finalName} directory - this means that as you continue developing Jetty is updated with the changes you make as you rebuild your artifact.



Pretty cool! This plugin obviously comes with a whole bunch of configuration options, but in it's default state it suits most of my needs. The only configuration I usually use is to update the port that Jetty is hosted on, this following config does that for you, updating the port to :8081

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8081</port>
</connector>
</connectors>
</configuration>
</plugin>
More details on the plugin can be found at http://www.mortbay.org/maven-plugin
which covers more configuration options you can shake a stick at!

I've been using this whilst developing Apache Tuscany enabled webapps, it really has improved my turnaround, so I thought it'd be useful to share!

Monday 11 February 2008

Using Tuscany with Weblogic

I've been playing around with Apache Tuscany quite a bit recently - it's an open source runtime based on the Service Component Architecture and to be pretty frank it's really cool :)

One of the things I needed to do was deploy a Tuscany based webapp to Weblogic - so I thought I'd throw together some brief instructions here....

The samples as provided by Tuscany don't work straight off on Weblogic - this is due to the way that Weblogic handles the content of WEB-INF/classes within a webapp - it's all packaged up into a jar and moved to the equivilant of WEB-INF/lib/your-classes.jar so that the Tuscany ClassLoader then can't access it.

Using samples/calculator-webapp as an example of how to get this to work, you just to make these changes.....

Firstly, you need to move the file:

src/main/resources/Calculator.composite

to

src/main/webapp/META-INF/Calculator.composite

This has the result of moving the .composite file back to a location accessible to the Tuscany ClassLoader used to parse the composite files.

You'll also need to create a src/main/webapp/WEB-INF/weblogic.xml with the following content:

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

This will enforce the contents of WEB-INF/lib (ie the Tuscany runtime) is higher in the ClassLoader than the weblogic entries - to make sure we use the Tuscany friendly implementations of things like XML parsers.

Once that's done, package up the example as normal (see the example's README if your unsure) to produce the webapp war.

Next, for weblogic - you'll need a suitable version of Weblogic installed that supports Java 5 - I'm using Weblogic 9.2MP2. Once you've got it installed and a suitable domain created you should go on over to the weblogic console - http://localhost:7001/ is the default, it'll be different if your using non-localhost or non-standard ports:



In order to allow you to make changes to your domain, you'll need to hit the Lock & Edit Button:



If you select the Deployment option under "Domain Structure" you'll then be presented with a screen which allows you to Install new applications:



Hit the Install button to be presented with the install assistant - here you can either navigate on your local disk to the application:



or select the upload your file(s) option - which I find much easier to use:



Hit the Browse Button for the "Deployment Archive:" option, navigate to your webapp and once your happy click next, you'll be presented with a screen which confirms the upload has completed successfully and that your webapp is available to deploy:



Ensure the radio button is selected next to your webapp and hit Next, you'll be presented with the following screen:



Leave this screen as is and Next again :)



You can leave this screen as it is and just hit Finish, this will take a moment or two, before you'll be presented with the following screen:



We're now able to Activate our changes and deploy the webapp, so go ahead and hit the Activate Changes button:



The page will refresh, our webapp will be deployed, but we're not quite there yet! You need to now start the webapp, so from the Deployments list you should select this webapp and then Start > Servicing all requests, as follows:



Next you'll be asked to confirm that your happy to start this webapp:



Hit Yes, wait a mo or two and you'll be presented with a Message to confirm that your webapp has started and is available for service:



We can now take ourselves over to http://localhost:7001/sample-calculator-webapp (again this is the default, update accordingly) where this webapp is being hosted:



All done! You've got your SCA application running with Tuscany on Weblogic 9.2 :)

These tests are with the 1.1-incubating release and mostly I've used a Sun JDK (1.5.0_10), though a few initial trials with JRockit and all seemed to work as expected.

Hopefully that should help a few people out!