使用 JDK 1.8 java 编译:无法访问类文件...找不到类文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40255718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:03:35  来源:igfitidea点击:

Compiling with JDK 1.8 java: cannot access class file... class file not found

javajava-8javacjdk1.6jdk1.8.0

提问by Anil Kamaraju

Though the same code was getting to compiled successfully with JDK 1.6 version, after upgrading to JDK 1.8 it won't compile, saying java cannot access ....class file ...as class file not found though it exists.

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

I am compiling this in IntelliJ Idea 13 IDE, tried with both Rebuild option as well as configured ANT build - result is same.

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

Any help is highly appreciated.

任何帮助都受到高度赞赏。

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)

回答by Anil Kamaraju

This issue is resolved now :). It's basically related to class path setup and only applicable for JDK 1.8.

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

For ex : If class 'A' has a reference to class B and class B is implementing an interface say 'C' then javac in JDK 1.8 requires both class B as well as Interface C on the class path where as prior to 1.8 only having class B on the class path was enough.

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

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

请参阅https://bugs.openjdk.java.net/browse/JDK-8055048了解更多信息。

回答by Riccardo Bonesi

Build -> Rebuild Project worked for me

构建 -> 重建项目对我有用

回答by Gaetano

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.

我在执行一个返回类路径中没有的类的函数时遇到了这个问题,但我只想访问他的内部字段。例如: container.getContent().getField()我必须导入 Content 类才能使其工作。

回答by dragonfly

You can use gradle to solve this problem.

你可以使用gradle来解决这个问题。

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

将“transitive = true”添加到依赖项中。像这样:

    compile('com.***.android:***sdk:1.0.2.6@aar') {
        transitive = true
    }