Announcement Announcement Module
Collapse
No announcement yet.
Getting namespace errors in xml config file when running from executable jar Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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

        Comment


        • #5
          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

          Comment

          Working...
          X