I have searched for a method of embedding a resource in a java project (using Eclipse v3.6.0) then using that embedded resource within a control (e.g., JLabel
).
Just put those resources in the source/package structure and use ClassLoader#getResource() or getResourceAsStream() to obtain them as URL
or InputStream
from the classpath by the full qualified package path.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("/image.gif");
// ...
Or if it is in the same package as the current class, you can also obtain it as follows:
InputStream input = getClass().getResourceAsStream("image.gif");
As a side question, how do I get Eclipse to create the project as a executable so it can be launched.
Rightclick Java Project > Export > Runnable JAR File .