关于后端:Maven项目模块打包引入

36次阅读

共计 2450 个字符,预计需要花费 7 分钟才能阅读完成。

工作中咱们会遇到这样的一种场景,就是写好的代码封包给别的部门应用或者我的项目应用,如果咱们此时依照失常的打包流程的话,对方是能够应用 maven 引入包的,然而包内的类缺无奈引入应用,此时就须要咱们上面所说的这种形式来解决

残缺代码可参考GitHub

https://github.com/zuiyu-main…

问题

maven能够引入,却不能 import 类应用

解决

  • 首先还是新建一个模块测试,license-common, 批改 pom.xml 中的打包插件为上面这种

        <groupId>com.zuiyu</groupId>
        <artifactId>license-common</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>license-common</name>
        
    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>
  • 执行 idea 中的打包,也就是mvn install
  • 须要该模块代码的我的项目 pom 中退出

        <dependency>
                <groupId>com.zuiyu</groupId>
                <artifactId>license-common</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>

总结

残缺的外围 pom 文件如下, 只保留打包相干

  • license-common

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.zuiyu</groupId>
        <artifactId>license-common</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>license-common</name>
        <description>license-client</description>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    
  • License-client

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.zuiyu</groupId>
        <artifactId>client</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>license-client</name>
        <description>license-client</description>
    
        <properties>
            <java.version>1.8</java.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <spring-boot.version>2.1.18.RELEASE</spring-boot.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>com.zuiyu</groupId>
                <artifactId>license-common</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    
    </project>
    

本文由 mdnice 多平台公布

正文完
 0