Using png file of other .jar as image doesn't work

Hey everybody,

I have a class at a .war and want to add at this class a png file of an other jar (EJB ) as icon to a button and it doesn’t work.

My scenario is the following:
I have several deployments at the Wildfly. One deployment (main.war) contains the main components of my UI. There exist also several other deployments (of typ .jar; they are EJBs; let’s say app1.jar, app2.jar,…) which act like apps. Each of this .jar has its own image (.png) that should be used as the image of a button. The main.war creates the buttons and needs the acces of the image files that can be found at app1.jar, app2.jar,…, e.g. image1.png at app1.jar and image2.png at app2.jar,…

The deployment of main.war can be found at
e.g. …\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143\main.war-b23e123f62eba416.

The deployments of app1.jar and app2.jar can be found at D:\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143.

Now I have a class at main.war that needs to call the images
D:\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143\app1.jar-a62b4712eef27341\app1.jar\image1.png
and
D:\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143\app2.jar-bf16351ac3271b36\app2.jar\image2.png.
It doesn’t work. I’ve tried things like that, but none of them worked:


StreamResource


String iconFilePath = “D:\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143\app1.jar-a62b4712eef27341\app1.jar\image1.png”;
StreamResource.StreamSource source = new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
return getClass().getResourceAsStream(iconFilePath);
}
};
Resource icon = new StreamResource(source, “image1.png”);
Button b = new Button(“Button”);
b.setIcon(icon);


ExternalResource


String iconFilePath = “D:\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143\app1.jar-a62b4712eef27341\app1.jar\image1.png”;


Resource icon = new ExternalResource(iconFilePath, “image/png”);
Button b = new Button(“Button”);
b.setIcon(icon);


ClassResource


Resource icon = new ClassResource(“/image1.png”);
Button b = new Button(“Button”);
b.setIcon(icon);


FileResource


String iconFilePath = “D:\wildfly\standalone\tmp\vfs\temp\tempa1532bfe1343d143\app1.jar-a62b4712eef27341\app1.jar\image1.png”;


Resource icon = new FileResource(new File(iconFilePath));
Button b = new Button(“Button”);
b.setIcon(icon);

What’s wrong? Has anybody an idea?

Thanks in advance.

I found a workaround!

Good that you found something that works! How did you solve it? :slight_smile:

When deployed main.war, app1.jar, app2.jar,… to the wildfly, the image files have to be copied to a specified folder and I can use the version with
new FileResource()
written above. Not the preferred solution, but it works :wink:

Thanks for sharing that.

-Olli