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

Jonathan Gibbons jonathan.gibbons at oracle.com
Mon Jun 18 17:52:25 UTC 2018


On 06/17/2018 03:56 AM, Jaikiran Pai wrote:
> 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?

Yes, that is what the message is saying.

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

This is the intended behavior, to avoid the ambiguity of having the 
class on the classpath (which defaults to the current directory) and the 
internally-compiled class generated from the source file.

>
> -Jaikiran
>
>



More information about the jdk-dev mailing list