我建立一個脂肪-JAR包含的Smooks和sevreal org.milyn.edi.unedifact映射就像許多其他依賴的行家下EDIFACT模式。因爲只有一個映射模型允許我選擇內部主要如下Maven的包的Smooks脂肪罐子錯誤的文件夾上MVN裝配
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();`
使用哪一個與ediFileModelUrn
看上去像"urn:org.milyn.edi.unedifact:d95a-mapping:1.4"
例如
測試運行良好,並預期如果我跑mvn package assembly:assembly
脂肪罐子產生。
但是,如果我嘗試使用該jar加載映射失敗,因爲它們在類路徑中尋找org.milyn.edi.unedifact:d95a-mapping:1.4
(和一些其他映射)。
我得到一個
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.
所以我看着生成JAR。一切都很好,除了映射以外,它裏面的所有類都可以。雖然該罐子中的每個其他類都很好地包裝在其包裝名稱所屬的位置,例如,
de.somecompany.someproject.SomeClass
=>de/somecompany/someproject/SomeClass.class
)將這些edifact映射放到名爲org_milyn_edi_unedifact/d95b-mapping/1_4
的文件夾中。
它看起來像在路徑中所有.
被替換爲_
之前,所有東西都被裝進那個胖罐子裏。該問題僅出現在映射中。所有其他的依賴關係都應該被打包,這讓我認爲這是milyn包裝中的一個錯誤。
我POM看起來是這樣的:
<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>
我該如何解決這個問題,這樣的路徑正確生成和映射發現了什麼?或者我必須改變我初始化映射的方式。但爲什麼測試會正常運行呢?