如何从Maven项目多模块和Spring Boot生成依赖项的jar文件

时间:2019-01-27 23:00:36

标签: maven

我有

  • 项目A(父级)
    • pom.xml
  • 项目B
    • pom.xml
  • 项目C
    • pom.xml
  • 项目D
    • pom.xml包含(依赖项B和C)

当我构建项目D时,我没有B.jar和C.jar。我有2个名为B和C的文件夹。

我需要B.jar和C.jar。拜托,该怎么做?

<?xml version="1.0" encoding="UTF-8"?>
<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>org.exemple.demo</groupId>
  <artifactId>ticket</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>ticket</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<java.version>1.8</java.version>
  </properties>


  <parent> 
	<groupId> org.springframework.boot </groupId> 
	<artifactId> spring-boot-starter-parent </artifactId> 
	<version> 2.1.2.RELEASE </version> 
   </parent>

	<!-- Ajouter des dépendances typiques pour une application Web --> 
	<dependencies> 
		<dependency> 
			<groupId> org.springframework.boot </groupId> 
			<artifactId> spring-boot-starter-web </artifactId> 
		</dependency> 

		<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-test</artifactId>
		    <scope>test</scope>
		</dependency>
	</dependencies>

	<!-- Le package est un fichier jar exécutable --> 
	<build> 
		<plugins> 
			<plugin> 
				<groupId> org.springframework.boot </groupId> 
				<artifactId> spring-boot-maven-plugin </artifactId> 
			</plugin > 
		</plugins> 
	</build>
	
  <modules>
    <module>ticket-consumer</module>
    <module>ticket-provider</module>
    <module>ticket-business</module>
    <module>ticket-webapp</module>
    <module>ticket-model</module>
    <module>ticket-technical</module>
  </modules>
</project>


the code above is the parent.

<!-- begin snippet: js hide: false console: true babel: false -->

此代码具有许多依赖性。但是,此项目的构建不会生成jar文件。

1 个答案:

答案 0 :(得分:0)

这个有依赖性的孩子:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.exemple.demo</groupId>
    <artifactId>ticket</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>org.exemple.demo</groupId>
  <artifactId>ticket-webapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>ticket-webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.exemple.demo</groupId>
      <artifactId>ticket-provider</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>org.exemple.demo</groupId>
      <artifactId>ticket-model</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

  </dependencies>

  <build> 
        <plugins> 
            <plugin> 
                <groupId> org.springframework.boot </groupId> 
                <artifactId> spring-boot-maven-plugin </artifactId> 
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <archive>
                            <manifest>
                                <mainClass>
                                    org.exemple.demo.App
                                </mainClass>
                            </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin > 
        </plugins> 
    </build>
</project>