开发者

How to load DTDs from a jar file?

The intended machine doesn't have a connection to the internet and I do not want to load it using a fixed location.

Aim: To load DTDs from a开发者_如何学Python jar, the jar will be a dependency.


To load any file from the classpath (it is, the space where youre classes reside, usually a bunch of jars) you can do:

InputStream is = this.getClass().getResourceAsStream("my/package/ResourceFile.dtd");

And then you can use the input stream where you want.

Note: getResourceAsStream() loads the resource using the class loader that loaded the class. If you are making an application any class from your application (and hence loaded by the same classloader with your jars) will be fine.


There is no standard way to provide a local cache (CATALOG if I recall correctly) of DTD's.

Hence, you will need to investigate the parser that will use the local copies, and use its non-standard configuration API to let it know about these local copies so that the trip to the net is avoided.

Use the getResourceAsStream() method to pick out entries from the classpath.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜