Reputation: 1538
I have an Applet
and when I use the getCodeBase()
I get a plain URL that looks like this:
http://localhost:8080/x/y/z/
I can use other Applet
methods like getImage(getCodeBase(), "images/img.gif")
to get resources (like an image in this case).
However, if I use Applet.class.getResource("/images/img.gif")
I see URLs that look like this:
jar:http://localhost:8080/x/y/z/a/b/lib/myjar.jar!/images/img.gif
Is one way better than the other? What are the pros and cons of each?
Upvotes: 2
Views: 56
Reputation: 597412
The latter is classpath-relative. It means that img.gif
is located within the jar file (and is found on the classpath of the applet jvm)
The former is a regular URL, and means that the gif file is present on the server at the given location.
They are used in different cases, so there's no "good or "bad" option. A thing to consider is: if you only need the image in the applet, you should place it in the jar rather than anywhere else on the server. (But this is not universal)
Upvotes: 3