Reputation: 103
I'm new to java. When I try to learn Maven in 5 minutes, I found that this command
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
worked the same way as
java -cp target/my-app-1.0-SNAPSHOT.jar com/mycompany/app/App
It drives me crazy because the last argument in the second command is actually a path. What is the difference between "." and "/" in java classname?
I have looked up some articles but still don't get it.
Upvotes: 9
Views: 396
Reputation: 95366
This is an implementation detail leaking out. Largely for irrelevant historical reasons, class names in the language are dot-separated but class names in the classfile format are slash-separated. (https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.) For the most part, internal names are not visible to users, but they do leak in some circumstances. Many tools that deal with classfiles will convert from the external (dotted) to internal (slashed) name using something like replace('.', '/')
, which has the effect that internal names are also accepted by the tool. That's what's going on here.
Upvotes: 17