6

私のプロジェクトの依存関係であるサードパーティの jar があります。ビジネス上の制約のため、エンタープライズまたは企業のリポジトリにアクセスすることはできません。ただし、このサードパーティ製の jar は公開されていないため、Web プロジェクトの に含まれていますsrc\main\resources

これは Maven プロジェクトであるため、このサードパーティの jar をコンパイル時の依存関係としてリストし、ビルド プロセスの一部としてローカル リポジトリにサードパーティの jar をインストールするビルド プラグインを pom に含めます。ビルド ライフサイクルのフェーズ中にこの目標を実行するように Maven に指示しvalidateます。これは、私の知る限り、他の Maven フェーズよりも前になります。

ただし、を実行しclean installてローカル リポジトリをクリアすると、サードパーティの jar がローカルまたは Maven 中央リポジトリで解決できないため、ビルドが失敗します。私が知る限り、pom は正しくセットアップされており、依存関係の解決を開始する前に、Maven がサードパーティの jar をローカルにインストールしようとしているのがわかるはずです。

問題は、jar がローカルにインストールされる前に依存関係がリストされている場合、その依存関係を解決できないためにビルドが失敗することです。サードパーティの jar 宣言を削除してビルドを実行すると、依存関係の解決が発生した後(これは、クリーン後に最初に行うことです)、他のフェーズの前に、jar がローカルにインストールされ、問題はありません。しかし、私の知る限り、validate依存関係を収集して解決する前にフェーズを実行する必要があるため、Maven によって解決される前に jarローカルにインストールする必要があります。アイデアや考えはありますか?

私のポン:

<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.company</groupId>
    <artifactId>project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Web Services</name>
    <description>This project will handle communication.</description>

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

    <build>
        <plugins>
            <!-- This plugin installs the Evip jar from the project's resource folder to the local 
                repository for normal Maven consumption -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>install-evip-jar</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>mvn</executable>
                    <arguments>
                        <argument>install:install-file</argument>
                        <argument>-Dfile=${basedir}\src\main\resources\EVIPSoapServer.jar</argument>
                        <argument>-DgroupId=com.company</argument>
                        <argument>-DartifactId=EVIPSoapServer</argument>
                        <argument>-Dversion=1.0.0</argument>
                        <argument>-Dpackaging=jar</argument>
                    </arguments>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <!-- EXCLUDE EVIPSOAPSERVER JAR FROM CLASSES DIRECTORY -->
                    <packagingExcludes>
                        ${basedir}\src\main\resources\EVIPSoapServer.jar
                    </packagingExcludes>
                    <webResources>
                        <!-- INCLUDE SOURCE FILES WITH WAR -->
                        <resource>
                            <directory>${project.build.sourceDirectory}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <!-- mvn clean install tomcat:run-war to deploy Look for "Running war 
                        on http://xxx" and "Setting the server's publish address to be /yyy" in console 
                        output; WSDL browser address will be concatenation of the two: http://xxx/yyy?wsdl -->
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.0</version>
                    <executions>
                        <execution>
                            <id>start-tomcat</id>
                            <goals>
                                <goal>run-war</goal>
                            </goals>
                            <phase>pre-integration-test</phase>
                            <configuration>
                                <port>${test.server.port}</port>
                                <path>/webservice</path>
                                <fork>true</fork>
                                <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <configuration>
                        <projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
                        <wtpmanifest>true</wtpmanifest>
                        <wtpapplicationxml>true</wtpapplicationxml>
                        <wtpversion>2.0</wtpversion>
                    </configuration>
                </plugin>

                <!--This plugin's configuration is used to store Eclipse m2e settings 
                    only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.codehaus.mojo
                                        </groupId>
                                        <artifactId>
                                            exec-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.2.1,)
                                        </versionRange>
                                        <goals>
                                            <goal>exec</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <!-- COMPILE DEPENDENCIES -->
        <dependency>
            <groupId>com.company</groupId>
            <artifactId>EVIPSoapServer</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>2.7.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.7.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.0.7.RELEASE</version>
            <scope>compile</scope>
        </dependency>

        <!-- PROVIDED/TEST DEPENDENCIES -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
4

5 に答える 5

5

http://randomizedsort.blogspot.com.es/2011/10/configuring-maven-to-use-local-library.htmlのソリューションは、ファイルベースのプロジェクト スコープの Maven リポジトリに基づいています。したがって、ライブラリはソース コードのバージョン管理下にあります。pom.xmlインストールは、ファイルで指定されたものではなく、1 回限りの手動プロセスです。

3 つのステップ:

  1. プロジェクトにリポジトリを保持するフォルダーを作成します。と言うlib
  2. Maven を使用して、jar を lib ディレクトリにインストールします。

    mvn install:install-file -Dfile=path_to_mylib.jar ^
        -DgroupId=com.mylib ^
        -DartifactId=mylib ^
        -Dversion=1.0 ^
        -Dpackaging=jar ^
        -DlocalRepositoryPath=path_to_my_project/lib 
    

3.アップデートpom.xml

    <repositories>
      <repository>
      <!-- DO NOT set id to "local" because it is reserved by Maven -->
        <id>lib</id>
        <url>file://${project.basedir}/lib</url>
      </repository>
    </repositories>

    <dependencies>
      <dependency>
        <groupId>com.mylib</groupId>
        <artifactId>mylib</artifactId>
        <version>1.0</version>
      </dependency>
    </dependencies>
于 2015-05-12T20:46:38.867 に答える
3

同様の問題の解決策を探しているときに、この質問を見ました。古いことは知っていますが、私の解決策を共有したかったのです。maven-install-plugin を直接使用して問題を解決しました。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>
                <execution>
                    <id>whatevs</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc6</artifactId>
                        <version>${oracle.version}</version>
                        <packaging>jar</packaging>
                        <file>${basedir}/dev-setup/lib/ojdbc6.jar</file>
                    </configuration>
                </execution>
            </executions>
        </plugin>

完璧に動作します。

于 2014-10-09T13:52:21.260 に答える
2

外部依存関係を別のプロジェクトとしてモデル化することをお勧めします (ラッパーと考えてください)。現在のプロジェクトは、ビルドの一部として外部 JAR をダウンロードし、独自の配布可能ファイルにパッケージ化できる独自のプロジェクトに依存している場合があります。

于 2013-11-08T16:52:42.410 に答える
1

申し分なく、議論と好みはさておき、私はサンダーの推薦に行きました。カスタムMojosなどなしで実際に機能したのはこれだけでした。タイプのパッケージングを使用した親Mavenプロジェクトがありpom、サードパーティのjar(任意の数の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>com.company</groupId>
    <artifactId>project-evip</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>EvipSoapServerJar</name>
    <packaging>pom</packaging>

    <modules>
        <module>webservices</module>
    </modules>

    <build>
        <plugins>
            <!-- This plugin installs the Evip jar from the project's lib to the local 
                repository for normal Maven consumption -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>install-evip-jar</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>mvn</executable>
                    <arguments>
                        <argument>install:install-file</argument>
                        <argument>-Dfile=${basedir}\src\main\resources\EVIPSoapServer.jar</argument>
                        <argument>-DgroupId=com.company</argument>
                        <argument>-DartifactId=EVIPSoapServer</argument>
                        <argument>-Dversion=1.0.0</argument>
                        <argument>-Dpackaging=jar</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings 
                    only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.codehaus.mojo
                                        </groupId>
                                        <artifactId>
                                            exec-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.2.1,)
                                        </versionRange>
                                        <goals>
                                            <goal>exec</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

次に、親 Maven プロジェクトの下に Maven モジュールを作成し、org.apache.cxf.archetype:cxf-jaxws-javafirst:2.7.7アーキタイプを使用しました。サードパーティの jar をコンパイル時の依存関係としてリストするだけで、それが解決され、結果の war に追加されます。子モジュールの 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>project-evip</artifactId>
        <groupId>com.company</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <groupId>com.company</groupId>
    <artifactId>webservices</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Web Services</name>
    <description>This project will handle communication.</description>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <webResources>
                        <!-- INCLUDE SOURCE FILES WITH WAR -->
                        <resource>
                            <directory>${project.build.sourceDirectory}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <!-- mvn clean install tomcat:run-war to deploy Look for "Running war 
                        on http://xxx" and "Setting the server's publish address to be /yyy" in console 
                        output; WSDL browser address will be concatenation of the two: http://xxx/yyy?wsdl -->
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.0</version>
                    <executions>
                        <execution>
                            <id>start-tomcat</id>
                            <goals>
                                <goal>run-war</goal>
                            </goals>
                            <phase>pre-integration-test</phase>
                            <configuration>
                                <port>${test.server.port}</port>
                                <path>/webservice</path>
                                <fork>true</fork>
                                <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <configuration>
                        <projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
                        <wtpmanifest>true</wtpmanifest>
                        <wtpapplicationxml>true</wtpapplicationxml>
                        <wtpversion>2.0</wtpversion>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <!-- COMPILE DEPENDENCIES -->
        <dependency>
            <groupId>com.company</groupId>
            <artifactId>EVIPSoapServer</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>2.7.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.7.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.0.7.RELEASE</version>
            <scope>compile</scope>
        </dependency>

        <!-- PROVIDED/TEST DEPENDENCIES -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

私はすべての助けに感謝します、ありがとう。

于 2013-11-08T19:54:24.700 に答える
0

私が現在使用しているgregmの答えに対応しています:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                        <packaging>jar</packaging>
                        <file>${project.build.directory}/${project.build.finalName}.jar</file>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

これにより、プロジェクト自体の JAR がローカル リポジトリにインストールされます。

結果:

--- maven-jar-plugin:2.3.2:jar (default-jar) @ SportyLib ---
Building jar: ...-1.0-SNAPSHOT.jar

--- maven-install-plugin:2.5.2:install (default-install) @ SportyLib ---
Installing ...-1.0-SNAPSHOT.jar to .../.m2/repository/.../1.0-SNAPSHOT/...-1.0-SNAPSHOT.jar
Installing .../pom.xml to .../.m2/repository/.../1.0-SNAPSHOT/...-1.0-SNAPSHOT.pom
于 2014-10-11T12:09:23.183 に答える