java - class.getResource ("."/*dot*/) 有什么特殊含义吗?

标签 java classloader

有时我会在其他人的代码中看到这一点。但是当我尝试时,它返回 null。

baseUrl = org.company.UploadService.class.getResource(".");
url = new URL(baseUrl, "http://192.168.164.32:9080/mka-web/services/UploadService?wsdl");

最佳答案

getResource(".") 在某些情况下会返回指向类文件所在目录的 URL。

This thread将行为描述为:

a URL pointing to the directory in the class path used to load the class if the class is loaded from a directory, or null when loaded from a jar.

最后一部分可能是您得到 null 的原因。另一个原因可能是:

It does not work with all JVMs

关于java - class.getResource ("."/*dot*/) 有什么特殊含义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24307480/

相关文章:

java - 在 Java Instrumentation Agent 中使用 Class.forName()

ant - 是否有使用 ant junit 任务的可自定义类加载顺序?

java - 什么是非惰性初始化?

java - 使用 scriptlet 在 jsp 中迭代 dataList

java - 什么是NullPointerException,我该如何解决?

java + sqlite : how to open database as read-only?

java - 我该如何进行此搜索 db.collection.find( { foo :/^bar$/i } ); on mongo but using Mongo Java Driver

java - NoClassDefFoundError 有时对于 System.out.close() 之后的标准类

java - 如何使用反射调用外部 jar 内的方法

java - Android studio gradle 太长