Java 从库实例化接口内部的内部类
我有一个实用程序项目,我们称之为Java 从库实例化接口内部的内部类,java,interface,java-8,Java,Interface,Java 8,我有一个实用程序项目,我们称之为实用程序库,它包含一个具有以下结构的类 public interface OuterInterfaceI { public static class InnerClass { // ... a couple of static and non static methods } } 现在,当我尝试在实用程序库中执行以下操作时,它编译得很好 OuterInterfaceI.InnerClass innerClassObject;
实用程序库
,它包含一个具有以下结构的类
public interface OuterInterfaceI {
public static class InnerClass {
// ... a couple of static and non static methods
}
}
现在,当我尝试在实用程序库中执行以下操作时,它编译得很好
OuterInterfaceI.InnerClass innerClassObject;
现在我需要在另一个项目中使用它,因此我将项目的jar实用程序库.jar
(通过mavent构建)添加到我的项目的构建路径(我们称之为我的应用程序
)。当我试图在类中编写以下代码时,它无法编译
import com.utility.commons.OuterInterfaceI;
public class SomeClass {
private static OuterInterfaceI.InnerClass myObject;
}
编译器失败,并显示以下错误消息
The type com.utility.commons.OuterInterfaceI.InnerClass cannot be resolved. It is indirectly referenced from required .class files.
我已确保实用程序库.jar
位于类路径上。我遗漏了什么
更新
我正在使用Eclipse版本:Mars.1发行版(4.5.1)和maven 3.3.3以及Java1.8.045。我认为这可能是eclipse中的一个bug,但当我尝试从终端构建时,我也遇到了同一个类的编译时问题
$ mvn clean test
[INFO] Scanning for projects...
[INFO]
.....................
.....................
[INFO] Compiling 90 source files to /home/msamirza/etilize_repo_folders/jdk8_migrations/...................
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com..... :[20,32] error: cannot access InnerClass
[ERROR] class file for com.utility.commons.OuterInterfaceI$InnerClass not found
/home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com/.....:[25,38] error: cannot find symbol
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.182 s
[INFO] Finished at: 2016-07-21T10:37:57+05:00
[INFO] Final Memory: 19M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project inQuire-Merchandising-Server: Compilation failure: Compilation failure:
[ERROR] /home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com/........:[20,32] error: cannot access InnerClass
[ERROR] class file for com.utility.commons.OuterInterfaceI$InnerClass not found
[ERROR] /home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com/........:[25,38] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
可能是一个eclipse错误(如果您正在使用eclipse)。可能重复的是静态嵌套类,而不是内部类。您导入接口了吗?所以您没有正确地将JAR文件添加到项目中。@EJP所有库都是通过maven管理的。即使这个实用程序项目
是在私有nexus服务器上构建和部署的,然后通过在项目的pom中将其声明为依赖项而用于我的应用程序
。解决了这个问题,因为某种原因,maven没有在jar文件中包含我的内部类。一个干净的安装和部署(一个新的快照)解决了这个问题。谢谢@EJPmay一个eclipse错误(如果您正在使用eclipse)。可能重复的是静态嵌套类,而不是内部类。您导入接口了吗?所以您没有正确地将JAR文件添加到项目中。@EJP所有库都是通过maven管理的。即使这个实用程序项目
是在私有nexus服务器上构建和部署的,然后通过在项目的pom中将其声明为依赖项而用于我的应用程序
。解决了这个问题,因为某种原因,maven没有在jar文件中包含我的内部类。一个干净的安装和部署(一个新的快照)解决了这个问题。谢谢@EJP