1

I have a utility project, lets call it utility-library that contains a class with the following structure.

public interface OuterInterfaceI {

    public static class InnerClass {
        // ... a couple of static and non static methods
    }

}

Now when I try to do the following within the utility-library, it compiles fine

OuterInterfaceI.InnerClass innerClassObject;

Now I need to use this in another project so I add the project's jar utility-library.jar (built via mavent) to the build path of my project (lets call it my-application). When I try to write the following code inside a class, it fails to compile.

import com.utility.commons.OuterInterfaceI;

public class SomeClass {
    private static OuterInterfaceI.InnerClass myObject;
}

Compiler fails with the following error message

The type com.utility.commons.OuterInterfaceI.InnerClass cannot be resolved. It is indirectly referenced from required .class files.

I have made sure that the utility-library.jar is on the classpath. Anything that I am missing ?

Update

I am using Eclipse Version: Mars.1 Release (4.5.1) and maven 3.3.3 with java 1.8.0_45. I thought that this may be a bug in eclipse, but I am getting compile time issue with the same class when I try to build from terminal as well

$ 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
Saif Asif
  • 5,516
  • 3
  • 31
  • 48
  • 1
    may a an eclipse bug (if you are using eclipse ). possible duplicate of http://stackoverflow.com/questions/18075343/java-project-in-eclipse-the-type-java-lang-object-cannot-be-resolved-it-is-ind – Saif Jul 21 '16 at 05:34
  • This is a static nested class, not an inner class. Have you imported the interface? – user207421 Jul 21 '16 at 05:43
  • So you haven't added the JAR file to the project correctly. – user207421 Jul 21 '16 at 05:46
  • @EJP All libraries are managed via maven. Even this `utility-project` is built and deployed over a private nexus server and then used in `my-application` via declaring it as a dependency in the pom of the project – Saif Asif Jul 21 '16 at 06:06
  • Neverthess that's what the symptoms suggest. It knows the full name of the class, which shows that the `import` is correct, it just can't find it anywhere. Maybe a versioning problem? – user207421 Jul 21 '16 at 06:21
  • Let me do a full clean and try to replicate the problem, one thing I have noticed is that the jar files contains the `OuterInterfaceI.class` but theres no `OuterInterfaceI$InnerClass.class` file. – Saif Asif Jul 21 '16 at 06:26
  • 1
    Solved the problem, problem was for some reason maven did not include my inner classes in the jar file. A clean install and deploy (a new snapshot) solved the problem. Thanks @EJP – Saif Asif Jul 21 '16 at 06:40
  • Then we can close or delete the question… – Holger Jul 21 '16 at 08:16

0 Answers0