Launching single file source code program - "error: class found on application class path"

Jaikiran Pai jai.forums2013 at gmail.com
Sun Jun 17 10:56:34 UTC 2018


Consider this very simple class:


public class A {
     public static void main(final String[] args) throws Exception {
         System.out.println("Passed");
     }
}

I built the latest JDK from source and used the "launch single file 
source program" feature as follows:

 > cd /tmp/foo-bar

(this dir contains just A.java file)

 > java A.java

The output is as follows (as expected):

Passed

Then I went ahead and did an explicit compilation of this Java file:

 > javac A.java

The /tmp/foo-bar directory now consists of A.class and A.java. I then 
went ahead and (tried) to launch the A.java using the new feature as 
previously:

 > java A.java

I now get this error message:

error: class found on application class path: A

1. That error message isn't clear about what the problem is. I guess 
it's trying to convey that there's already a compiled class for the same 
source class, in the application classpath?

2. Why is this an error? Is it intentional?

-Jaikiran




More information about the jdk-dev mailing list