Java - 编译错误:无法访问函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28584798/
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
Java - compilation error: cannot access Function
提问by
I have osgi project. Every bundle is a separate maven project. Project is large enough and includes about 10 bundles. Everything works and is ok.
我有 osgi 项目。每个包都是一个单独的 Maven 项目。项目足够大,包括大约 10 个包。一切正常,一切正常。
Today I've added one more library - https://code.google.com/p/owasp-java-html-sanitizer/. I've set all dependencies and ide (netbeans 8) shows everything is ok. However I get the following compilation code in this method:
今天我又添加了一个库 - https://code.google.com/p/owasp-java-html-sanitizer/。我已经设置了所有依赖项,ide (netbeans 8) 显示一切正常。但是我在这个方法中得到以下编译代码:
@Override
public void sanitize(Map<String,Object> policies){
PolicyFactory policy=(PolicyFactory) policies.get("html0");
this.code=policy.sanitize(this.code);
}
At the second line of the method (this.code...) I get the following compilation error: cannot access Function. Can't understand what it is about...
EDIT
Import section:
在该方法的第二行 (this.code...),我收到以下编译错误:无法访问函数。无法理解它是关于...
编辑
导入部分:
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.owasp.html.PolicyFactory;
EDIT
编辑
COMPILATION ERROR :
-------------------------------------------------------------
com/subjects/SubjectDirItemCore.java:[166,24] error: cannot access Function
1 error
-------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.687s
Finished at: Wed Feb 18 16:11:11 MSK 2015
Final Memory: 14M/205M
EDIT
- I tried via mvn install -X
编辑
- 我尝试通过 mvn install -X
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.....: Compilation failure ..../subjects/SubjectDirItemCore.java:[166,24] error: cannot access Function
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 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:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure /..../subjects/SubjectDirItemCore.java:[166,24] error: cannot access Function
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656) at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more [ERROR]
org.apache.maven.lifecycle.LifecycleExecutionException:无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.....: Compilation failure 。 .../subjects/SubjectDirItemCore.java:[166,24] 错误:无法访问函数
在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 在 org.apache.maven.lifecycle .internal.MojoExecutor.execute(MojoExecutor.java:145) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder) .java:59) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 在 org。 apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli。MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 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.refoke.Method.in (Method.java:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 引起:org.apache.maven。插入。CompilationFailureException: 编译失败 /..../subjects/SubjectDirItemCore.java:[166,24] 错误:无法访问函数
在 org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656) 在 org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128) 在 org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:101) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 更多 [错误]
采纳答案by Pranalee
I found the anwser - I used guava 12 instead of guava 11. I took 12 as it was the first version as osgi bundle.
我找到了 anwser - 我使用了 guava 12 而不是 guava 11。我使用了 12,因为它是 osgi bundle 的第一个版本。
回答by amphibient
In my case this happened when the artifact was posted to the local Maven
repository without a proper pom.xml
so the transitive dependencies did not get downloaded. Look for the artifact where the unfound class is located and manually enter it in your pom.xml, that should fix the problem.
在我的情况下,这发生在工件在Maven
没有适当的情况下发布到本地存储库时,pom.xml
因此没有下载传递依赖项。查找未找到的类所在的工件并在您的 pom.xml 中手动输入它,这应该可以解决问题。
回答by Pranalee
This seems jar version issue. Most probably, newer version of jar containing class PolicyFactory has reduced visibility level of method sanitize. There must be new method which you are supposed to use as earlier method is restricted.
这似乎是 jar 版本问题。最有可能的是,包含类 PolicyFactory 的较新版本的 jar 降低了方法 sanitize 的可见性级别。必须有您应该使用的新方法,因为较早的方法受到限制。