idea 开发多模块之间依赖的项目,不是父子模块的情况下,一个模块如何成功打包?
入门idea使用不久,也不太熟练maven构建工具。
新建一个空项目,创建两个maven模块,分别是测试普通java模块工程和测试Web工程模块(打成Jar包),这两个模块没有父子关系。以下是相关代码
测试java代码:
TestUtil:
package test;public class TestUtil {
public static void test(){
System.out.println("调用工具包:Hello Word");
}
}
AppStart1代码
package start;import test.TestUtil;
public class AppStart1 {
public static void main(String[] args) {
System.out.println("测试5");
TestUtil.test();
}
}
TestUtilMaven1的pom代码:
<?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>me.test</groupId>
<artifactId>TestUtilMaven1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
TestMavenMainWeb2的pom代码:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.test</groupId>
<artifactId>TestMavenMainWeb2</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>TestMavenMainWeb2 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.test</groupId>
<artifactId>TestUtilMaven1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>TestMavenMainWeb2</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.sql</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
<!-- java11 保留参数名编译参数 -->
<compilerArgument>-parameters</compilerArgument>
<compilerArguments><verbose /></compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>demo</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>start.AppStart1</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resources>
<!-- <resource>demo-config-dev.txt</resource> -->
<!-- <resource>.PDF</resource> -->
<!-- <resource>READ.md</resource> -->
</resources>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
TestUtilMaven1是一个工具库模块,而TestMavenMainWeb2是一个Web模块,我的要求是,TestMavenMainWeb2调用TestUtilMaven1一些静态方法。完成后,打包TestMavenMainWeb2模块,打成jar包,然后通过java cmd命令运行jar
但是打包时出现以下错误提示:
"C:\Program Files\Java\jdk-11.0.8.10-hotspot\bin\java.exe" -Dmaven.multiModuleProjectDirectory=XX\TestMavenMainWeb2 -Djansi.passthrough=true "-Dmaven.home=D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\lib\idea_rt.jar=2102:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2022.3.1 -s D:\develop_config\maven\apache-maven-3.8.4\conf\settings.xml install[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< me.test:TestMavenMainWeb2 >----------------------
[INFO] Building TestMavenMainWeb2 Maven Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for me.test:TestUtilMaven1:jar:1.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.143 s
[INFO] Finished at: 2023-02-03T10:42:17+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project TestMavenMainWeb2: Could not resolve dependencies for project me.test:TestMavenMainWeb2:jar:1.0-SNAPSHOT: Could not find artifact me.test:TestUtilMaven1:jar:1.0-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Process finished with exit code 1
问题:Failed to execute goal on project TestMavenMainWeb2: Could not resolve dependencies for project me.test:TestMavenMainWeb2:jar:1.0-SNAPSHOT: Could not find artifact me.test:TestUtilMaven1:jar:1.0-SNAPSHOT
如何解决这个问题
回答:
先install TestUtilMaven1发布到本地仓库
再去build TestMavenMainWeb2
以上是 idea 开发多模块之间依赖的项目,不是父子模块的情况下,一个模块如何成功打包? 的全部内容, 来源链接: utcz.com/p/944958.html