首先,我是 Maven 新手,如果问题太简单,我很抱歉:)
我有主模块“main” 和子模块:a,b,c,...
我想要的是与子模块 b 共享子模块 a 中的一些数据。
父 pom 看起来像: 4.0.0
<groupId>Parent</groupId>
<artifactId>Parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>a</module>
<module>b</module>
<module>c</module>
</modules>
</project>
我想分享的 child 看起来像:
<parent>
<artifactId>Parent</artifactId>
<groupId>Parent</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>a</artifactId>
</project>
“消费者” child 看起来像:
<parent>
<artifactId>Parent</artifactId>
<groupId>Parent</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>b</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>a</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
我确实看到 jar 文件被添加到“外部库”中(我正在使用 Intellij) 但 jar 只包含 META-INF 文件夹,没有代码(可以吗?)
故事结束,我不能在 ChildB 类中使用 ChildA 类...... 如有任何帮助,我们将不胜感激!!
最佳答案
问题是我“破坏了”maven 项目结构...... 一旦我按照 maven 的方式构建了模块,就会像魅力一样工作:) http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
关于java - 在 Maven 项目的模块内共享类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27406044/