Configuring Maven’s maven-assembly-plugin

October 27th, 2008

Maven provides an excellent plugin for packaging your application into a binary file called the maven-assembly-plugin. The latest version is 2.3-beta, and should be used to avoid any issues with missing manifest settings in the pom.xml. In my case, i needed to create an executable jar file from my eclipse project that is manage by m2eclipse

To use the maven-assemlby-plugin to create a jar, your pom.xml file should look like so.  Note that i’ve commented out the <descriptorRef> element because I am defining a descriptor file that the plugin will reference using the more versatile <descriptors> element. The assembly-descriptor.xml file it needs to understand how to execute my desired jar-with-dependencies task is referenced as <descriptor> child element:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-3-SNAPSHOT</version>
<configuration>

<descriptors>
<descriptor>/assembly-descriptor.xml</descriptor>
</descriptors>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<mainClass>
com.voyager.VCATApplication
</mainClass>
</manifest>
<manifestEntries>
<mode>development</mode>
<SplashScreen-Image>
vcat-splash.jpg
</SplashScreen-Image>
</manifestEntries>
</archive>
</configuration>
</plugin>

I then create the assembly descriptor file, placing it in the root path (/vcat) alongside the pom.xml.  As long as you provide the correct path in the <descriptor> element, the plugin will find the descriptor file and use the settings defined in it.  Since i wanted to exclude certain files in the final jar, i have to use the <directory> element to define the directory in which my <fileSet> will be valid.  In this case, the files i want to exclude reside in the target/classes directory, and i want to exclude specifically certain some .properties files, which i name explicitly using the <exclude> element, and then all .sql, .csv files using wildcard characters. Note that this syntax will exclude the files defined in the /target/classes file from being output to the root path of the jar, which is what i want - i explicitly tell this to the plugin using the <outputDirectory> element with the root path (/) as the argument.

<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>/target/classes</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>encryptable.properties</exclude>
<exclude>hibernate.properties</exclude>
<exclude>hibernate.cfg.xml</exclude>
<exclude>market-data-securities.properties</exclude>
<exclude>*.csv</exclude>
<exclude>*.sql</exclude>
</excludes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>

Eclipse XML editor

June 26th, 2008

The default Eclipse XML editor is quite useful, especially its ability to import schemas and then strongly type an XML file…

I’ve also installed the Rinzo XML editor, which has great auto-completion assist for DTD, but i was unable to see the same capability using a schema, when i switched my Spring configuration over from DTD to XSD

Hear that the Web Tools Platform’s XML editor is the shizzle…

Spring - Original must not be null

June 26th, 2008

Was getting this during the Bean init of Spring:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name...nested exception is
java.lang.IllegalArgumentException: Original must not be null

so, this post in the Spring forum describes the issue when using “fluent interface”, which is not supported by the JavaBean spec. I was getting the problem because i was missing a setter. Lesson: always make sure your properties have their setter/getters, otherwise Spring will toss this exception en route to wiring your beans…

JXStatusBar

June 26th, 2008

Using JFormDesigner to design a GUI, and am interested in the JXStatusBar, from SwingX offered by Swinglabsthis article discusses its use, and shortfalls. nifty component. seems limited…

Using Java 5 Enums as Keys in a Map or in a List with Spring

June 26th, 2008

Here’s the list of references i’ve found relating to this topic:

  • Use Enums as Map keys
  • Injecting Enums with Spring
  • talking about Java 5 Enums and Spring
  • Excellent example for Enums with Spring

    My solution can be seen in the following snippets. What we’re doing is using Spring to inject values into a Java Generics Map, paramaterized by an Enum as the key; the Map’s value points at a generified strategy class, Calculation<T>:

    I’ve created a class, ViewCalculationMap, which is a LinkedHashMap wrapper. The Map property that we’ll populate with Spring, calculations, is defined in the following snippet:

    public class ViewCalculationMap {
    	LinkedHashMap<ViewProperty,Calculation<TabularViewModel>> calculations;
    	public ViewCalculationMap(){}
    ...
    }
    public enum ViewProperty {
    	Sector("Sector"),
    	Weighting("Weighting"),
    	Amount("Amount"),
    	Return("Expected Return"),
    	Appreciation("Capital Appreciation"),
    	AfterTax("After Tax"),
    	CategoryWeighting("Category Weighting");
    
    	String description;
    	ViewProperty(String description){
    		this.description = description;
    	}
    
    	public String toString(){
    		return this.description;
    	}
    }
    

    and this is configured in Spring like so, noting that the key values are the Enum literals from the ViewProperty Enum. This shortcut works because the Map we’re populating is a Java Generics Map, so we know the type of the key at compile-time.

    <bean id="viewCalculationsMap" class="com.voyager.util.ViewCalculationMap">
    		<property name="calculations">
    			<map>
    				<entry key="Weighting" value-ref="calcSectorWeighting"/>
    				<entry key="Amount" value-ref="calcAmount"/>
    				<entry key="Return" value-ref="calcExpectedReturn"/>
    				<entry key="Appreciation" value-ref="calcCapitalAppreciation"/>
    				<entry key="AfterTax" value-ref="calcAfterTax"/>
    				<entry key="CategoryWeighting" value-ref="calcCategoryWeighting"/>
    			</map>
    		</property>
    	</bean>
    

    I also use a List of Enums in my application. These Enums are of type AssetCategory, which has a similar definition as the ViewProperty Enum defined above. The question is: how to configure Spring to place the Enum values in a list. This can be accomplished using the <util:list> schema, defined in the Spring 2.5 xsd uri

    <util:list id="securityAssetCategories" list-class="java.util.ArrayList">
    		<util:constant static-field="com.voyager.model.AssetCategory.Cash"/>
    		<util:constant static-field="com.voyager.model.AssetCategory.FixedIncome"/>
    		<util:constant static-field="com.voyager.model.AssetCategory.HedgeFund"/>
    	</util:list>
    
  • Generate *.hbm.xml files from Annotated Java POJOs

    May 22nd, 2008

    Maven, Eclipse, Hibernate and Annotations…

    • Despite my earlier thinking, you don’t use the HibernateTools, rather what you want to do (if your project is configured with Maven) is use the Maven plugin for Hibernate3
    • If you’re using Ant, then this guide is what you want to follow.

    For Maven, I’m using the org.codehaus.mojo plugin, hibernate3-maven-plugin, to reverse engineer POJOs into hbm.xml files, and to also generate schema files for my MySQL 5.x db. I setup the plugin with the following configuration block, which lives within the pom.xml:

    <project>
    ...
    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
    <source>1.6</source>
    <target>1.6</target>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.1</version>
    <extensions>true</extensions>
    <configuration>
    <components>
    <component>
    <name>hbm2ddl</name>
    <outputDirectory>src/main/resources</outputDirectory>
    <implementation>annotationconfiguration</implementation>
    </component>
    </components>
    <componentProperties>
    <configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
    <outputfilename>schema.sql</outputfilename>
    <propertyfile>/src/main/resources/hibernate.properties</propertyfile>
    <jdk5>true</jdk5>
    <export>true</export>
    <drop>true</drop>
    </componentProperties>
    </configuration>
    <dependencies>
    <!-- Necessary to be able to connect to db -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
    </dependency>
    </dependencies>
    </plugin>
    </plugins>
    <extensions>
    <extension>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
    </extension>
    </extensions>
    </build>
    ...
    </project>

    Search the Ant documentation to figure out what the different properties that are accepted by the different components, <hbm2ddl>, <hbm2hbmxml> Also look [here] to see the various componentproperty settings for the components; these are settings that will be passed to each component

    You must add the following to the hibernate.cfg.xml file in order to get the plugin to search your classpath for POJOs that it will infer the schema from:

    <mapping class=”com.voyager.model.Asset”/>
    <mapping class=”com.voyager.model.AssetHolding”/>

    And if you want this to be able to generate and export the schema to the db, you have to include a <dependency> section within the <plugin/> element!!!! I found that out [here]. Otherwise, you will get this gem:

    java.sql.SQLException: No suitable driver found for jdbc:

    Bloomberg Market Data Feeds

    May 13th, 2008

    Scarce info exists on the web about accessing market data feeds of securities data through Bloomberg…However, it is possible!!! See the synopsis of the following products. Naturally, they are quite private about their data access methods, and they have strict guidelines about using the data, accessing it, etc… oh, and their fees are not designed at the typical developer:

    • Desktop API - this api is available for interacting with Bloomberg data while logged on at your Bloomberg Terminal. There is a C, COM, and .NET api. Primarily used for getting data into Excel, or apps that reside on the Terminal
    • Data License - this api is more general and allows you to connect to a Bloomberg data feed server from anywhere. you are given an ftp login and can then send requests to the server. the server populates a delimited ascii file and sends it back to you. it is your responsibility to parse this data. not cheap in comparison to market feeds like opentick and IQFeed
    • Server API - this api wraps the Desktop API so that you can present services offered by the Bloomberg Terminal to any clients in your workplace. Must be logged on to the Bloomberg Terminal for authentication.

    Market Data Feed APIs

    May 9th, 2008

    Tool Language Pros Cons Price
    opentick Java open-source
    api is a good data model
    access to numerous Exchanges
    cheap
    includes access to Level I,II, NYSE, OPRA, AMEX, CBOT, ECN
    $435
    DTN NxCore
    Reuters Java/C++ SIAC, NASDAQ, OPRA, NYSE OpenBook, NYSE ARCA ECN, NASDAQ Market Makers, INET ECN and others might be too much
    Strike Iron Web Service AMEX, NYSE, NASDAQ end-of-day pricing on equities $1439-$4319
    Bloomberg C++/COM not java-ready?
    Feed Relay real-time
    persistence-layer option
    seems very high end
    IQFeed C++/Java api available max 500 symbols simultaneous update $700
    JForex FIX API Java only access to Swiss Forex Marketplace $100 dev fee
    PlusFeed institutional

    Financial Data Acquisition

    May 8th, 2008

    Up and Runnin

    May 7th, 2008

    yeehaw, i gots me a wiki, blog, and soon a software development lifecycle manager thingie…sweet