Can't name symbolic link to java file other than name of the java file

302 Views Asked by At

Take a look at the following picture:

I make a symbolic link to java .class file. And it works, I can pass the original file to Java interpreter via symbolic link, and it runs program normally. But if I name link any other than original file name, it doesn't work.

It frustrates me that I have to name it like original file name.

Not sure should I have posted this to Unix/Linux stack.

1

There are 1 best solutions below

0
On BEST ANSWER

It's a requirement because that's how Java finds the class file.

When you say java App, the App is not a file name, but a fully-qualified class name.

Java has some rules how to get from a class name to a file name. This is implemented in the default class loader. When the class is stored in a .class file (rather than a .jar file), it automatically appends the .class extension to the class name. Before it does that, it translates the package separator (which looks like a dot in Java source code) into the path separator of your operating system (on Linux, a / (slash), and on Windows a \ (backslash).

If you give the class file a different name, whether you do that with a real rename or with a symlink, Java is just not able to find it, because it doesn't follow the Java rules on how to get from a class name to a file name.