Posts Tagged ‘maven’

Axis2, Maven, and java.net woes and why Maven sucks

I had some interesting problems trying to use the Axis2’s Maven plugin (1.5.1) for generating java code from a WSLD. Here’s what I did to get it working.

First thing’s first I had to define the plugin in my POM:

      <plugin>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
        <version>1.5.1</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>wsdl2code</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <packageName>com.ashlux.myproject</packageName>
          <wsdlFile>src/main/wsdl/myproject.wsdl</wsdlFile>
          <databindingName>adb</databindingName>
        </configuration>
      </plugin>

And don’t forget the necessary Axis2 dependencies:

<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2</artifactId>
    <version>1.5.1</version>
</dependency>
<dependency>
    <groupId>wsdl4j</groupId>
    <artifactId>wsdl4j</artifactId>
    <version>1.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.ws.commons.axiom</groupId>
    <artifactId>axiom-api</artifactId>
    <version>1.2.8</version>
</dependency>
<dependency>
    <groupId>org.apache.ws.commons.axiom</groupId>
    <artifactId>axiom-impl</artifactId>
    <version>1.2.8</version>
</dependency>

That’s more dependencies than I’d want to specify (can’t I just get axiom and wsdl4j transitively?) but otherwise so far so good. Here’s were things took a turn for the worst:

$ mvn clean install
[INFO] Scanning for projects…
[INFO] ————————————————————————
[INFO] Building Rally Java API
[INFO] task-segment: [clean, install]
[INFO] ————————————————————————
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/10/maven-plugins-10.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/7/maven-parent-7.pom

Downloading: http://repo1.maven.org/maven2/org/apache/apache/4/apache-4.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.jar

Downloading: http://repo1.maven.org/maven2/org/apache/axis2/axis2-wsdl2code-maven-plugin/1.5.1/axis2-wsdl2code-maven-plugin-1.5.1.pom

Downloading: http://repo1.maven.org/maven2/org/apache/axis2/axis2-parent/1.5.1/axis2-parent-1.5.1.pom

Downloading: http://ws.zones.apache.org/repository2/org/apache/apache/3/apache-3.pom
[INFO] Unable to find resource ‘org.apache:apache:pom:3′ in repository apache-ws-snapshots2 (http://ws.zones.apache.org/repository2)
Downloading: http://tomcat.apache.org/dev/dist/m2-repository/org/apache/apache/3/apache-3.pom
[INFO] Unable to find resource ‘org.apache:apache:pom:3′ in repository tomcat-repository (http://tomcat.apache.org/dev/dist/m2-repository)
Downloading: http://repo1.maven.org/eclipse/org/apache/apache/3/apache-3.pom
[INFO] Unable to find resource ‘org.apache:apache:pom:3′ in repository eclipse-repo (http://repo1.maven.org/eclipse)
Downloading: https://maven-repository.dev.java.net/nonav/repository//org.apache/poms/apache-3.pom
349b downloaded (apache-3.pom)
[WARNING] *** CHECKSUM FAILED – Checksum failed on download: local = ‘0f56ee033ef4b78d33722aceb71a09c7ed68183f’; remote = ‘ Downloading: https://maven-repository.dev.java.net/nonav/repository//org.apache/poms/apache-3.pom
349b downloaded (apache-3.pom)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '0f56ee033ef4b78d33722aceb71a09c7ed68183f'; remote = ' [INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: org.apache.axis2:axis2-parent:pom:1.5.1

Reason: Cannot find parent: org.apache:apache for project: org.apache.axis2:axis2-parent:pom:1.5.1 for project org.apache.axis2:axis2-parent:pom:1.5.1

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17 seconds
[INFO] Finished at: Mon Jun 14 20:10:40 CDT 2010
[INFO] Final Memory: 3M/15M
[INFO] ------------------------------------------------------------------------

Uh oh, clearly org.apache:apache:pom:3 does exist, so what went wrong? This portion of the Maven output is suspicious:

[WARNING] *** CHECKSUM FAILED – Checksum failed on download: local = ‘0f56ee033ef4b78d33722aceb71a09c7ed68183f’; remote = ‘ Downloading: https://maven-repository.dev.java.net/nonav/repository//org.apache/poms/apache-3.pom

That is some checksum coming from https://maven-repository.dev.java.net/nonav/repository, definitely can’t be right! The culprit lies in org.apache.axis2:axis2-parent:1.5.1:

        <repository>
            <id>java.net</id>
            <url>https://maven-repository.dev.java.net/nonav/repository/</url>
            <layout>legacy</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>

The problem is Maven does not support permanent redirects (301). There are several workarounds, from modifying your local repository to adding a mirror for java.net for your settings.xml, none of which I find appropriate since builds are unnecessarily broken for new developers. I chose the settings.xml since I think it’s the cleanest out of all of them:

<settings>
  ...
  <mirrors>
    ...
    <mirror>
      <id>java.net.2</id>
      <name>java.net Mirror of http://repo1.maven.org/maven2/</name>
      <url>http://download.java.net/maven/2/</url>
      <mirrorOf>java.net</mirrorOf>
    </mirror>
  </mirrors>
</settings>

Times like this I think we’d be better off we “all made a big mistake in coming down from the trees in the first place.” I heard some guys on the Java Posse arguing arguing that “even the trees had been a bad move, and that no one should ever have left the oceans.”

 

Hudson and the Sonar plugin fail: MavenInstallation NoSuchMethodError

No. Not this Hudson.

No. Not this Hudson.

We ran into an interesting and less than informative error when configuring Maven with our Hudson installation. Maven worked great, as expected, but the Sonar plugin stopped working and were causing builds to fail.

The error message wasn’t terribly helpful:


FATAL: hudson.tasks.Maven$MavenInstallation.forNode(Lhudson/model/Node;Lhudson/model/TaskListener;)Lhudson/tasks/Maven$MavenInstallation;
java.lang.NoSuchMethodError: hudson.tasks.Maven$MavenInstallation.forNode(Lhudson/model/Node;Lhudson/model/TaskListener;)Lhudson/tasks/Maven$MavenInstallation;
at hudson.plugins.sonar.SonarPublisher.getMavenInstallationForSonar(SonarPublisher.java:204)
at hudson.plugins.sonar.SonarPublisher.executeSonar(SonarPublisher.java:213)
at hudson.plugins.sonar.SonarPublisher.perform(SonarPublisher.java:177)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildStep(AbstractBuild.java:372)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildStep(AbstractBuild.java:360)
at hudson.model.Build$RunnerImpl.post2(Build.java:183)
at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:345)
at hudson.model.Run.run(Run.java:943)
at hudson.model.Build.run(Build.java:112)
at hudson.model.ResourceController.execute(ResourceController.java:93)
at hudson.model.Executor.run(Executor.java:119)

A little Googling, I found just two hits.

One result was helpful in which it said the Sonar plugin is compatible with Hudson 1.306+. Currently we’re running 1.303. We’re not exactly far behind, but apparently far enough behind.

Backing up Hudson

While there is a backup plugin for Hudson. The plugin would be ideal, but in case just installing the plugin screws something up, best do a manual backup.

The easiest way to manually backup Hudson is to just copy your Hudson working directory. However, space is limited for us, so a backup that was more selected was necessary. This script seemed to backup the most important configuration files (it wouldn’t make for a pretty recovery, but it’d work):

#/bin/sh

cp $HUDSON_HOME/*.jar $NEWHUDSON_HOME/
cp $HUDSON_HOME/*.xml $NEWHUDSON_HOME/
cp -r $HUDSON_HOME/plugins $NEWHUDSON_HOME
for job in $HUDSON_HOME/jobs/*; do
        echo "Processing $job"
        mkdir -p "$NEWHUDSON_HOME/jobs/$job"
        cp "$job/config.xml" "$NEWHUDSON_HOME/jobs/$job/config.xml"
done
All aboard!

All aboard!

All aboard the fail boat

The upgrade appeared to go well, but after manually starting the Windows service, I get an error. Amusingly, the hudson.err.log showed some slight inconsistencies:

Jul 27, 2009 2:38:03 PM hudson.model.UpdateCenter$DownloadJob run
INFO: Installation successful: hudson.war
Invalid or corrupt jarfile C:\hudson\hudson.war

Hudson the Butler can’t make up his mind; it’s claiming success before imploding on itself.

Hudson recuperated

Skimming around and very annoyed my butler had blatantly lied to me, I noticed hudson.war was sitting at only 2 MB. Yah, that can’t be right.

Luckily the fix was easy: Hudson was successfully fixed by manually downloading the newest hudson.war and replacing the messed up version.

It turns out I really did not need to backup Hudson. Though naturally if I hadn’t backed up Hudson I will have needed my backup!

Upgrading to Hudson 1.317 solved the mysterious java.lang.NoSuchMethodError error. I would not have thought configuring a Maven installation rather than using Hudson’s default would cause issues. Go figure.

 

potbs4j 0.4: Java library for Pirates of the Burning Sea web services

Pirates in your Java, sacking the classloader.

Pirates in your Java, sacking the classloader.

A few weeks ago I put together a Twitter publisher for Pirates of the Burning Sea (PotBS) for my wife.  She plays the game perhaps a bit too religiously. :-)   Anyhow, two things get published to twitter: (1) server status changes, and (2) in-game port status changes (who is battling who).

To make life a little easier, I wrote potbs4j, a Java library  to work with PotBS services. (My name for the library is genius, really!)  There really wasn’t any need to couple the twitter publisher with XML parsing and HttpURLConnection.

I doubt ayone will make use of the library, but if anyone is really interested in using it, I’ve worked out some usage instructions here.

If you’re using Maven (highly recommended), just include the potbs4j in your list of dependencies:

<dependency>
<groupId>com.ashlux.potbs</groupId>
<artifactId>potbs4j</artifactId>
<version>0.4</version>
</dependency>

Since potbs4j does not exist in the central repository, you will also need to add my maven repository (it’s slow but works) to your pom.xml:

<repositories>
<repository>
<id>ashlux-repository</id>
<url>http://www.ashlux.com/maven2/repo</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository><id>ashlux-snapshot-repository</id>
<url>http://www.ashlux.com/maven2/snapshotRepo</url>
<snapshots>
<enabled>true</enabled>
</snapshots></repository>
</repositories>

You can get the server status with the following code:

ServerStatusService serverStatusService =
new ServerStatusServiceImpl("apikey", "userid");

// get list of all server statuses
ServerListDocument serverListDocument =
serverStatusService.getAllServerStatuses();

// get server status for a single server
ServerDocument serverDocument =
serverStatusService.getServerStatus(ServerName.Antigua);

You can get the server status with the following code:

LandmarkStatusService landmarkStatusService =
new LandmarkStatusServiceImpl("apikey", "userid");
// get list of all port statuses for a server

PortListDocument portListDocument =
landmarkStatusService.getAllLandmarkStatuses(ServerName.Antigua);

// get list of all port statuses for a server
PortListDocument portListDocument =
landmarkStatusService.getLandmarkStatus(ServerName.Antigua, PortName.IRSH_PT);

There are also two utility classes NationUtils (for converting a nation to a nationality) and PortUtils (for converting a PortName.Enum to a string).

An important thing to keep in mind: the library currently does NOT cache results, so you will need to handle this on your own.  Both of the services do implement a method called getMinimumUpdateFrequency that returns the minimum number of minutes you should wait until calling the service.

The source code is hosted on github in all its glory.