我想在我的maven项目中安装一些非maven jar。
步骤1:我正在使用maven-antrun-plugin
在预包装阶段使用ant(因为非maven项目是基于Ant的)生成非maven项目的jar。
步骤2:然后我使用maven-install-plugin
在包阶段将插件安装到本地存储库
步骤3:我还使用maven-war-plugin
将所有这些包装在安装阶段的战争中
此外,我在pom.xml中添加了所有非maven项目作为依赖项
当我在我的项目上运行mvn-install时,pom会出错:Missing artifact for non maven jars
。
The POM for com.non_maven:com.non_maven:jar:version is missing, no dependency information available
如果运行包阶段,则只会在存储库中安装非maven jar。但似乎Maven期望存储库中已存在所有依赖项。 我可以通过单独安装非maven jar来解决这个问题 maven存储库然后运行pom.xml来创建战争。 但我想使用单个pom执行这些步骤。 我怎样才能做到这一点? 感谢
的pom.xml
<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>com.swte.sca</groupId>
<artifactId>MyProject</artifactId>
<packaging>war</packaging>
<version>1.1.19</version>
<name>MyProject</name>
<build>
<finalName>MyProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>common-jar</id>
<phase>package</phase>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>com.non_maven</groupId>
<artifactId>com.non_maven</artifactId>
<version>${version}</version>
<file>F:/addressMaven</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-war-file</id>
<phase>prepare-package</phase>
<configuration>
<target name="display">
<ant antfile="src/main/ant/build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>F:\Folder\APP</outputDirectory>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>F:/addressMaven</directory>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.swte.ojdbc7</groupId>
<artifactId>com.swte.ojdbc7</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.non_maven</groupId>
<artifactId>com.non_maven</artifactId>
<version>${version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
答案 0 :(得分:2)
从你的pom,我可以看到你没有使用模块。 https://maven.apache.org/guides/mini/guide-multiple-modules.html
我已经看到模块解决了类似的问题。
您可以按原样保留主pom,然后在带有子pom的专用模块中提取特定的构建步骤。
<version>1.1.19</version>
<name>MyProject</name>
<modules>
<module>child-module</module>
</modules>
<build>
在文件夹/子模块中,您创建一个类似于父母的pom:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.swte.sca</groupId>
<artifactId>MyProject</artifactId>
<version>1.1.19</version>
</parent>
<groupId>com.swte.sca</groupId>
<artifactId>non-maven-module</artifactId>
<version>1.0.0</version>
你可以在那里写下你的模块的构建步骤