2011-09-07 36 views
8

Tôi cần sử dụng XML để JSON lib trong chiến tranh của mình. Tôi đã theo dõi một số tutorial giải thích rằng các phụ thuộc được yêu cầu trong dự án.Ant/Eclipse phàn nàn về tạo tác: phụ thuộc

Nhưng khi tôi thêm như sau trong kiến ​​của tôi build.xml (file dùng để tạo ra chiến tranh), Eclipse phàn nàn về artifact:dependencies, có vẻ như nó không thích : .Tôi có thông báo lỗi sau:

Tiền tố artifact cho các phần tử artifact:dependencies không bị ràng buộc ...

<artifact:dependencies filesetId="dependency.fileset" 
    sourcesFilesetId="sources.dependency.fileset" 
    javadocFilesetId="javadoc.dependency.fileset" 
    versionsId="dependency.versions"> 
    <!-- DEPENCIES GO HERE --> 
</artifact:dependencies> 

Bất kỳ ý tưởng?

CẬP NHẬT

Tôi có cùng một vấn đề cố gắng để xác định một pom trong bộ nhớ với:

<artifact:pom id="mypom" groupId="org.acme" artifactId="project1" version="1.0"> 
    <dependency groupId="junit" artifactId="junit" version="4.1"/> 
    <dependency groupId="org.codehaus.plexus" artifactId="plexus-utils" version="1.5.5"/> 
    <license name="apache" url="http://www.apache.org"/> 
</artifact:pom> 

Tiền tố artifact cho các phần tử artifact:pom không bị ràng buộc ...

CẬP NHẬT 2

Tôi đã cài đặt maven-ant jar trong kiến ​​/ lib và thay đổi tệp build.xml để nó chứa định nghĩa về các phần tạo tác nhưng tôi có thông báo lỗi khi chạy nó.

<project name="test" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant"> 

<artifact:dependencies pathId="dependency.classpath"> 
    <dependency> 
     <groupId>net.sf.json-lib</groupId> 
     <artifactId>json-lib</artifactId> 
     <version>2.3</version> 
     <type>jar</type> 
     <classifier>jdk15</classifier> 
     <scope>compile</scope> 
     </dependency> 
     ... 

Thông báo lỗi Eclipse cho là:

BUILD FAILED 
D:\J2EE\workspace\Test\build.xml:3: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:dependencies 
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. 
No types or tasks have been defined in this namespace yet 
This appears to be an antlib declaration. 
    Action: Check that the implementing library exists in one of: 
    -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib 
    -C:\Documents and Settings\luc\.ant\lib 
    -a directory added on the command line with the -lib argument 

Các jar maven-ant tồn tại trong -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib

CẬP NHẬT 3

Đây là file build.xml tôi đang sử dụng.

<!-- 
<project name="Monitoring" default="install" xmlns:artifact="urn:maven-artifact-ant" xmlns:test="urn:test-tasks"> 
--> 
<project name="Monitoring" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant"> 

<!-- project-specific variables --> 
<property environment="env" /> 
<property name="project_home" value="D:\J2EE\workspace\Monitoring"/> 
<property name="webapp.dir" value="${project_home}/target" /> 
<property name="jboss.dir" value="D:\J2EE\jboss\standalone\deployments" /> 
<property name="package.name" value="monitoring.war" /> 
<property name="lib.dir" value="${project_home}/lib" /> 
<property name="src.dir" value="${project_home}/src" /> 
<property name="resources.dir" value="${project_home}/resources" /> 
<property name="dest.dir" value="${project_home}/target" /> 
<property name="package.file" value="${dest.dir}/${package.name}" /> 

<!-- put everything in a temp folder with the right structure during the build --> 
<property name="temp.dir" value="${project_home}/temp" /> 
<property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" /> 
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" /> 
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" /> 
<property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" /> 


<path id="build.class.path"> 
    <fileset dir="${env.JAVA_HOME}/lib"> 
     <include name="**/*.jar" /> 
    </fileset> 
    <fileset dir="D:\ant\lib"> 
      <include name="**/*.jar" /> 
    </fileset> 
</path> 

<target name="deps"> 
    <artifact:dependencies pathId="dependency.classpath"> 
     <dependency> 
      <groupId>net.sf.json-lib</groupId> 
      <artifactId>json-lib</artifactId> 
      <version>2.3</version> 
      <type>jar</type> 
      <classifier>jdk15</classifier> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>1.3.2</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>xom</groupId> 
      <artifactId>xom</artifactId> 
      <version>1.1</version> 
     </dependency> 
    </artifact:dependencies> 
</target> 

<target name="clean" depends="deps"> 
    <delete> 
     <fileset dir="${dest.dir}" includes="**/*"/> 
    </delete> 
    <delete dir="${temp.dir}" /> 
    <delete dir="${temp.dir.classes}" /> 
    <delete dir="${temp.dir.meta-inf}" /> 
    <delete dir="${temp.dir.web-inf}" /> 
</target> 

<target name="prepare" depends="clean"> 
    <mkdir dir="${dest.dir}" /> 
    <mkdir dir="${temp.dir}" /> 
    <mkdir dir="${temp.dir.lib}" /> 
    <mkdir dir="${temp.dir.meta-inf}" /> 
    <mkdir dir="${temp.dir.web-inf}" /> 
    <mkdir dir="${temp.dir.classes}" /> 
</target> 

<!-- COMPILE --> 
<target name="compile" depends="prepare"> 
    <echo>=== COMPILE ===</echo> 
    <echo>Compiling ${src.dir} files ...</echo> 
    <javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}" includes="**/*" includeantruntime="false"> 
     <classpath refid="build.class.path" /> 
     <classpath refid="dependency.classpath" /> 
    </javac> 
</target> 

<!-- PACKAGE --> 
<target name="package" depends="compile"> 
    <echo>=== PACKAGE ===</echo> 

    <!-- copy the config files --> 
    <copy file="${resources.dir}/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" /> 
    <copy file="${resources.dir}/manifest.mf" tofile="${temp.dir.meta-inf}/manifest.mf" overwrite="true" /> 
    <copy todir="${temp.dir.classes}"> 
    <fileset dir="${src.dir}"> 
     <include name="**/*.xml"/> 
     <include name="**/*.xsl"/> 
    </fileset> 
    </copy> 

    <!-- the ant war task. with all resources in place, create the war file --> 
    <war destfile="${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}"> 
    <lib dir="${lib.dir}" /> 
    <classes dir="${temp.dir.classes}" /> 
    </war> 
</target> 

<!-- INSTALL --> 
<target name="install" depends="package"> 
    <echo>=== INSTALL ===</echo> 
    <copy file="${package.file}" tofile="${webapp.dir}/${package.name}" overwrite="true" /> 
    <copy file="${package.file}" tofile="${jboss.dir}/${package.name}" overwrite="true" />   
</target> 

</project> 

Nó hoạt động tốt trước khi tôi thêm tất cả nội dung phụ thuộc ... vẫn không thể tìm ra pb tại đây. Bất kỳ trợ giúp sẽ rất hoan nghênh.

Trả lời

12

Có vẻ như bạn đang sử dụng số Maven Ant Tasks. Để làm điều này, bạn sẽ cần một bản sao của lọ từ khu vực tải xuống here. Khi (hoặc nếu) bạn đã có, bạn sẽ cần phải sửa đổi tệp buildfile của bạn để sử dụng nó.

Những điều chính mà are needed là để xác định không gian tên artifact, và thêm typedef cho ant-lib:

<project name="foo" default="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant"> 

    <path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" /> 
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml" 
     uri="antlib:org.apache.maven.artifact.ant" 
     classpathref="maven-ant-tasks.classpath" /> 
+0

cảm ơn. Tôi đã làm những gì bạn đề nghị nhưng tôi vẫn có một số vấn đề. Tôi đã cập nhật câu hỏi để thêm chi tiết. – Luc

+0

@Luc - nhiều lời xin lỗi Tôi nghĩ rằng mẫu tôi tham chiếu không phải bằng bất kỳ lý tưởng nào. Tôi đã thêm một liên kết đến mẫu thích hợp và cập nhật XML mẫu ở trên. Bit bị thiếu là typedef. –

+0

Cảm ơn bạn đã đề cập đến việc xác định tên miền. Bằng cách nào đó đã bỏ lỡ điều đó. – stevebot

0

tôi đã được thông báo lỗi tương tự nhưng nguyên nhân là khác nhau.

Đi tới cửa sổ -> Tùy chọn -> Ant -> Thời gian chạy và cài đặt Ant Home giải quyết được sự cố của tôi.

Vì vậy, đối với bất kỳ ai ở trên giải pháp không hoạt động, hãy kiểm tra xem "Ant Home" đang trỏ đúng hướng

Các vấn đề liên quan