Posts Tagged maven

making m2 salad

Irrelevant Silliness

So… I’m a vim hold out. I still care deeply about emacs and it’s spawn being defeated once and for all.

Which means I don’t really like bloated IDE’s like Eclipse…. which makes me a pariah… which means people whisper and plot against me behind my back…

And… they’re always out to get me… and…

Ahem… sorry, about that… Like I was saying….

Which means I prefer to write a lot of tools and utilities to provide the sort of out-of-the-box functionality other people are perfectly happy to point and click thru with their brains in the neutral gear.

It’s part of a sickness I have… and I am going to confess it here on the internet: I love programming computers.

I know, I know… appalling! The gall! But there it is! My dirty little secret!

So what have I brewed up this time?

You know that functionality which lets you see right click and see methods, etc in Eclipse?

I thought it would be nice to have something like it for the CLI where I can use grep the way the Lawd intended. Here is the soup-to-nuts for nuts.

Finally he gets to the point

% m2_salad.sh 
m2_cp.txt is older than pom.xml... rebuilding m2_cp.txt
m2_soup.txt is older than m2_cp.txt... rebuilding m2_soup.txt
m2_salad.txt is older than m2_soup.txt... rebuilding m2_salad.txt

Zounds! So I wrote 2 new scripts: m2_soup.sh and m2_salad.sh.

Like m2_cp.sh, each produces a file named X.txt with some junk in it.

Here is the breakdown:

m2_cp.txt      colon separated list of the jars maven uses
m2_soup.txt    list of all the classes defined in the m2_cp.txt jars
m2_salad.txt   javap of all the classes listed in m2_soup.txt

These along with the standard UNIX CLI utils provides the same sort of handy lookup funtionality, where it belongs: in the CLI, not in the editor.

And?

Well… OK, maybe it could live in the editor too if it was slim-and-fast and minimalist…

I’ve really enjoyed the vim plugin supertab for tab completion.

Part of the challenge of integrating it with the output from the scripts is to make the completion be contextual… Which means a plugin would have to have some notion of the program semantics.

For example, it would need to know that a piece of text was a variable and what it’s type was so it could lookup the appropriate methods.

Not easy, but I’m a big believer in the 90/10 rule.

Alternatively… what other sort of useful development application could be written leveraging this info?

Good times… good times…

Leave a Comment

4 useful shell scripts for maven

yeah maven

Maven (2 of course) is the jam when it comes to Java build systems.

Ant is some old timey donkey-mess madness which doesn’t even address the issue of dynamic build dependency resolution.

There are other build systems like: ivy, maven1, and made-up-mess, but the real goodness is the m2 universe.

In addition, to it’s main duties, maven produces a really neat resource in the form of your local repository (mine lives in ${HOME}/.m2/repository).

The dependencies your project pulls in also pull in dependencies and some of them are cool things you didn’t even know you couldn’t live without!

Here are a few scripts I use to leverage a little bit of that powerful force for funtimes!

m2_cp.sh : maven classpath

Maven compiles all your code and runs all your test cases. To do that it has to use an olde timey classpath just like duh, but …. how can you get at it when all you see is your pom.xml?

You can use the olde school trick: mvn -X test -Dmaven.test.skip=true ; and scrap it out of there

Or… you can use my little m2_cp.sh and it will parse it out for you into a file called “m2_cp.txt” that you can use to play more reindeer games.

Like what?

Like packaging up some tarball+script to run your stuff, or some uberJar (though the assembly plugin is a better solution for that), or maybe some…

m2_javap.sh : all your class are… ok…

Almost every Java developer uses an IDE. They pretty much all use eclipse.

I’m in that oddball 0.01% that just uses eclipse as a remote debugger… so… I use a lot of command line tools instead, for example: javap

The javap command will print the method signatures given a list of class names. But… you have to feed it a classpath.

In tricky eclipse, this happens like magic! Neat! But… as a magician, I want to be the magical man… so…

When I’m working on say, a portlet project (from maven-archetype-portlet), and I’m wanting to see some good times, I type: m2_javap.sh javax.portlet.GenericPortlet

Even that too much bother? How ’bout: m2_javap.sh GenericPortlet

m2_latest.sh : to the greatest

Ever use log4j in a project? Ha! Yeah… so now you have a new project and you want to pull it in again… what as the most recent version: m2_latest.sh log4j ; tells you the jar

m2_dep.sh : jar file to dependency

OK, so you need log4j, and the latest is ${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar ; time to start typing that annoying stanza… but wait:

m2_latest.sh log4j | m2_dep.sh

% m2_latest.sh log4j | m2_dep.sh

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>

Script it up

The local repo is really neato! Perfect scripting fodder! Good times…

Leave a Comment

dear maven, yes! I want to use fckng java 1.5 generics, you ass!

OMG! I am so…. tired of doing this for every new archetype’d project:

<build>
	<plugins>
		<plugin>
			<!-- seriously? -->
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.5</source>
				<target>1.5</target>
			</configuration>
		</plugin>
	</plugins>
</build>

The gnashing of teeth!

Leave a Comment

update: maven + seam numberguess demo

Well… I finally got around to cleaning this up and getting it completely converted over to maven2 using seam 2.0.0.BETA1.

The troubles I had with the ear plugin went away when I move to maven 2.0.9!

Here is the quick and dirty:

% wget http://brianin3d.googlepages.com/in3.tgz
% tar xfz in3.tgz 
% cd in3/
% mvn package
% cp ear/target/in3.ear .  
% mv in3.ear ${JBOSS_HOME}/server/default/deploy/in3.ear 

hit it as http://localhost:8080/seam-numberguess-mvn

Next up, I want to try a bigger app like the dvd-store example.

Then I should be able to create an archetype 😀

For now, the tarball makes a pretty good maven2 starting point for some types of fun

Comments (2)

how ’bout a nice game of mvn+seam+jsf mit jboss?

I spent some time looking for a good recent archetype to do this that actually worked before giving up and deciding to do it in 3 easy pieces as part of a multiproject.

Since I’m pretty gnu to seam/jsf, I decided to start with seam-numberguess-2.1.0.CR1.ear and put it back together again.

Sadly, this process didn’t result in a completely clean solution… in the end I couldn’t quite get the ear plugin to do what I wanted and ended up overriding the application.xml, jboss-app.xml, jamming some stuff into a lib dir in the ear etc.. Hope to clean it up at some point.

Perhaps you can get softeu to work for you… for me it just blowed up in various interesting ways…

multiproject

groupId=jsf-in3
package=us.versus.them.demos.jsf.in3
version=1.0.0-SNAPSHOT
common="-DgroupId=${groupId} -DpackageName=${package} -Dversion=${version}"
webapp=-DarchetypeArtifactId=maven-archetype-webapp

mvn archetype:create ${common} -DartifactId=in3-project
cd in3-project
cat pom.xml | sed 's,>jar<,>pom<,' > fu
mv fu pom.xml
mvn archetype:create ${common} -DartifactId=in3-jar
mvn archetype:create ${common} ${webapp} -DartifactId=in3-war
mvn archetype:create ${common} ${webapp} -DartifactId=in3-ear

Unfortunately, there is a lot more junk that has to be done by hand… Stuff that is really pretty dumb.

java 5, please

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

jboss repo

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>jboss</id>
            <name>JBoss Maven Repository</name>
            <layout>default</layout>
            <url>http://repository.jboss.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

war: wtf is it good for?

So I pulled the goodies out of the war and put them in their maven-ish spots:

.
|-- pom.xml
`-- src
    `-- main
        |-- resources
        |   `-- messages.properties
        `-- webapp
            |-- WEB-INF
            |   |-- components.xml
            |   |-- pages.xml
            |   `-- web.xml
            |-- cheat.jspx
            |-- confirm.jspx
            |-- giveup.jspx
            |-- index.html
            |-- index.jsp
            |-- jboss-seam-numberguess.war
            |-- lose.jspx
            |-- niceforms.css
            |-- niceforms.js
            |-- numberGuess.jspx
            `-- win.jspx

there is a also a “images” directory under webapp I left out, cuz it’s kinda boring.

This structures is a little lame, but I don’t wanna change too much right now…

war deps

There are a two deps that I resolved to something like this:

  <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.7.0</version>
  </dependency>
  <dependency>
      <groupId>jboss</groupId>
      <artifactId>jboss-seam-ui</artifactId>
      <version>2.0.0.BETA1</version>
  </dependency>

jar it

mkdir -p src/main/resources
touch src/main/resources/seam.properties

seam.properties has to end up in the root of the jar or seam will not work!!!! it will be broken!!! even though it is just a dumb empty properties file!!!! don’t forget it!!!!

You will end up with a nasty bit like:

javax.servlet.ServletException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(selectGuessRadio).  Found null.

and even if you hack the jspx you will end up with something like:

javax.servlet.ServletException: /numberGuess.jspx(42,82) '#{numberGuess.currentGuess}' Target Unreachable, identifier 'numberGuess' resolved to null

And you may tear your hair out! And you may gnash your teeth! And when you find out the problem you may want to post it on your blog so noone else will have to suffer the same fate! I would imagine… 😉

jar it up some more

mkdir -p src/main/java/org/jboss/seam/example/numberguess/
cp NumberGuess.java ${_}

I snagged mese’f a copy of NumberGuess.java

The biggest thing the tutorial left to the imagination was the imports:

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

Presumably in the interests of brevity…

jar deps

  <dependency>
      <groupId>jboss</groupId>
      <artifactId>jboss-seam</artifactId>
      <version>2.0.0.BETA1</version>
  </dependency>

ear is totally wrong

I dunno what else to say about it… Ended up redoing the whole pom and even then it wasn’t right. The jboss-app.xml was always empty, I couldn’t get it to quit being dumb about being smart about ejbModules…

In the end, I clobbered the generated application.xml and jboss-app.xml with the ones from the seam-numberguess-2.1.0.CR1.ear

cp pageflow.jpdl.xml cheat.jpdl.xml target/in3 
cp jboss-app.xml application.xml target/in3/META-INF 
jar cf in3.ear -C target/in3 . 
mv in3.ear ${JBOSS_HOME}/server/default/deploy/

final product

As I said in the beginning this was not a 100% success, but it was a lot closer than when I started:

% wget http://brianin3d.googlepages.com/in3-project.tgz
% tar xfz in3-project.tgz
% cd in3-project
# this assumes you have JBOSS_HOME defined...
% mvn package &&  ( cd in3-ear/ ;  ./bother.sh )

Hit http://localhost:8080/seam-ng-mvn to see it in action.

A rough start, but at least it’s a start… 😀

Leave a Comment

Amazon S3 Library for SOAP in Java

UPDATE!

After trying to run the code based on this blog, it suddenly just doesn’t work!

Recommend you look at JetS3t which provides a nice wrapper around the S3 SOAP stuff.

The main reason not to the S3 SOAP directly is because signing requests is a complete pain in the ass.

Woe is me!

After looking a lot of tools, I decided I need to write a one-off for my application to update ACL’s. All the tools I found wanted to pull back every ACL and update it! I want all my keys in this part of my bucket to have the same ACL.

I tried to use the wsimport’d library, but….

javax.xml.ws.soap.SOAPFaultException: The SOAP 1.1 request is missing a security element
    at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171)
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:102)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
    at $Proxy33.getObjectAccessControlPolicy(Unknown Source)
    at us.versus.them.jarczar.publisher.AppTest.testApp(AppTest.java:44)

OSS to the Rescue

I cursed and cried and then found the Amazon S3 Library for SOAP in Java. The only bit I really wanted was com.amazon.s3.AWSAuthConnection which takes care of the blasted authentication nonsense.

Compiling s3-example-libraries

Compiling it was fun:

% javac -d out $( find com -name "*.java" ) -classpath ${HOME}/.m2/repository/org/codehaus/castor/castor/1.2/castor-1.2.jar:${HOME}/.m2/repository/org/apache/axis/axis/1.4/axis-1.4.jar:${HOME}/.m2/repository/com/sun/javaee/javaee/5.0/javaee-5.0.jar
% jar cf  s3-example-libraries.jar -C out .
% addToRepo.sh com.amazon.s3 1.0.0 s3-example-libraries.jar
${HOME}/.m2/repository/com/amazon/s3/s3-example-libraries/1.0.0

Using it

Using it was trivial:

import com.amazon.s3.AWSAuthConnection;
import com.amazonaws.s3.doc._2006_03_01.*;

//....

AWSAuthConnection aws = new AWSAuthConnection( awsAccessKeyId, awsSecretAccessKey );
AccessControlPolicy acl = aws.getACL( bucket, key );

Maven Dependencies

It did pull in a few deps....
        <dependency>
            <groupId>org.codehaus.castor</groupId>
            <artifactId>castor</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>com.amazon.s3</groupId>
            <artifactId>s3-example-libraries</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.javaee</groupId>
            <artifactId>javaee</artifactId>
            <version>5.0</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.4</version>
        </dependency>
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-wsdl4j</artifactId>
            <version>1.5.1</version>
        </dependency>

bloc

Leave a Comment