0

i am trying to build a single executable jar file with dependencies using maven shade plug in. in my pom.xml, i have added a dependency on a package which i have locally complied (mvn install) which is also a springframework based package. but i am getting following errors when i run my application.

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/context] Offending resource: class path resource [applicationContext.xml]

while spending half of today googling for answers, i've found out that different springframework modules' manifest files can overwrite each other, and hence i have to use AppendingTransformer so that they can be appended instead of being overwritten. so i have added those lines, but it is still failing. what could be wrong?

here is my plug-in definition.

  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.1</version>

  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <finalName>my-spring-app</finalName>
        <shadedArtifactAttached>true</shadedArtifactAttached>
        <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <mainClass>com.mycomp.App</mainClass>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>META-INF/spring.handlers</resource>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>META-INF/spring.schemas</resource>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>META-INF/spring.tooling</resource>
          </transformer>
        </transformers>

      </configuration>
    </execution>
  </executions>
</plugin>

UPDATE here's my applicationContext.xml ( partial)

<?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:task="http://www.springframework.org/schema/task"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">



    <context:property-placeholder location="classpath*:test.properties" />

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />

        <!-- C3P0 properties -->
        <property name="acquireIncrement" value="${acquireIncrement}" />
        <property name="minPoolSize" value="${minPoolSize}" />
        <property name="maxPoolSize" value="${maxPoolSize}" />
        <property name="maxIdleTime" value="${maxIdleTime}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="default_schema">test</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>

        <property name="annotatedClasses">
            <list>

                <value>com.mycomp.database.myVO</value>

            </list>
        </property>

    </bean>

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="persistenceExceptionTranslationPostProcessor"
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <tx:annotation-driven transaction-manager="transactionManager" />


    <task:annotation-driven />

</beans>
Tunaki
  • 132,869
  • 46
  • 340
  • 423
user3590506
  • 171
  • 1
  • 4
  • 16

3 Answers3

1

Maven-shade-plugin is temperamental, and in my experience getting a good jar from it can be a hassle once you've got more than a few classes with a few library jars. Capsule is an interesting alternative that uses a launcher to set up the classpath and even download dependencies from Maven Central if you wish! There's a maven plugin for it, but that's still in early development.

That said, you need to mvn clean package to force the shaded jar to be rebuilt from scratch.

Steve McKay
  • 2,123
  • 17
  • 26
0

i have resolved my issue by going xml-less set up for my spring project. i defined my spring beans in @Configurations class and that fixed the issue for me.

user3590506
  • 171
  • 1
  • 4
  • 16
0

Ok. i finally found the problem. my pom was not configured correctly.

i had shade plugin entry as below.

<plugins>
  <pluginManagement>
     <plugin>
        .... shade stuff
     </plugin>
  </pluginManagement>
</plugins>

solution was to put it outside pluginManagement like below.

<plugins>
  <plugin>
    ... shade stuff
  </plugin>
  <pluginManagement/>
</plugins>
user3590506
  • 171
  • 1
  • 4
  • 16