在我的 maven 中,您想创建一个包含包中唯一已编译类的 jar, org.lory.ejb.commons如您在此处看到的:
因为这些类在 ejb 核心项目和客户端项目之间是通用的。我正在尝试使用 maven 程序集插件,其中我的程序集描述符是:
<assembly>
<id>commons</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/target/classes/</directory>
<outputDirectory>${basedir}/target/</outputDirectory>
<includes>
<include>org/lory/ejb/commons/**</include>
</includes>
</fileSet>
</fileSets>
我的 pom.xml 的部分是
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
似乎一个 jar 是由它内部的包路径生成的,它不受尊重(它与包含的编译类不同)。事实上,如果我尝试将它导入到另一个项目中,Eclipse 不会让我使用它:
哪个是正确的使用方法?谢谢
和 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lory-ejb-commons</groupId>
<artifactId>lory-ejb-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>lory-ejb-commons</name>
<modules>
<module>lory-ejb</module>
</modules>
这是另一个项目的 pom.xml(从中删除了 commons 包)
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lory-ejb-commons</groupId>
<artifactId>lory-ejb-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>lory-ejb</artifactId>
<name>lory-ejb</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>lory-ejb-commons</groupId>
<artifactId>lory-ejb-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
但它仍然不起作用。清理和安装两个项目后,我遇到了这个错误
[错误] 无法在项目 lory-ejb 上执行目标:无法解析项目 lory-ejb-commons:lory-ejb:jar:0.0.1-SNAPSHOT 的依赖项:找不到工件 lory-ejb-commons:lory-ejb -commons:jar:0.0.1-SNAPSHOT -> [帮助 1]
在子项目中,我什至无法将 commons 包作为 jar 导入,它只是将其视为一个目录,即使我可以在源代码中导入类,java 编译器仍然说
导入 org.lory.ejb.commons.OperationOutcome 无法解析



