Results 1 to 5 of 5

Thread: Getting namespace errors in xml config file when running from executable jar

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default Getting namespace errors in xml config file when running from executable jar

    OK. So I can run my application in IntelliJ. But after I build my app and create an executable jar. It won't work on the command line

    Here is my dependency in my pom

    Code:
    ///THE PROPERTIES
    <spring.amqp.version>1.1.1.RELEASE</spring.amqp.version>
    <spring-data-commons.version>1.3.1.RELEASE</spring-data-commons.version>
    <spring-data-mongodb.version>1.1.0.M1</spring-data-mongodb.version>
    <spring-security.version>3.1.0.RELEASE</spring-security.version>
    <spring-integration.version>2.1.3.RELEASE</spring-integration.version>
    
    <!-- Spring AMQP -->
            <dependency>
                <groupId>org.springframework.amqp</groupId>
                <artifactId>spring-amqp</artifactId>
                <version>${spring.amqp.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.amqp</groupId>
                <artifactId>spring-rabbit</artifactId>
                <version>${spring.amqp.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.amqp</groupId>
                <artifactId>spring-erlang</artifactId>
                <version>${spring.amqp.version}</version>
            </dependency>
    
    
            <!-- Spring Integration jars-->
            <dependency>
               <groupId>org.springframework.integration</groupId>
               <artifactId>spring-integration-amqp</artifactId>
               <version>${spring-integration.version}</version>
            </dependency>
    The exception I am getting is

    Code:
    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/integration/amqp]
    Offending resource: URL [jar:file:/Users/bytor99999/Documents/OurProjects/projectName/data-integration-server/target/data-integration-server-0.1.0.jar!/META-INF/spring/applicationContext-integration.xml]
    Here is the header and a couple beans in my xml file

    Code:
    <?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:rabbit="http://www.springframework.org/schema/rabbit"
           xmlns:int="http://www.springframework.org/schema/integration"
           xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd">
    
        <task:executor id="gameStateThreadPool" pool-size="20" queue-capacity="40"/>
    
        <int-amqp:inbound-channel-adapter channel="gameStateIn"
                                          concurrent-consumers="40"
                                          connection-factory="connectionFactory"
                                          queue-names="queue.gamestate" channel-transacted="true"/>
    What am I missing?

    Thanks

    Mark

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Are you also extracting the jar content of the spring jars into this jar? If so you are overwriting spring files needed for namespace handling, instead of overwriting you need to concat those files together. It concerns the META-INF/spring.handlers and META-INF/spring.schemas files. There are several post about this on the forum so you might want to use the search.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Quote Originally Posted by Marten Deinum View Post
    Are you also extracting the jar content of the spring jars into this jar? If so you are overwriting spring files needed for namespace handling, instead of overwriting you need to concat those files together. It concerns the META-INF/spring.handlers and META-INF/spring.schemas files. There are several post about this on the forum so you might want to use the search.
    Yeah. thanks. That makes perfect sense, don't know what I was thinking. Wish there was a way to make a lib directory within an executable jar file with other jars in it. I was trying to avoid deploying in some kind of server, so I just made a static void main method. But I might have to make it a war file even though it isn't a website. But I also don't want to deploy in an app server.

    I think I will go about it without it being an executable jar and run it straight with a huge -cp.

    Thanks again Marten.

  4. #4
    Join Date
    Aug 2005
    Location
    Atlanta
    Posts
    124

    Default

    Hi,

    You may want to take a look at the Maven Shade Plugin:

    http://maven.apache.org/plugins/maven-shade-plugin/

    It can do the merging of the Spring namespace handler config files for you. As an example, take a look at an old blog post of mine:

    http://hillert.blogspot.com/2011/04/...continued.html

    Code:
    ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>1.4</version>
      <executions>
        <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <filters>
            <filter>
              <artifact>com.hillert:camellos-si</artifact>
                <excludes>
                  <exclude>users.properties</exclude>
                </excludes>
              </filter>
            </filters>
            <transformers>
              <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.ManifestResourceTransformer">
                <mainClass>com.hillert.camellos.Main</mainClass>
              </transformer>
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>
    ...
    Full source code (a little out-dated though):

    https://github.com/ghillert/camellos-spring-integration

    I hope this helps!

    Cheers,

    Gunnar
    Gunnar Hillert
    SpringSource/VMWare, Spring Integration team
    SpringSource Team - Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/ghillert
    http://blog.hillert.com/
    http://blog.springsource.com/author/ghillert/

  5. #5
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Thanks gunnar. I will try that out. I had had tried shade, but didn't have the transformers there, so the same thing was happening when using shade.

    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •