views:

104

answers:

2

I'm creating a stand-alone Sava application with Spring, to handle the JDBC access. The application works fine on every test and I decided that I need a jar to be deployed our clients.

They might not have spring in their classpath, so I used maven-assembly-plugin to handle the jar creation with dependencies.

However when I try to run the application:

java -jar target/insereraios-0.0.1-SNAPSHOT-jar-with-dependencies.jar

Which throws the following error:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/p]
Offending resource: class path resource [applicationContext.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
...and so on to the database access class of this project.

The applicationContext.xml file is in projectbase/src/main/resources. And its placed at target/packagename base.

The applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;


    <bean id="dataSourceDesenv" class="org.apache.commons.dbcp.BasicDataSource"... />

    <bean id="simpleJdbcDaoSupport" class="org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport"
      p:dataSource-ref="dataSourceDesenv" />

    <bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="dataSourceDesenv" />
    </bean>

</beans>

That's all I can think that could be useful. I'll provide more info if requested.

A: 

Looks like a bug in the Maven Assembly Plugin - MASSEMBLY-360, and as discussed in this blog entry here.

In short, the meta-data files in the Spring JARs that handle the Spring namespaces are being mangled by maven.

skaffman
+1  A: 

I found the error, the bug lies in an unfixed bug in the maven-assembly plugin. I used the following workaround:

First commented out the maven-assembly code in my pom. Then I copied the dependencies to a lib folder at the target using the maben-dependency-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Then I used the maven-jar-plugin to setup my executable jar:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>org.simepar.insereraios.App</mainClass>
                    </manifest>
                    <manifestEntries>
                        <mode>development</mode>
                        <url>${pom.url}</url>
                        <key>value</key>

                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

Finally I created a bash script that is deployed with the application that runs my app with its libs and any provided arguments:

java -cp lib/*:insereraios-0.0.1-SNAPSHOT.jar org.simepar.insereraios.App $@

I should have built the app in python =/

awregan