In Java, Eclipse, what location does this line of code refer to?

this.getClass().getResource()

Does it give me the project folder? Or the package folder? Or anything else?

How exactly should one work with this?

没有正确的解决方案

其他提示

this.getClass().getResource("/")

it refers to root of your output directory (target/classes or any other output directory configured in your ide configuration if IDE is the case)

the same directory where your class file is located.

for example, you have an eclipse project with a x.y.z.My.java in the src dir

if it's compiled to x.y.z.My.class in the bin dir

then if this() is My.class, this will point to bin/x/y/z

GetResources is reffering to the location related all the packages in your CLASSPATH it means target/classes. Classpath and target can be configured depends on the IDE. For instance for Intellij : project properties->modules->paths

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top