Embark Tomcat in Java Desktop application

0

After a long time, I was able to develop a Java application, with a graphical interface (swing), which simulates access to a given site and extracts data. The problem is that as it simulates a browser (with HtmlUnit), it needs Tomcat, and when I try to run the application on another machine (and I'll need to use it on both Windows and MAC machines), it does not run because of Tomcat radius.

The question is: How do I load Tomcat into a non-web application, so that the jar is "self-sufficient"? I use Netbeans, and, if information is important, the application uses Apache's Commons Codec libraries, Apache's POI and HtmlUnit.

    
asked by anonymous 19.11.2018 / 21:38

3 answers

0

I thought of 2 possible solutions:

1st Solution

A) In the tomcat project, you make the web application with all the requests you want. This project will grab the data you want and play it in a file or database.

B) Your Desktop project queries this database for this information.

-

2nd Solution

It would be you to make a request to the site by java itself. Through URLConnection. Take a look at this link: link

    
20.11.2018 / 00:45
0

In this case, I recommend you use the jetty shipped, you can start the server along with the start of the application. You just need to configure and understand some things, if you do not have difficulty with English, I recommend taking a look at this site that has an example of embedded server with jetty.

link

    
20.11.2018 / 11:16
0

I already faced this problem, my solution was to use framewok:
link

He uses jetty as a server. And he's pretty cool. In my case I generated a .jar of my project, to start in the client machine it was necessary only to run the command:

java -jar meuprojeto.jar

However, I realize that you already have an application all ready. You could generate an .exe (for windows) using link , the logic would be as follows:

  • You select the files that you have to copy to the client machine. You'll compile your project (.war) into a tomcat. At the time of your install, it will copy that tomcat to your client.

  • You can also enter the command that it should run when you finish copying the project to an installation folder. That is, it will start your tomcat.

  • Be careful with the port you want to start your tomcat on the machine of your client. Because it may be in use.

  • Another solution would also be to use the spring-boot, it already comes with an embedded tomcat. You would compile your project normally, in the end it generates a .jar and you would run the project as follows:

     java -jar seuprojeto.jar 
    
        
    20.11.2018 / 12:11