2009-04-21 8 views
9

私のpomのプロパティをすべてのプロジェクトの依存関係を含むクラスパスに設定したいと思います。 antプラグインはこのようなことをするので、間違いなく可能です。maven.compile.classpathに含まれるプロパティをAntなしに設定する

私は基本的には私のポームの中で好きな場所であればどこでも$ {maven.compile.classpath}を使いたいだけです。私はこれを達成するためにプラグインなどを使用しても構いません。

多くのおかげで、

ニック

答えて

5

私はあなた自身のMavenプラグインを記述することなくこれを行う方法があるとは思いません。つまり、dependency:build-classpathを使ってクラスパスに行くことができます。それは使用のですか?

2

私は依存関係をビルド - クラスパスの提案です。それは現在のプロパティに入れませんが、簡単に変更することができます。これは、それがどのように動作するかである

+0

http://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file -in-mavenは、結果をMavenプロパティとしてロードする方法を説明しています。 http://jira.codehaus.org/browse/MCOMPILER-97の添付ファイルは完全な例です。 –

6

(パッチが受け入れられた):それはあなたが${maven.classpath}プロパティを使用することができます実行されます

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7</version> 
    <executions> 
    <execution> 
     <id>define-classpath</id> 
     <phase>process-resources</phase> 
     <goals> 
     <goal>run</goal> 
     </goals> 
     <configuration> 
     <exportAntProperties>true</exportAntProperties> 
     <target> 
      <property name="maven.classpath" refid="maven.runtime.classpath"/> 
     </target> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

後。

+0

私はこの解決策が大好きですが、antrun m2eコネクタがないので使用できません。 – Ring

+0

これは、子pomによって使用される親pom宣言では機能していないようです.... – momomo

5

バージョン2.7以降、maven-dependency-pluginはプロパティをクラスパスに設定できるようになりました。あなたはEclipseのサポートはここに私の更新サイトだ場合

<plugin> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <version>2.8</version> 
     <executions> 
      <execution> 
       <phase>generate-sources</phase> 
       <goals> 
        <goal>build-classpath</goal> 
       </goals> 
       <configuration> 
       <outputProperty>maven.compile.classpath</outputProperty> 
       <pathSeparator>;</pathSeparator> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 

:ここでは例です

http://terraframe.github.io/m2e-maven-dependency-plugin/snapshots/

0

あなたは(完全なパスなし)瓶の単純なリストとしてクラスパスを生成する必要がある場合は、以下の例のようなプラグインを実装することができます。私はEclipse "JarRsrcLoader"(これはOne-JARと似ています)のようなツールを使っているので、クラスパスを "Class-Path"以外のプロパティを使ってマニフェストに追加する必要があります。このようにManifest.MFを作成します:

Manifest-Version: 1.0 
Rsrc-Class-Path: ./ ssm-core-0.0.1-SNAPSHOT.jar commons-codec-1.9.jar 
commons-io-2.4.jar ehcache-2.8.3.jar spring-beans-4.0.5.RELEASE.jar s 
sm-standalone-cryptlayer-0.0.1-SNAPSHOT.jar shiro-core-1.2.3.jar comm 
ons-beanutils-1.8.3.jar bcprov-jdk15on-1.50.jar javacsv-2.0.jar ssm-f 
ile-persistence-0.0.1-SNAPSHOT.jar spring-context-4.0.5.RELEASE.jar s 
pring-aop-4.0.5.RELEASE.jar aopalliance-1.0.jar spring-core-4.0.5.REL 
EASE.jar commons-logging-1.1.3.jar spring-expression-4.0.5.RELEASE.ja 
r slf4j-log4j12-1.7.7.jar slf4j-api-1.7.7.jar log4j-1.2.17.jar 
Built-By: ctasso 
Build-Jdk: 1.7.0_10 
Class-Path: . 

だから、私はこのようなMavenプラグインに定義:このプラグインを使用して

public void execute() throws MojoExecutionException, MojoFailureException { 
     try { 


      MavenArchiver mavenArchiver = new MavenArchiver(); 

      ManifestConfiguration config = new ManifestConfiguration(); 
      config.setAddClasspath(true); 
      Manifest manifest = mavenArchiver.getManifest(project, config); 


      String classPath = manifest.getMainAttributes().getValue("Class-Path"); 

      getLog().debug(String.format("Setting the classpath property %s to %s",classpathVarName,classPath)); 

      project.getProperties().put(classpathVarName, classPath); 

     } catch (DependencyResolutionRequiredException e) { 
      throw new MojoFailureException(e.getMessage()); 
     } catch (ManifestException e) { 
      throw new MojoFailureException(e.getMessage()); 
     } 

    } 

を、あなたはクラスパスのjarファイルのリストが含まれているプロパティを定義することができます

<plugin> 
    <groupId>it.cineca.plugins</groupId> 
    <artifactId>classpath-maven-plugin</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <executions> 
     <execution> 
      <id>set-classpath</id> 
      <phase>package</phase> 
      <goals> 
       <goal>setcp</goal> 
      </goals> 
      <configuration> 
       <classpathVarName>cineca.classpath</classpathVarName> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

としたいところはどこでもあなたのカスタムMANIFEST.MFを作成するために、たとえば、このプロパティを使用します。

<archive> 
    <manifestEntries> 
     <Rsrc-Class-Path>./ ${cineca.classpath}</Rsrc-Class-Path> 
     <Class-Path>.</Class-Path> 
     <Rsrc-Main-Class>it.cineca.cpd.starter.TestStarter</Rsrc-Main-Class> 
     <Main-Class>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</Main-Class> 
    </manifestEntries> 
</archive> 
関連する問題