- There are two eclipse workspaces, Workspace A and Workspace B.
In Workspace A, there is a project with an interface defining a public static method:
package workspacea; public interface Foo { public static String sayHello() { return "Hello, world!"; } }
I then exported the entire project from Workspace A to a *.jar-File, using Export → Java → JAR file and default settings.
In Workspace B, a class should access the static method previously defined:
package workspaceb; import workspacea.Foo; public class Bar { public static void test() { String msg = Foo.sayHello(); } }
The previously exported *.jar from Workspace A is added to the Java Build Path using Project Properties → Java Build Path → Libraries → Add External JARs...
After following these steps, the line Foo.sayHello();
does not compile:
Unresolved compilation problem:
This static method of interface Foo can only be accessed as Foo.sayHello
From my understanding, it should compile (it recognizes the Foo
interface perfectly fine). The funny thing is that it compiles fine if both projects are located in the same workspace (still using the *.jar library and not a project dependency).
Eclipse offers a quick-fix, which has no effect (at least not on the code).
What is happening here? Why does the code not compile? Is this an Eclipse bug? If so, is there a fix for it?
I am using Luna Service Release 2 (4.4.2) Build 20150219-0600 and used Java 8 in Workspace A, Java 7 in Workspace B.
Additional note: I can only reproduce this by using an interface
. Using an abstract class
and the same method works.