Archive for the ‘java’ Category
« Older EntriesPer-assembly filtering with the maven-assembly-plugin
Monday, January 18th, 2010
Posted in: filtering, maven assembly plugin J2EE, java, maven 2.
The maven assembly plugin is an extremely powerful tool when it comes to creating custom distributions (aka assemblies) of your artifacts for individual platforms etc. However, the ability to create multiple variants of an artifact within a single build conflicts with the standard maven approach of using multiple build profiles and executing a single build for each profile to generate artifact variants.
This also means that mavens resource filtering is not very useful for individual assemblies, since you can only replace placeholders such as ${someValue} with the same value for all assemblies (since resources are only filtered once, using the active profile(s), for all assemblies).
You can, however, configure the maven assembly plugin to use individual filter property files for each assembly using the <execution> section of the plugin configuration, like so:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<executions>
<execution>
<id>production</id>
<goals>
<goal>single</goal>
</goals>
<configuration>
<filters>
<filter>${project.basedir}/src/main/assembly/production.properties</filter>
</filters>
<finalName>${artifactId}-production-${version}</finalName>
<ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
</execution>
<execution>
<id>integration</id>
<goals>
<goal>single</goal>
</goals>
<configuration>
<filters>
<filter>${project.basedir}/src/main/assembly/integration.properties</filter>
</filters>
<finalName>${artifactId}-integration-${version}</finalName>
<ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
</execution>
</executions>
</plugin>
This snippet uses the same assembly descriptor (you can use any assembly descriptor, actually) to build individual artifacts for production and integration. Note that the ${project.basedir}/ prefix is a workaround for MASSEMBLY-150 and is nedded to avoid a nasty Failed to create assembly: Error filtering file ... Error loading property file 'src/main/...' error when executing the mojo from outside the module directory (say, for instance, in a mvn release:prepare…).
Filtering must be enabled in the assembly descriptor, like so:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/xsd/assembly"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/xsd/assembly http://maven.apache.org/xsd/assembly-1.1.1.xsd">
...
<fileSets>
<fileSet>
<filtered>true</filtered>
...
</fileSet>
</fileSets>
</assembly>
Thanks to John Casey for suggesting this in MASSEMBLY-430!
No CommentsObtaining the default charset (aka platform encoding) in JAVA
Monday, November 9th, 2009
Posted in: Charset, Platform encoding java, open source.
… is really simple since JDK 1.5:
java.nio.charset.Charset.defaultCharset()
So please don’t use messy, old workarounds such as this:
byte [] byteArray = {'a'};
InputStream inputStream = new ByteArrayInputStream(byteArray);
InputStreamReader reader = new InputStreamReader(inputStream);
String defaultEncoding = reader.getEncoding();
Which, unfortunately, is one of the first things you stumble upon when searching for this topic.
No CommentsUsing RPC-style, encoded Axis 1 webservices with spring-remoting
Monday, October 12th, 2009
Posted in: Axis 1, Jax-ws, Spring-Remoting J2EE, System architecture, java, open source.
Preamble
When working with enterprise integration you will quite often deal with legacy systems integration.
I recently had the case where integration of webservices was requested, and much to my surprise there are huge issues when attempting to integrate old webservices (as in pre axis2 and pre jax-ws).
These webservices use outdated or unsupported methods, such as rpc-style/encoded communication, or even worce, outdated elements in the XML messages, for instance <multiref>’s. Having to integrate such services does of course imply that you cannot change anything on the server side, and thus such an outdated format must still be consumed.
This is a huge problem, since current WS implementations, such as the popular axis2 framework, do simply not support these formats.
What surprised me the most about this is that webservices are designed to make systems independent by defining a common communication and data format, which is the exact opposite of what is going on here – and these formats are not that old, we are probably talking 4-5 years.
Developers facing these problems are taking rather desperate measures to work around these problems, such as using on-the-fly XSLT transformation to convert incoming and outgoing WS messages. However, this binds your application even stronger to the outdated format and specific service data.
In my case I wanted to use Spring-remoting. Since the service was RPC-style, I wanted to use the JaxRpcPortProxyFactoryBean to create an on-the-fly proxy implementing the service interface. What I did not want to do is having to write any additional code to consume the service. Furthermore, I wanted the complex objects transferred by the services to be represented by standard JAVA beans, and not be generated using the wsdl2java axis1 tools. Here is how I got this to work.
Read the rest of “Using RPC-style, encoded Axis 1 webservices with spring-remoting”
Using apache to redirect from the root “/” context to a webapp context
Monday, October 12th, 2009
Posted in: apache, java, open source, tomcat.
Just a short note:
The best way of doing this avoiding endless recursion is to use apaches RedirectMatch rule, like this:
RedirectMatch ^/$ http://targethost/mywebapp
Easy, agreed. But i’ve seen (and done it wrong my self) quite often…
No CommentsSorry guys, server crash…
Friday, September 11th, 2009
Posted in: dude, oh crap, where is that backup java.
Folks,
There was a hardware crash at the hosting center that has caused a complete exchange and re-installation of this server.
I’ve got older backups running now, recent posts are not up yet but will be within the next week.
Posts may still look crappy and outtakes may occur, but for now, a least the older stuff is back online…
Greetings
Olaf
Running mvn:release with Subversion 1.5.x
Monday, March 23rd, 2009
Posted in: J2EE, SCM, System engineering, java, maven 2, open source, subversion.
When attempting to prepare a release using maven and the maven-release-plugin, you are currently very likely to see your build fail with a message such as:
[INFO] Executing: svn --non-interactive copy --file /tmp/...commit . https://subversion..../tags/...
[INFO] Working directory: ...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to tag SCM
Provider message:
The svn tag command failed.
Command output:
svn: Commit failed (details follow):
svn: File '...' already exists
If you do, you are using subversion 1.5.x which no longer supports tagging from a local working copy, thus causing the unfortunately very misleading error message.
This is a known issue of the subversion sourcecode management (SCM) and there is a simple workaround:
Read the rest of “Running mvn:release with Subversion 1.5.x”
Modular development with OSGI about to be very, very popular – finally.
Monday, March 2nd, 2009
Posted in: J2EE, JPA, OSGI, System architecture, eclipselink, java, open source, spring.
It’s quite exciting to see the tremendous progress in development tools, patterns, frameworks and libraries since the release of JAVA 1.0 in 1996.
Within just thirteen years, development improved from the first applets, from the dark ages of the first EJB standardization attempts and a lack of suitable development processes into an age where aspect oriented programming, dependency injection and a freely available range of lightweight yet extremely powerful frameworks, libraries and API’s finally permitted the humble programmer to do what he always wanted to do – analyze problems, and elegantly write them down without spending all of his precious time on the syntax.
I would even go as far as saying that there was no object orientation before programming crosscutting concerns and using dependency injection became established mechanisms.
Think about it: The original goal of OO is not to use inheritance, encapsulation, identity and polymorphism, but to express the real world of things – our reality – using an abstract world of things, while preserving most of the properties and relationships we observe in reality.
Before AOP, before being able to separate the description of things from creating, configurating and connecting concrete instances through dependency injection frameworks, this goal was hard to achieve.
Modules larger than classes with OSGI
Now however, we are about to reach a new stage in development of object orientation in JAVA: Developing modules that are larger than classes, modules which can, once properly identified, be developed independently using all the wonderful technology described beforehand. The technology used to achieve this has a name: OSGI. This technology has quite a long history of development, but a certain lack of elegance and light-weightiness barred this component model from becoming a real hit in the worldwide development community. This is about to change.
Read the rest of “Modular development with OSGI about to be very, very popular – finally.”
Maven, Surefire, remote debugging and the -javaagent switch
Monday, February 2nd, 2009
Posted in: J2EE, java, maven 2, spring.
When using maven surefire in conjunction with remote debugging (mvnDebug, for instance)
it seems necessary to disable forking of the test executions into separate processes, as the remote debugging works process wise. This is usually done by setting the the fork mode to never, e.g. by specifying -DforkMode=never on the command line.
This is, however, a misunderstanding. mvnDebug is there to enable debugging of the maven process and not of the surefire execution – and disabling forking may have various side effects. One of those is the use of Java agents. When using agents, e.g. for loadtime-weaving in the Spring Framework, one often specifies a -javaagent: as a JVM argument for surefire:
Read the rest of “Maven, Surefire, remote debugging and the -javaagent switch”
Repository search for maven artifacts
Monday, November 10th, 2008
Posted in: java, maven 2, open source.
Most of the maven users know the site www.mvnrepository.com which provides a nice lookup of maven artefacts.
Now there is also a newer site, www.mvnbrowser.com which currently performs better than mvnrepository. In addition, you can lookup repositories actually containing your desired artifact – now that’s sweet!
Solving the eclipselink (former toplink) issue with HSQLDB
Tuesday, August 12th, 2008
Posted in: J2EE, JPA, eclipselink, java.
When using the great hypersonic java database (hsql) with eclipselink 1.0, i stumbled upon a schema generation (ddl generation) issue. It appears as though eclipselink generates “CREATE TABLE…” statements containing UNIQUE keywords which are incompatible with HSQLDB.
As it turned out, there already is an issue filed for the problem (240618).
The resulting exceptions look like this:
[EL Warning]: 2008.08.12 11:01:13.134--ServerSession(28607378)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Unexpected token: UNIQUE in statement [CREATE TABLE ... (ID INTEGER UNIQUE]
Error Code: -11
Read the rest of “Solving the eclipselink (former toplink) issue with HSQLDB”