0

I have made a java program that fetches the bitcoin value every minute and prints it on a png image. I've added this program to a Tomcat server and I can see that it runs. mypimage.png gets updated. But while tomcat is running, I can't access the picture with localhost:8080/MyAppFolder/myimage.png. It just keeps loading forever or says connection refused.

The java program is a infinity loop, since I want the picture to keep being updated while Tomcat is running.

MyAppFolder contains the WEB-INF folder and myimage.png. WEB-INF contains classes folder which contains two folders myPackage and images. My package contains the class, and images contains the original image, which I add the bitcoin value to.

WEB-INF also contains a lib folder and web.xml which I'll paste the code to below.

I have tried to remove the WEB-INF folder from MyAppFolder and restart Tomcat. And then it works to access the picture through localhost:8080/MyAppFolder/myimage.png.

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> myDisplayName

<servlet>
    <servlet-name>myServlet</servlet-name>
    <servlet-class>myPackage.Btc</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

Flipize
  • 1
  • 1
  • I changed the class so it's not an infinity loop, and it works to access the image. So it seems like I cant access it while the program is running... Is there any way to get around this? – Flipize Jun 30 '19 at 13:56
  • welcome to stackoverflow. Your question contains just a description of plans, no meaningful code, no description of what goes wrong and no indicator what exactly your problem is. It's good to know you figured out the solution by yourself already, but as it stands here now, I wouldn't consider your "question" a question. Even the title points to a completely different direction than the body. Please see https://stackoverflow.com/help/how-to-ask – Olaf Kock Jun 30 '19 at 17:37

1 Answers1

0

I found the solution here: How to run a background task in a servlet based web application?

and here: Background Thread for a Tomcat servlet app

I was not suppose to use a servlet, but a servlet listener.

Flipize
  • 1
  • 1