簡體   English   中英

非Maven jar依賴項在pom.xml Maven中給出錯誤

[英]Non maven jar dependencies giving error in pom.xml maven

我想在我的Maven項目中安裝一些非Maven Jar。

步驟1:在打包前的階段,我使用maven-antrun-plugin使用ant生成非maven項目的jar(因為非maven項目基於Ant)。

步驟2:然后在打包階段使用maven-install-pluginmaven-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存儲庫中分別安裝非maven jar,然后運行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>

從您的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>

在文件夾/ child-module中,創建一個類似於父代的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>

您可以在此處為模塊編寫構建步驟

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM