由于依赖项无效,无法加载类org.eclipse.jdt.core.JDTCompilerAdapter

时间:2015-11-08 21:20:32

标签: java ant eclipse-jdt ecj

我正在创建一个java代理,用于对某些类进行字节码修改org.eclipse.jdt.core.JDTCompilerAdapter就是其中之一。我正在使用javassit修改execute()的{​​{1}}方法。所以我在我的代理项目中使用了ecj(使用gradle)

org.eclipse.jdt.core.JDTCompilerAdapter

因为我需要使用ecj中的一些类。

代理的目标是拦截对execute方法的调用,修改execute方法以添加对我的某些类的一些调用,以触发一些处理。

我正在针对具有2个类的Simple java项目测试代理。该项目使用ant构建,并使用compile group: 'org.eclipse.jdt.core.compiler' ,name: 'ecj', version :'4.3.1' 作为编译器。

这是build.xml文件

JDTCompilerAdapter

构建项目时将使用代理。 因此,为了测试代理,我使用以下命令:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="TestProject">
<property file="build.properties" />

<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="PClasspath">
    <pathelement location="bin"/>
</path>


<target name="init">
    <mkdir dir="bin"/>
    <copy includeemptydirs="false" todir="bin">
        <fileset dir="src">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>
<target name="clean">
    <delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="init" name="build">

    <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
        <src path="src"/>
        <classpath refid="PClasspath"/>

    </javac>
</target>
<!--
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
    <copy todir="${ant.library.dir}">
        <fileset dir="${ECLIPSE_JDT_CORE}" includes="*.jar"/>
    </copy>
</target>-->
<target  name="build-e" >

    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    <antcall target="build"/>
</target>

build_wrapper.sh包含这个(我添加了ecj依赖项,所以我可以使用java -jar agent-wrapper.jar --outdir ./out --exec ./build_wrapper.sh 编译项目,就像我在bulid.xml JDTCompilerAdapter中一样:

<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>

这个想法是代理包装器将解析参数(outdir用于生成一些东西,exec是用于启动我的测试项目的构建的脚本)从{{1}获取要执行的命令(在这种情况下为../ant/bin/ant -lib ../eclipse/plugins/ecj-4.3.1.jar build-e )并将其作为java代理添加到命令中。

在执行代理期间会出现问题。这是输出:

build_wrapper.sh

当我在代理项目中不使用ecj-4.3.1.jar时,构建运行良好我拦截了对../ant/bin/ant -lib ../eclipse/plugins/ecj-4.3.1.jar build-e方法的调用,但是我不能使用其他类来自ecj jar。

1 个答案:

答案 0 :(得分:2)

显示停止错误是&#34;由于依赖性无效,无法加载类org.eclipse.jdt.core.JDTCompilerAdapter。&#34;

可以通过阅读此链接找到有关故障的第一个提示 http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-ant_javac_adapter.htm

第二个提示可能是缺少运行JDTCompilerAdapter所需的其中一个jar。

为了让JDTCompilerAdapter工作,我将JDTCompilerAdapter.jar和org.eclipse.jdt.core.jar复制到ant / lib文件夹中。

根据上面提到的链接中记录的eclipse版本和java版本存在差异。

相关问题