maven Java -编译错误:无法访问函数

xurqigkl  于 2023-01-29  发布在  Maven
关注(0)|答案(4)|浏览(216)

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.
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:

@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:

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
    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]
lymgl2op

lymgl2op1#

在我的例子中,当工件被发布到本地Maven存储库时,没有正确的pom.xml,因此传递依赖项没有被下载,就会发生这种情况。查找未找到的类所在的工件,并手动将其输入到您的pom.xml中,这应该可以解决问题。

t98cgbkg

t98cgbkg2#

这似乎是jar版本问题。最有可能的是,包含类PolicyFactory的较新版本的jar降低了方法清理的可见性级别。必须有您应该使用的新方法,因为较早的方法受到限制。

niknxzdl

niknxzdl3#

我找到了anwser -我用Guava12而不是Guava11。我取了12,因为它是作为osgi捆绑包的第一个版本。

ocebsuys

ocebsuys4#

我遇到了Java版本的问题:所需的依赖项的版本对于我有“无法访问”的项目来说太高级了。
但我不知道,直到我更新了编译器插件,使它能够正确地抱怨类文件版本,而不是只是“无法访问”。

相关问题