18

虽然使用 JDK 1.6 版本可以成功编译相同的代码,但升级到 JDK 1.8 后它不会编译,说java cannot access ....class file ...as class file not found though it exists.

我在 IntelliJ Idea 13 IDE 中编译它,尝试使用 Rebuild 选项和配置的 ANT 构建 - 结果是相同的。

非常感谢任何帮助。

cannot access IDispatchRequest
class file for com.abc.xyz.orchestrator.dispatch.IDispatchRequest not found
1 error


Compile failed; see the compiler error output for details.
    at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1079)
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:882)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.Main.start(Main.java:179)
    at org.apache.tools.ant.Main.main(Main.java:268)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
4

6 回答 6

23

这个问题现在解决了:)。它基本上与类路径设置有关,仅适用于 JDK 1.8。

例如:如果类'A'引用了类B并且类B正在实现一个接口说'C',那么JDK 1.8中的javac在类路径上需要类B和接口C,而在1.8之前只有类路径上的 B 类就足够了。

Please refer https://bugs.openjdk.java.net/browse/JDK-8055048 for more info.

于 2016-10-28T06:51:40.830 回答
1

Build -> Rebuild Project worked for me

于 2020-01-14T16:02:45.460 回答
0

I had this problem when executing a function that was returning a class that i didn't had in classpath, but I just wanted to access his inner fields. e.g: container.getContent().getField() I had to import the Content class to make it work.

于 2018-10-25T12:54:59.183 回答
0

For me this meant I had downloaded a corrupted jar I think. Nuke ~/.m2/repository and try again...

于 2020-11-13T20:00:15.753 回答
0

For me, the class that cannot be accessed was inside an external JAR. The scenario was suitable with the accepted answer here.

I solved mine by adding the JAR as a dependency to the module that error was thrown. Meaning if the error was thrown from class A, and class C was not accessed, I added the JAR containing class C as dependency to the pom.xml of module containing class A.

于 2021-02-12T16:17:02.620 回答
-1

You can use gradle to solve this problem.

Add "transitive = true" to the dependency. Just like this:

    compile('com.***.android:***sdk:1.0.2.6@aar') {
        transitive = true
    }
于 2018-10-26T06:36:34.813 回答