Glassfish v3 Maven plugin

Apparently there is a plugin for Maven that allows you to deploy your application against an embedded maven server http://blogs.sun.com/sirajg/entry/using_maven_plugin_for_v3

If it works, I’ll be able to get rid of all the complicated Maven XML I have for downloading and installing Glassfish V2.

There is documentation available for the plugin in the Sun GlassFish Enterprise Server v3 Embedded Server Guide

Performing a SQL distributed query by using ADSI

For historical reasons, I have the personalisation information for some users stored in a Sun LDAP server, and I have some data about them stored in a Microsoft SQL Server. Unfortunately we are using Microsoft Reporting services.

In the database users are referred to by a system wide unique identifier. The mapping from this unique identifier to the user’s display name is stored in the LDAP directory server.

Fine, I thought, I think SQL Server has a way to do queries which span multiple data sources. And I think Microsoft has a way to talk to Active Directory servers over LDAP. So, I should be able to co-opt that for my purpose.

Only it turns out that you can’t.

[OLE/DB Provider ‘ADSDSOObject’ IRowset::GetData returned 0x40eda: Data status returned from the provider: [COLUMN_NAME=sn STATUS=DBSTATUS_E_CANTCONVERTVALUE]]

A lot of LDAP attributes are marked as multi-valued in the schema. And, even though I know that there will only be one value (I am happy to treat multiple values as an error condition) – the ADSDSOObject just doesn’t support multi-valued attributes, no matter how many values there actually are. Its in the distributed query documentation. For various other reasons I can’t change the LDAP schema.

The first limitation is that multivalued properties cannot be returned in the result set to SQL Server. ADSI will read schema information from the LDAP server that defines the structure and syntax of the classes and attributes used by the server. If the attribute that is requested from the LDAP server is defined in the schema as being multi-valued it cannot be returned in an OPENQUERY statement.

So near, and yet so far away as to be nearly incomprehensible. Why, oh why did they design it that way?

Apache VFS URI with spaces

Apache VFS currently seems to have a problem handling file paths with spaces in them if you want to convert that path to a URI.

Here is a workaround that will at least handle that case (if not every case of wrongly encoded data):

/**
 * Convert a file object to a URI
 *
 * There is a bug in the way that apache VFS handles paths with spaces in
 * https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675797#action_12675797
 *
 * @param resource the resource to convert
 *
 * @return a valid URI for the file object
 *
 * @throws URISyntaxException
 */
public URI fileObjectToUri(final FileObject resource) throws URISyntaxException
{
   return new URI(resource.getName().getURI().replace(" ", "%20"));
}

Domain properties in Glassfish

You can make properties files available to you WAR and EAR applications by putting the file in the folder glassfish/domains/${glassfish.domain.name}/lib/classes

You can use these in your spring configuration by prefixing the resource name with classpath:. For example:

<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <beans:property name="location" value="classpath:some.properties"/>
</beans:bean>

Configuration Properties in Spring

Make configuration properties from a properties file available in a Spring context

<bean id="propertyPlaceholderConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="locations">
      <list>
         <value>application.properties</value>
      </list>
   </property>
</bean>

m2eclipse and separate output folders

The recent versions of m2eclipse (> 0.9.3) are a nightmare to get working. The biggest issues is that if you run a command line build whilst eclipse is working, one or the other will get totally borked. there is a section in the FAQ describing how to use separate output folders. Essentially you have to tell eclipse to use a certain maven profile, which changes your project configuration.

The instructions almost work. However, some plugins need the project.build.directory variable (for example for code-generation) to be set, and the FAQ does not achieve that.

Ordinarily you would have to specify the directory element in the build section:

<directory>${basedir}/${target.dir}</directory>

If you do this however, anything you launch in eclipse will not have the correct classpath. You must fully specify the output directories:

<directory>${basedir}/${target.dir}</directory>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<testOutputDirectory>${basedir}/${target.dir}/test-classes</testOutputDirectory>

I assume this is because m2eclipse is doing some kind of parsing of the pom.xml

Maven Default Execution Ids

Maven execution IDs have changed in maven versions greater than 2.2.0.

It seems that you can disable a default a default execution by binding it to the phase “none”:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
   <executions>
      <execution>
         <id>default</id>
         <goals>
            <goal>unpack</goal>
         </goals>
         <phase>none</phase>
      </execution>
      <execution>
         <id>unpack</id>
         <phase>process-resources</phase>
         <goals>
            <goal>unpack</goal>
         </goals>
         <configuration>
            <artifactItems>
               <artifactItem>
                  [...]
               </artifactItem>
            </artifactItems>
         </configuration>
      </execution>
   </executions>
</plugin>

Linked Folders in Eclipse

In your .project file:

<projectDescription>
   [...]
   <linkedResources>
      <link>
         <name>target</name>
         <type>2</type>
         <locationURI>some/location</locationURI>
      </link>
   </linkedResources>
</projectDescription>