首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >由于无效的依赖项,无法加载类org.eclipse.jdt.core.JDTCompilerAdapter。

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

Stack Overflow用户
提问于 2015-11-08 21:20:31
回答 1查看 4.3K关注 0票数 6

我正在创建一个java代理,它将用于对某些类进行字节码修改,org.eclipse.jdt.core.JDTCompilerAdapter就是其中之一。我正在使用javassit修改org.eclipse.jdt.core.JDTCompilerAdapter的一些org.eclipse.jdt.core.JDTCompilerAdapter方法。因此,我在代理项目中包含了ecj (使用gradle)。

代码语言:javascript
运行
复制
compile group: 'org.eclipse.jdt.core.compiler' ,name: 'ecj', version :'4.3.1'

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

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

我正在用带有两个类的简单java项目来测试代理。该项目使用ant构建,并使用JDTCompilerAdapter作为编译器。

这是build.xml文件

代码语言:javascript
运行
复制
<?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>

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

代码语言:javascript
运行
复制
java -jar agent-wrapper.jar --outdir ./out --exec ./build_wrapper.sh

build_wrapper.sh包含这样的内容(我添加了ecj依赖项,这样我就可以像在bulid.xml <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>中那样用JDTCompilerAdapter编译该项目:

代码语言:javascript
运行
复制
../ant/bin/ant -lib ../eclipse/plugins/ecj-4.3.1.jar  build-e

其思想是,代理包装器将解析参数(outdir用于生成一些内容,exec是一个用于启动测试项目构建的脚本),获取要从build_wrapper.sh执行的命令(在本例中为../ant/bin/ant -lib ../eclipse/plugins/ecj-4.3.1.jar build-e),并将其作为java代理添加到命令中。

此问题发生在代理的执行过程中。这是输出:

代码语言:javascript
运行
复制
    java -jar  custom-agent.jar --outdir ./out --exec ./build_wrapper.sh                              [10:18:53]
Picked up JAVA_TOOL_OPTIONS: -javaagent:/Users/dev/TestAgent/project/custom-agent.jar=OUTDIR=/Users/dev/TestAgent/project/./out 
objc[30474]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Buildfile: /Users/dev/TestAgent/project/build.xml

build-e:

init:
    [mkdir] Created dir: /Users/dev/TestAgent/project/bin

build:

BUILD FAILED
/Users/dev/TestAgent/project/build.xml:47: The following error occurred while executing this line:
/Users/dev/TestAgent/project/build.xml:32: Class org.eclipse.jdt.core.JDTCompilerAdapter could not be loaded because of an invalid dependency.

Total time: 2 seconds
abnormal termination, exit code: 1

当我在代理项目中不使用ecj-4.3.1.jar时,构建运行良好--我拦截对execute()方法的调用,但不能使用ecj中的其他类。

EN

Stack Overflow用户

回答已采纳

发布于 2015-11-18 17:03:10

显示停止错误是“由于无效的依赖关系而无法加载类org.eclipse.jdt.core.JDTCompilerAdapter”。

从读取此链接adapter.htm中可以找到错误的第一个提示。

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

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

在上面提到的链接中,基于eclipse版本和java版本的差异是有记录的。

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33599163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档