Java 如何将不同模块中的类绑定到jar?
我有一个主项目(比如a),它包含模块B和模块C。模块C是模块B的依赖项。除此之外,我想将模块C的所有类添加到模块B的jar中。通过将C作为依赖项添加到maven pom文件中可以很好地工作。但是模块B jar独立运行,并且在运行时需要模块C类(编译) 我怎么能对maven这样做。?Java 如何将不同模块中的类绑定到jar?,java,maven,intellij-idea,Java,Maven,Intellij Idea,我有一个主项目(比如a),它包含模块B和模块C。模块C是模块B的依赖项。除此之外,我想将模块C的所有类添加到模块B的jar中。通过将C作为依赖项添加到maven pom文件中可以很好地工作。但是模块B jar独立运行,并且在运行时需要模块C类(编译) 我怎么能对maven这样做。? 我正在使用JIdea 12。使用,并将其配置为将模块C隐藏到模块B中或直接隐藏到主项目中。使用,并将其配置为将模块C隐藏到模块B中或直接隐藏到主项目中。首先将C作为依赖项添加到B中 <dependency>
我正在使用JIdea 12。使用,并将其配置为将模块C隐藏到模块B中或直接隐藏到主项目中。使用,并将其配置为将模块C隐藏到模块B中或直接隐藏到主项目中。首先将C作为依赖项添加到B中
<dependency>
<groupId>A</groupId>
<artifactId>C</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
A.
C
1
假如
然后在模块B的pom文件中使用maven shade插件,如下所示
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${artifactId}-${version}</finalName>
</configuration>
</plugin>
org.apache.maven.plugins
maven阴影插件
包裹
阴凉处
${artifactId}-${version}
首先将C作为依赖项添加到B
<dependency>
<groupId>A</groupId>
<artifactId>C</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
A.
C
1
假如
然后在模块B的pom文件中使用maven shade插件,如下所示
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${artifactId}-${version}</finalName>
</configuration>
</plugin>
org.apache.maven.plugins
maven阴影插件
包裹
阴凉处
${artifactId}-${version}