Maven 在 mvn assembly 上的 fat jar 中的错误文件夹下打包 smooks edifact 模型
Maven packages smooks edifact models under wrong folder in fat jar on mvn assembly
我正在使用包含 Smooks 和 sevreal org.milyn.edi.unedifact 映射的 maven 构建一个 fat-JAR,就像许多其他依赖项一样。由于只允许使用一种映射模型,因此我在 main 中选择使用哪一种,如下所示
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 加载映射失败,因为它们是在 class 路径中的 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。它和其中的所有 classes 都很好,除了映射。虽然那个 jar 中的每个 class 都很好地打包到它所属的包命名位置,例如
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>
我该如何解决该问题,以便正确生成路径并找到映射?或者我是否必须更改初始化映射的方式。但是为什么要正确测试 运行 呢?
我找到的唯一解决方案是通过 maven-antrun-plugin 将映射 jar 放入目标文件夹并从那里执行 jar。
我正在使用包含 Smooks 和 sevreal org.milyn.edi.unedifact 映射的 maven 构建一个 fat-JAR,就像许多其他依赖项一样。由于只允许使用一种映射模型,因此我在 main 中选择使用哪一种,如下所示
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 加载映射失败,因为它们是在 class 路径中的 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。它和其中的所有 classes 都很好,除了映射。虽然那个 jar 中的每个 class 都很好地打包到它所属的包命名位置,例如
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>
我该如何解决该问题,以便正确生成路径并找到映射?或者我是否必须更改初始化映射的方式。但是为什么要正确测试 运行 呢?
我找到的唯一解决方案是通过 maven-antrun-plugin 将映射 jar 放入目标文件夹并从那里执行 jar。