After a day of googling, I'm still lost.
I've created a Spark web-application that runs on the embedded Jetty server, but I want to run my web-application on a Tomcat server.
I'm using Maven to build my web-application and can't find any good resources on using Spark on Tomcat with Maven.
How can I create a Maven project with Spark and run it on a Tomcat server?
You'll need to implement EmbeddedServer interface in order to do it. Currently, it only supports Jetty by default. So, fork it and submit a PR to the author.
Related
I have an application that is currently built on Spring Boot 1.5.9 and I am trying to update it to the latest Spring Boot 2 version.
The application uses spring-security, spring-security-taglibs, spring-boot-starter-data-jpa, spring-session-jdbc, jstl (jsp pages) and connects to two databases, I also use profiles to configure the application differently in development and production environments.
I was successfully able to upgrade my development application. I only needed to modify my pom.xml and a few java files.
During development I usually use the integrated Tomcat server. i.e. The one you get when you run mvn spring-boot:run
As a sanity test I also installed Tomcat 9.0.43 (this is the same build that is used in my production environment). The Spring Boot 2 version of the application works perfectly fine using this method.
However, all my problems started when I tried to deploy my application into the production environment.
When restarting the Tomcat server, I don't see any indication that it even detects the Spring Boot 2 application. In Spring Boot 1, I would usually get the Spring logo and a bunch of startup messages. Visiting the website in a browser shows The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
The Spring Boot application does not generate any log files and Tomcat's log files merely indicate the application was deployed successfully.
What could be causing this issue.
Both my development system and the production server have JRE and JDK 8 installed (although, different minor versions)
Both systems are running the same version of Tomcat.
Both systems run on Windows. The server runs on Windows server 2013 and the development environment is on Windows 10.
I use Visual Studio Code for development and debugging
Update 1
The spring boot 2 version of my application is using version 2.5.1
Here are a few things that I have done:
I have made sure that the application extends SpringBootServletInitializer
I can't put my local Tomcat installation in the production server (at least, not without a lot of issues), but I've copied the server's Tomcat installation onto my development machine and verified that the application DOES start correctly.
The only property in my POM is <java.version>8</java.version>
While both environment have JRE and JDK 8, they may have different minor versions
Update 2
I created a brand new Spring Boot 2.5.9 application (using Spring Initializr and no dependencies) and tried to run this in a Tomcat 8.5.20 instance on the server. I also created an index.html to display a simple Hello World!!! if the application starts correctly
The application works fine on my development system (using both integrated Tomcat and separate Tomcat installation)
In production, the Spring Boot application did not start (i.e. I got a 404)
It did not appear to generate any logs or errors.
I have a web app built with Java, Spring MVC, and JDBC. The result is a WAR file.
To run it, the user has to install Java 8 JDK and Tomcat, and deploy the WAR file to the Tomcat server.
It would be great if they could just download the one file run it as a standalone application.
That is, run "the WAR file" and just browse to http://localhost:8080/myapp
Also, on Windows it would be great it was setup as a Server (like Tomcat is when installed with the installer).
Is there any way to do this? Maybe with Spring Boot or something new like that?
Yep, Spring boot is the way to go.
It allows you to build an executable Jar with all dependencies and a Tomcat (by default, can be changed) embedded.
But users will still need to download a JRE to execute the Jar, and a database if it's required, but you can use en embedded database like H2, HSQLDB..., depends what is your needs.
Yes . you can use spring boot to achieve your results. Kindly refer the below link for sample code
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/
You can use embedded jetty server using maven but that would require you to setup few things your app and may have align your existing app, please check this article for more information.
Jetty is similar to tomcat server in terms of running spring application, there are not much difference in terms of development. Tomcat is just more famous.
Other option as others said, is to migrate your app to spring boot which would be easy if you already have app written in spring (But that depends how much code you have and how much time you have)
After some radical changes to our schema and reading some posts on why you should avoid in memory databases.
We have decided to use MySQL locally for testing and developing. Using a MySQL docker container with a volume for persistence.
This is fairly straightforward however the issues we are having are the following:
Requires the container to be executed separate from the spring boot application (a manual task docker run
Same goes for stopping the container, its a independant process
My question is essentially, is it possible to have spring boot (when using a dev config profile) to manage this docker container.
i.e. I start development work in IntelliJ and run the service, the service checks if the container is running, if not starts it up.
If this idea is bad, then please let me know.
For testing its not issue, because we are using a maven docker plugin to create the container during the maven lifecycle.
Its more for devs working locally, and getting the service running locally with ease.
Any suggestions welcomed!
Bonus for Intellij setup!
I have created Spring boot application and Angular project (Angular 1) separately. In my local i am using npm to server the client app and it calls my back end app services. I am using Embedded tomcat in spring boot application.
Now i want to host my application in server. How do i do that?
Can i have embedded tomcat and build as jar or should i have to install standalone tomcat in the server and deploy my application as war?
How to configure my client code for example, in godaddy i have given ip xx.xx.xx.xx to www.xyz.com. The ip address is my production cloud server. How to redirect to angular application and that application calls server exposed apis.
I cannot have single application that has client code. I should do with two different application only. Please help me deploying this in best way. If embedded tomcat doesnt help then i can install standalone tomcat in server and and build my app as war and deploy it.
The current best practice would be to embed the servlet container (Tomcat, Jetty, other) into the artifact and build a fat JAR. The main advantage is a simplified deployment process: it's enough to push the far JAR into environment and execute it. Unlike the usual servlet container with WAR deployment model the embedded approach doesn't have to deal with additional configuration layers e.g. thread pools or data sources shared between different WARs.
One example of how to build a far JAR with embedded servlet container is spring-boot-starter-web dependency with spring-boot-maven-plugin:repackage goal. In this setup to build a fat JAR it's enough to run mvn clean package repackage.
If you are developing locally your web client code most likely will face issues with the same-origin policy. You most likely will need a CORS filter, however it's provided by Tomcat.
I have a java application which I was running using tomcat server. Now I need to run the same application in jboss server.I am new to jboss, I tried deploying war file in jboss but not able to do so.
I don't know what changes needs to be done for application to run on jboss.
Any one please guide me.
Thank you.
An obvious answer would be Read The Friendly Manual.
You can configure JBoss to autodeploy files in the standalone/deployed/ directory for example, you can also use the maven-jboss7 plugin to handle deployment from maven.
I'm sure the jboss community forums have plenty of examples.