2

最近、UbuntuマシンにAnt 1.8.4JasperReports 4.6.0をインストールしました。

私のアカウントには、次の環境変数が設定されています。

PATH=$PATH:/opt/ant/bin

export PATH

export ANT_HOME=/opt/ant

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64

コマンドを使用してJasperReportsデモ サンプル ディレクトリでデモ ビルド ファイルを実行しようとするとant、次のエラーが発生します。

Buildfile: build.xml

BUILD FAILED
/opt/jasperreports-4.6.0/demo/samples/antcompile/build.xml:3: The following
 error occurred while executing this line:
jar:file:/opt/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed to create task or type componentdef
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.

この問題を解決するための助けは非常に役に立ちます。

build.xmlファイルのスニペット:

<project name="antcompile" default="test" basedir=".">

    <description>Shows how multiple JRXML files can be compiled in batch mode using ANT.</description>

    <path id="classpath">
        <pathelement location="../../../build/classes"/>
        <fileset dir="../../../lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <path id="runClasspath">
        <path refid="classpath"/>
        <pathelement location="../../fonts"/>
        <pathelement location="./build/classes"/>
    </path>

    <taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"> 
        <classpath refid="classpath"/>
    </taskdef>

    <target name="javac" description="Compiles the Java source files used in the report designs.">
        <mkdir dir="./build/classes"/> 
        <javac srcdir="./src" destdir="./build/classes" debug="true" optimize="false" deprecation="false"/>
    </target> 

    <target name="compile1" description="Compiles report designs specified using the &quot;srcdir&quot; in the &lt;jrc&gt; tag."> <!-- 27 row # -->
        <mkdir dir="./build/reports"/> 
        <jrc 
                srcdir="./reports"
                destdir="./build/reports"
                tempdir="./build/reports"
                keepjava="true"
                xmlvalidation="true">
            <classpath refid="runClasspath"/>
            <include name="**/*.jrxml"/>
        </jrc>
    </target> 
4

3 に答える 3

2

このAntスクリプトは、カスタム タスクjrcを使用しています。

以下のスニペットからわかるように (これはjasperreports-4.6.0/demo/samples/antcompileフォルダーのbuild.xmlファイルです)、このタスクの定義は同じビルド ファイルのクラスパスを参照します。

<path id="classpath">
    <pathelement location="../../../build/classes"/>
    <fileset dir="../../../lib">
        <include name="**/*.jar"/>
    </fileset>
</path>

...

<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"> 
    <classpath refid="classpath"/>
</taskdef>

../../../build/classesフォルダー (サンプルを含むJasperReportsパッケージのフォルダー構造内)を確認する必要があります - net.sf.jasperreports.ant.JRAntCompileTaskクラスがそこにある必要があります。

つまり、このクラス (またはjasperreports-4.6.0.jar ) をクラスパス ( path id="classpath") に配置する必要があります。


問題の原因として考えられるもう 1 つの原因は、Antパッケージのバージョンです。

Project#createTask がAntの bugtrackerで task componentdef の問題を見つけられないと訴えていること、およびproject.createTask() が ant-1.8.2 の投稿で機能しないことについて読むことができます。

于 2012-08-21T18:56:01.670 に答える
2

CLASSPATH の次の要素 /opt/jasperreports-4.6.0/lib/ant-1.7.1.jar を /opt/ant/lib/ant.jar に変更することで機能させました。役立つリンクを投稿してくれた Alex に感謝します。アンジャン

于 2012-08-21T19:47:52.350 に答える
0

あなたはここで私たちを少し助けなければならないでしょう...

JasperReports-4.6.0を構築していますか?または、JasperReportsを一部として使用していますbuild.xmlか?build.xmlこれはJasperReportsのデモテストですか?

エラーは、カスタムタスク/タイプが宣言されていることを確認することを示しています。37行目のAntタスクは何ですか?にありますか?クラスパスが定義されていますか?taskdefがある場合は、それが何であるか、およびカスタムタスクが何であるかを確認してください。build.xml

iReportをダウンロードして、あなたが何をしているかを理解できるかどうかを確認していますが、15分かかります。私はあなたがいくつかの瓶を入れることになっているに違いない$ANT_HOME/lib。たぶん、そのJasperReportsまたはiReportjarfileです。

iReportをダウンロードして、あなたが話していることを確認でき次第、回答を更新します。

その間、行#35の周りに関連するコードをあなたbuild.xmlに、taskdefタスクをあなたに含めてくださいbuild.xml


iReportのダウンロードが完了し、build.xmlファイルが含まれていません。コードを投稿する必要があるので、コードを確認します。

繰り返しになりますが、私の仮定では、あなたが固執する/opt/ant/libと仮定したが、固執しなかったjarファイルがいくつかあると仮定しています。

于 2012-08-21T18:24:15.583 に答える