Search code examples
mavenjarsmooksedifact

Maven packages smooks edifact models under wrong folder in fat jar on mvn assembly


I'm building a fat-JAR with maven containing Smooks and sevreal org.milyn.edi.unedifact mappings just like lots of other dependencies. As only one mapping model is allowed I choose inside main which one to use as follows

Smooks smooks = new Smooks();

SmooksResourceConfiguration modelLoaderResource = new SmooksResourceConfiguration();
modelLoaderResource.setResource(ModelLoader.class.getName());
modelLoaderResource.setParameter("mappingModel", ediFileModelUrn);
smooks.addConfiguration(modelLoaderResource);

GenericReaderConfigurator configurator = new GenericReaderConfigurator(UNEdifactReader.class);
configurator.getParameters().setProperty("mappingModel", ediFileModelUrn);
configurator.getParameters().setProperty("ignoreNewLines", "true");
smooks.setReaderConfig(configurator);

StringWriter writer = new StringWriter();
smooks.filterSource(new StreamSource(new FileInputStream(this.getFileToBeImported().getAbsolutePath())), new StreamResult(writer));
return writer.toString();`

with ediFileModelUrn looking like "urn:org.milyn.edi.unedifact:d95a-mapping:1.4" e.g.

Tests run fine and a fat jar is produced as expected if I run mvn package assembly:assembly.

However if I try to use that jar loading the mappings fails, as they are looked for under org.milyn.edi.unedifact:d95a-mapping:1.4 (and some other mappings) in classpath.

I get an

Caused by: org.milyn.edisax.EDIConfigurationException: 
Failed to locate jar file for EDI Mapping Model URN
'org.milyn.edi.unedifact:d95b-mapping:1.4'. Jar must be available on classpath.

So i looked at the jar built. Everything is fine with it and all classes inside of it except the mappings. While each other class in that jar is packed nicely to where it belongs regarding the package namings, e.g.

de.somecompany.someproject.SomeClass => de/somecompany/someproject/SomeClass.class) the edifact mappings are put to folders called like org_milyn_edi_unedifact/d95b-mapping/1_4.

It looks like in the path all . are replaced with _ before everything get's packed into that fat jar. That problem appears only at the mappings. All other dependencies are packed as they should be, which makes me think it is a bug in milyn packaging.

My POM looks like this:

<dependencies>

    ...

    <!-- Smooks -->
    <dependency>
        <groupId>org.milyn</groupId>
        <artifactId>milyn-smooks-all</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.milyn</groupId>
        <artifactId>testres</artifactId>
        <version>1.6</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.milyn</groupId>
        <artifactId>milyn-edisax-parser</artifactId>
        <version>1.6</version>
    </dependency>

    <!-- Smooks EDI Cartridge -->
    <dependency>
        <groupId>org.milyn</groupId>
        <artifactId>milyn-smooks-edi</artifactId>
        <version>1.4</version>
        <scope>compile</scope>
    </dependency>

    <!-- Required Mapping Models -->
    <dependency>
        <groupId>org.milyn.edi.unedifact</groupId>
        <artifactId>d99b-mapping</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.milyn.edi.unedifact</groupId>
        <artifactId>d95a-mapping</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.milyn.edi.unedifact</groupId>
        <artifactId>d95b-mapping</artifactId>
        <version>1.4</version>
    </dependency>

    ...

</dependencies>


<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>

                <configuration>
                    <finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>org.somecompany.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.somecompany.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>

                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

How can i solve that issue, so the paths are generated correctly and the mappings are found? Or do I have to change something in the way i initialize the mappings. But why would tests run properly then?


Solution

  • The only solution i found was putting the mapping jar's to the target folder by maven-antrun-plugin and executing the jar from there.