2016-07-11 15 views
0

問題:pom.xmlには、アーティファクトが見つからないというエラーが表示されます。 ローカルリポジトリを使用してプロジェクトを作成しました。その中に必要なjarファイルをコピーしました。 は、私はちょうどのpom.xmlに必要なjarの名前とバージョンを置くように動的プロジェクトを作成しようとしましたが、ポイジャーなどのようにそれを見つけることができませんでしたローカルリポジトリとローカル依存関係を持つMavenプロジェクトの作成

の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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.mavenproject.test</groupId> 
    <artifactId>testproject</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>testproject</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
<repositories> 
     <repository> 
     <id>localrepository</id> 
     <url>C:/Users/anil/.m2/repository</url> 
     </repository> 
    </repositories> 
    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     </dependency> 
     <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     </dependency> 
    <dependency> 
     <groupId>commons-digester</groupId> 
     <artifactId>commons-digester</artifactId> 
     </dependency> 
     <dependency> 
     <groupId>itext</groupId> 
     <artifactId>itext</artifactId> 
     </dependency> 
     <dependency> 
     <groupId>jasperreports</groupId> 
     <artifactId>jasperreports</artifactId> 
     </dependency> 
     <dependency> 
     <groupId>poi</groupId> 
     <artifactId>poi</artifactId> 
     </dependency> 
    </dependencies> 
</project> 

` ローカルレポジトリ:ローカルリポジトリ内のJARファイルが存在{示すいくつかのJARファイル} Jarfileinformation present in local repository 有効POM:

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.mavenproject.test</groupId> 
    <artifactId>testproject</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>testproject</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencyManagement> 
    <dependencies> 
     <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     </dependency> 
     <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     <version>1.9.0</version> 
     </dependency> 
     <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.2.1</version> 
     </dependency> 
     <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.1</version> 
     </dependency> 
     <dependency> 
     <groupId>commons-digester</groupId> 
     <artifactId>commons-digester</artifactId> 
     <version>2.1</version> 
     </dependency> 
     <dependency> 
     <groupId>itext</groupId> 
     <artifactId>itext</artifactId> 
     <version>2.1.7</version> 
     </dependency> 
     <dependency> 
     <groupId>jasperreports</groupId> 
     <artifactId>jasperreports</artifactId> 
     <version>6.2.2</version> 
     </dependency> 
     <dependency> 
     <groupId>poi</groupId> 
     <artifactId>poi</artifactId> 
     <version>3.10.1</version> 
     </dependency> 
    </dependencies> 
    </dependencyManagement> 
    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     <version>1.9.0</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.2.1</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.1</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-digester</groupId> 
     <artifactId>commons-digester</artifactId> 
     <version>2.1</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>itext</groupId> 
     <artifactId>itext</artifactId> 
     <version>2.1.7</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>jasperreports</groupId> 
     <artifactId>jasperreports</artifactId> 
     <version>6.2.2</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>poi</groupId> 
     <artifactId>poi</artifactId> 
     <version>3.10.1</version> 
     <scope>compile</scope> 
    </dependency> 
    </dependencies> 
    <repositories> 
    <repository> 
     <id>localrepository</id> 
     <url>C:/Users/anil/.m2/repository</url> 
    </repository> 
    <repository> 
     <snapshots> 
     <enabled>false</enabled> 
     </snapshots> 
     <id>central</id> 
     <name>Central Repository</name> 
     <url>https://repo.maven.apache.org/maven2</url> 
    </repository> 
    </repositories> 
    <pluginRepositories> 
    <pluginRepository> 
     <releases> 
     <updatePolicy>never</updatePolicy> 
     </releases> 
     <snapshots> 
     <enabled>false</enabled> 
     </snapshots> 
     <id>central</id> 
     <name>Central Repository</name> 
     <url>https://repo.maven.apache.org/maven2</url> 
    </pluginRepository> 
    </pluginRepositories> 
    <build> 
    <sourceDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\src\main\java</sourceDirectory> 
    <scriptSourceDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\src\main\scripts</scriptSourceDirectory> 
    <testSourceDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\src\test\java</testSourceDirectory> 
    <outputDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target\classes</outputDirectory> 
    <testOutputDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target\test-classes</testOutputDirectory> 
    <resources> 
     <resource> 
     <directory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\src\main\resources</directory> 
     </resource> 
    </resources> 
    <testResources> 
     <testResource> 
     <directory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\src\test\resources</directory> 
     </testResource> 
    </testResources> 
    <directory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target</directory> 
    <finalName>testproject-0.0.1-SNAPSHOT</finalName> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.3</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-5</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.8</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-release-plugin</artifactId> 
      <version>2.3.2</version> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
     <artifactId>maven-clean-plugin</artifactId> 
     <version>2.5</version> 
     <executions> 
      <execution> 
      <id>default-clean</id> 
      <phase>clean</phase> 
      <goals> 
       <goal>clean</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-install-plugin</artifactId> 
     <version>2.4</version> 
     <executions> 
      <execution> 
      <id>default-install</id> 
      <phase>install</phase> 
      <goals> 
       <goal>install</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-resources-plugin</artifactId> 
     <version>2.6</version> 
     <executions> 
      <execution> 
      <id>default-resources</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>resources</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>default-testResources</id> 
      <phase>process-test-resources</phase> 
      <goals> 
       <goal>testResources</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.12.4</version> 
     <executions> 
      <execution> 
      <id>default-test</id> 
      <phase>test</phase> 
      <goals> 
       <goal>test</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <executions> 
      <execution> 
      <id>default-testCompile</id> 
      <phase>test-compile</phase> 
      <goals> 
       <goal>testCompile</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>default-compile</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>compile</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>2.4</version> 
     <executions> 
      <execution> 
      <id>default-jar</id> 
      <phase>package</phase> 
      <goals> 
       <goal>jar</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-deploy-plugin</artifactId> 
     <version>2.7</version> 
     <executions> 
      <execution> 
      <id>default-deploy</id> 
      <phase>deploy</phase> 
      <goals> 
       <goal>deploy</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <artifactId>maven-site-plugin</artifactId> 
     <version>3.3</version> 
     <executions> 
      <execution> 
      <id>default-site</id> 
      <phase>site</phase> 
      <goals> 
       <goal>site</goal> 
      </goals> 
      <configuration> 
       <outputDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target\site</outputDirectory> 
       <reportPlugins> 
       <reportPlugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-project-info-reports-plugin</artifactId> 
       </reportPlugin> 
       </reportPlugins> 
      </configuration> 
      </execution> 
      <execution> 
      <id>default-deploy</id> 
      <phase>site-deploy</phase> 
      <goals> 
       <goal>deploy</goal> 
      </goals> 
      <configuration> 
       <outputDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target\site</outputDirectory> 
       <reportPlugins> 
       <reportPlugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-project-info-reports-plugin</artifactId> 
       </reportPlugin> 
       </reportPlugins> 
      </configuration> 
      </execution> 
     </executions> 
     <configuration> 
      <outputDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target\site</outputDirectory> 
      <reportPlugins> 
      <reportPlugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-project-info-reports-plugin</artifactId> 
      </reportPlugin> 
      </reportPlugins> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    <reporting> 
    <outputDirectory>D:\Anil Bhendarkar\Company Projects\Rolls-Royce\Workspace\testproject\target\site</outputDirectory> 
    </reporting> 
</project> 

私はこの問題を理解していない。 私の目的は、このライブラリを使用してmavenプロジェクトを依存関係として作成することです。

ありがとうございます。

+0

リポジトリマネージャの使用を開始し、必要なjarファイルをそこにインストールします。単にdepを使用するだけです。瓶。 – khmarbaise

答えて

0

依存関係としてローカルjarを追加するには、これを実現する方法が2つあります。

1)スコープsystem

<dependency> 
    <groupId>poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>1.0</version> <!-- Dummy Version --> 
    <scope>system</scope> 
    <systemPath>/pathToJar/poi.jar</systemPath> 
</dependency> 

しかし、いくつかのMavenの構築ツールがmaven-assembly-pluginmaven-shade-pluginのように、原因スコープsystemに失敗したこの方法を使用してを使用してください。このような使用を避けるために。ローカルリポジトリを作成することにより

2)、

は、プロジェクトディレクトリ内のディレクトリrepoを作成します。 Mavenの次 ランに、cmdを経由して、プロジェクトフォルダ内のファイル名を指定して実行mvn deployコマンド

mvn deploy:deploy-file -Durl=file:///path/toyourproject/repo/ -Dfile=/pathToJar/poi.jar -DgroupId=poi -DartifactId=poi -Dpackaging=jar -Dversion=1.0 

、ローカルリポジトリにjarファイルをインストールするコマンド。 mvnがマシンにインストールされていない場合は、次のリンクを使用してください。

Install Maven in Windows

Install Maven in Ubuntu/UNIX

そしてローカルリポジトリエントリのpom.xmlを追加します。

<repositories> 
    <repository> 
     <id>project.local</id> 
     <name>project</name> 
     <url>file:${project.basedir}/repo</url> 
    </repository> 
</repositories> 

は最後に

<dependency> 
    <groupId>poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>1.0</version> 
</dependency> 

この依存関係は、プロジェクトフォルダ内に作成したローカルリポジトリからjarファイルを使用しますが、あなたの依存関係を追加します。

+0

提案していただきありがとうございます。 –

+0

私は2つのオプションを選択してmvn deployを使いたいのですが、このコマンドをどこで実行すればいいのですか?jarディレクトリをプロジェクトリポジトリにコピーできないのはなぜですか? –

+0

@AnilBhendarkarあなたの最初の質問の更新部分をチェックし、このコマンドでmavenが適切に作成されます。pomファイルリポジトリ構造は、Mavenリポジトリとして簡単に活用できます。 – Sheel

関連する問題