2016-07-04 13 views
0

私はAntでビルドされたレガシーjavaプロジェクトを持っています。しかし、ビルドされた新しいモジュールプロジェクトは進行中のプロジェクトです。問題は、antスクリプトを使用してmavenプロジェクトを作成し、従来のプロジェクトと新しいプロジェクトの依存関係を含む1つの.earファイルを作成することです。また、pom.xmlを使ってantスクリプトを実行する方法も探しています。私は両方の方法を試みたが、成功を収めることができなかった。antスクリプトを使ってmavenプロジェクトをビルドするには?

私のbuild.xmlにはこのターゲットを置いています。しかし、それはそれがbuild.xmlの中でエラーを示し

<artifact:mvn pom="../../idp/pom.xml" mavenHome="C:\Program Files\Apache\maven"> 
     <arg value="install"/> 
     </artifact:mvn> 

を助けにはなりません「プレフィックス"要素のアーティファクト" "アーティファクト:MVN "がバインドされていません」

私もこれを試してみてください。

compile-mvn-init: 
    [typedef] Could not load definitions from resource org/apache/maven/artifact/a 
nt/antlib.xml. It could not be found. 
    [echo] maven.repo.local=C:\Users\singh.pankaj/.m2/repository 
BUILD FAILED 
D:\projects\ddev\SL\DEV\RL2016_03\omega\build\build.xml:702: Problem: failed to 
create task or type urn:maven-artifact-ant:localRepository 
Cause: The name is undefined. 
Action: Check the spelling. 
Action: Check that any custom tasks/types have been declared. 
Action: Check that any <presetdef>/<macrodef> declarations have taken place 

<target name="compile-mvn-init" unless="compile.classpath" xmlns:artifact="urn:maven-artifact-ant">  
      <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" 
       classpath="lib/maven-ant-tasks-2.1.3.jar"/> 
      <condition property="maven.repo.local" value="${maven.repo.local}" else="${user.home}/.m2/repository"> 
       <isset property="maven.repo.local"/> 
      </condition>   
      <echo>maven.repo.local=${maven.repo.local}</echo> 
      <artifact:localRepository id="local.repository" path="${maven.repo.local}"/> 
      <artifact:pom file="../../idp/pom.xml" id="maven.project"/> 
      <artifact:dependencies pathId="compile.classpath" filesetId="compile.fileset" useScope="compile"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
      <artifact:dependencies pathId="test.classpath" filesetId="test.fileset" useScope="test"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
      <artifact:dependencies pathId="runtime.classpath" filesetId="runtime.fileset" useScope="runtime"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
     </target> 

をしかし、それは失敗のことを言います。

私は自分のbuild.xmlでこの部分を編集しましたが、これは実際にはパスの問題です。

<target name="compile-server" 
      description="Compiles Application Tier Implementation classes."> 

     <javac srcdir="${SOURCE.DIR}" destdir="${BUILD.DIR}" includes="com/emergis/els/server/**/*" 
       deprecation="${compile.deprecation}" debug="${compile.debug}" fork="${compile.fork}" 
       failonerror="${compile.failonerror}" verbose="${compile.verbose}" classpathref="javac.classpath.id"/> 

    </target> 

    <target name="compile-mvn-init" unless="compile.classpath" xmlns:artifact="urn:maven-artifact-ant">  
      <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" 
       classpath="${basedir}\lib\maven-ant-tasks-2.1.3.jar"/> 
      <condition property="maven.repo.local" value="${maven.repo.local}" else="${user.home}/.m2/repository"> 
       <isset property="maven.repo.local"/> 
      </condition>   
      <echo>maven.repo.local=${maven.repo.local}</echo> 
      <artifact:localRepository id="local.repository" path="${maven.repo.local}"/> 
      <artifact:pom file="../../idp/pom.xml" id="maven.project"/> 
      <artifact:dependencies pathId="compile.classpath" filesetId="compile.fileset" useScope="compile"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
      <artifact:dependencies pathId="test.classpath" filesetId="test.fileset" useScope="test"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
      <artifact:dependencies pathId="runtime.classpath" filesetId="runtime.fileset" useScope="runtime"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
     </target> 

ここでエラーはなくなりましたが、pom.xmlは実行されません。

compile-mvn-init: 
    [echo] maven.repo.local=C:\Users\singh.pankaj/.m2/repository 
[artifact:dependencies] Downloading: com/oracle/ojdbc14/10.2.0.1.0/ojdbc14-10.2. 
0.1.0.pom from repository central at http://repo1.maven.org/maven2 
[artifact:dependencies] Unable to locate resource in repository 
[artifact:dependencies] [INFO] Unable to find resource 'com.oracle:ojdbc14:pom:1 
0.2.0.1.0' in repository central (http://repo1.maven.org/maven2) 
[artifact:dependencies] Downloading: com/oracle/weblogi/weblogic/10.3.5/weblogic 
-10.3.5.pom from repository central at http://repo1.maven.org/maven2 
[artifact:dependencies] Unable to locate resource in repository 
[artifact:dependencies] [INFO] Unable to find resource 'com.oracle.weblogi:weblo 
gic:pom:10.3.5' in repository central (http://repo1.maven.org/maven2) 
[artifact:dependencies] Downloading: com/oracle/weblogi/wlfullclient/10.3.5/wlfu 
llclient-10.3.5.pom from repository central at http://repo1.maven.org/maven2 
[artifact:dependencies] Unable to locate resource in repository 
[artifact:dependencies] [INFO] Unable to find resource 'com.oracle.weblogi:wlful 
lclient:pom:10.3.5' in repository central (http://repo1.maven.org/maven2) 

mavenに基づいたプロジェクトidpのターゲットフォルダは更新されません。

+2

mavenを使用してAntプロジェクトを構築できますが、Antを使用してMavenプロジェクトを構築することはできません。 https://maven.apache.org/ant-tasks/しかし、最も良い方法は、レガシーをmavenに移行することです。 –

+1

Antにexecタスクがあり、コマンドラインでexecを実行できます。それはうまくいくでしょう。または、あなたはgraleを使ってantとmavenの両方を実行できます。 http://ant.apache.org/manual/Tasks/exec.html –

答えて

0

長い研究の末、私は解決策を出しました。私の新しいプロジェクトと私の遺産プロジェクトを成功裏に構築することができます。このために私は既存のbuild.xmlを変更しました。さらに2つのターゲット "compile-mvn-init"と "compile-idp"を追加します。

<target name="compile" 
      depends="init, with.clover, compile-auth-provider, compile-shared, compile-server, compile-client, compile-mvn-init, compile-idp" 
      description="Compiles Java code."/> 


<target name="compile-mvn-init" unless="compile.classpath" xmlns:artifact="urn:maven-artifact-ant" >  
      <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" 
       classpath="${basedir}\lib\maven-ant-tasks-2.1.3.jar"/> 
      <condition property="maven.repo.local" value="${maven.repo.local}" else="${basedir}/idp_lib"> 
       <isset property="maven.repo.local"/> 
      </condition> 
     <echo>maven.repo.local=${maven.repo.local}</echo> 
      <artifact:localRepository id="local.repository" path="${maven.repo.local}"/> 
      <artifact:pom file="../../idp/pom.xml" id="maven.project"/> 
      <property name="VERSION" value="${maven.project.version}"/> 
      <echo>The version is ${maven.project.version}</echo> 
      <property name="ARTIFACT_ID" value="${maven.project.artifactId}"/> 
      <echo>The ARTIFACT_ID is ${ARTIFACT_ID}</echo> 
      <artifact:dependencies pathId="compile.classpath" filesetId="compile.fileset" useScope="compile"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
      <artifact:dependencies pathId="test.classpath" filesetId="test.fileset" useScope="test"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
      <artifact:dependencies pathId="runtime.classpath" filesetId="runtime.fileset" useScope="runtime"> 
       <pom refid="maven.project"/> 
       <localRepository refid="local.repository"/> 
      </artifact:dependencies> 
     </target> 

<target name="compile-idp" > 

     <javac srcdir="../../idp/src" destdir="../../idp/target/idp-0.1/WEB-INF/classes" classpathref="compile.classpath"/> 
     <javac srcdir="../../idp/src/main/java" destdir="../../idp/target/classes" classpathref="compile.classpath"/> 

     <delete file="../../dist/idp"/> 
     <mkdir dir="../../dist/idp"/> 
     <mkdir dir="../../dist/idp/META-INF"/> 
     <mkdir dir="../../dist/idp/WEB-INF"/> 
     <mkdir dir="../../dist/idp/WEB-INF/classes"/> 
     <mkdir dir="../../dist/idp/WEB-INF/lib"/> 

     <copy todir="../../dist/idp/META-INF"> 
     <fileset dir="../../idp/src/main/webapp/META-INF"/> 
     </copy> 
     <copy todir="../../dist/idp/WEB-INF"> 
     <fileset dir="../../idp/src/main/webapp/WEB-INF"/> 
     </copy> 

     <javac srcdir="../../idp/src/main/java" destdir="../../dist/idp/WEB-INF/classes" classpathref="compile.classpath"/> 
     <copy todir="../../dist/idp/WEB-INF/lib" flatten="true"> 
     <fileset refid="runtime.fileset"/> 
     </copy> 
     <delete file="${app.deploy_dir}/config/${app.domainname}/applications/els.ear_dir/${ARTIFACT_ID}-${VERSION}.war"/> 
     <zip destfile="${app.deploy_dir}/config/${app.domainname}/applications/els.ear_dir/${ARTIFACT_ID}-${VERSION}.war" basedir="../../dist/idp"/> 
     </target> 
関連する問題