0

I'm doing the deploy to a local tomcat server from a spring boot rest project using maven with sub modules. Using the command mvn tomcat7: deploy, deploy occurred successfully, however when accessing the local server and trying to access the project I get a 404 error code.

My Architecture is:

/ radarveicular-application

  / service <- packaging war

  / api <- packaging war

  / dao <- packaging war

  pom.xml <- packaging pom in the parent

And the result of deploy was: enter image description here

In the libs folder are all submodules compressed in .jar file, as well as the dependencies of the project

I've written code in java for years, but I've never done any deploy before... Is it missing setting up something for the project to work? or was the deploy done wrong?

Bruno César
  • 81
  • 1
  • 13
  • 1
    Since it's a `Spring Boot` application, it already has an embedded Tomcat. You don't need to deploy to a web server explicitly . You can just start the application by invoking the following command from the parent directory, `mvn spring-boot:run` or `java -jar ` – Indra Basak Sep 09 '17 at 20:22
  • But, how it works in a production server? I've been using spring-boot for a while for develop local applications, but I am envolved in a project where the application needs tô be deployed in a existing tomcat 8 server, so I'am trying to do this local to learn before the implementation – Bruno César Sep 09 '17 at 20:33
  • see https://spring.io/blog/2014/03/07/deploying-spring-boot-applications#what-about-the-java-ee-application-server and https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/ – Oleg Sep 09 '17 at 20:41
  • @BrunoCésar Please check an existing Stack Overflow reponse [here](https://stackoverflow.com/questions/39873651/deploy-maven-project-in-tomcat8-in-eclipse) – Indra Basak Sep 09 '17 at 20:57
  • @ibasak I follow this steps and the deploy to tomcat was ok, but when I try to access the project from localhost I get a 404 error, as mentioned above. – Bruno César Sep 09 '17 at 21:17
  • @BrunoCésar 1. Make sure you are calling the correct port 2. Check Tomcat log files to see if there were any errors during deployment. – Indra Basak Sep 09 '17 at 21:25

1 Answers1

0

How about just running it as it already has a built-in webserver.

Run the following from your project root: mvn spring-boot:run

Source: https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html


You can also deploy as a war if you like: https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/

Feras Wilson
  • 380
  • 1
  • 3
  • 13
  • Thats how you run it on production. The way it is intented is to run as a micro-service. If you run it on an existing Tomcat you will defeat it's purpose. Do you still want to do that? Edit: You can execute it as a java application from the jar provided in the build dir after it has been built. – Feras Wilson Sep 09 '17 at 20:36
  • Absolutely not! It's fully capable running in a container and designed for both usages. – Oleg Sep 09 '17 at 20:42
  • I am a bit confusion on how this process works.. lets suppose that i have a local machine where I code all my stuff... After that what I have to do? Copy my code to production server and run mvn spring-boot:run? – Bruno César Sep 09 '17 at 20:46
  • Okay, suppose you are finished with your code, then you run: mvn package. This will give you a jar file inside the target directory. Move that jar to your production environment and run it there. This is a very simple explanation. In a more real life enterprise scenario, you usually have a jenkins server that does continues integration and continues deployment of your application which will save you the manual work of testing and transferring. – Feras Wilson Sep 09 '17 at 20:51
  • If i have a multi module application every module will have your own jar file? – Bruno César Sep 09 '17 at 21:00
  • Yes, and they will run at different ports / addresses. Every module should have some kind of interface, like REST. – Feras Wilson Sep 09 '17 at 21:02
  • @BrunoCésar No, if it's one Spring Boot application mvn package will create one jar that will contain everything(all your modules and dependencies), it has a normal main method and you can just copy it to anywhere you want and run it with java -jar thejar.jar. – Oleg Sep 09 '17 at 21:10
  • Each module should have it's own jar. If the modules is part of the same application then it is one jar. – Feras Wilson Sep 09 '17 at 21:13
  • @BrunoCésar I hope you got the answer you needed. – Feras Wilson Sep 09 '17 at 21:21
  • @Firre I am trying to do the way you said. Where i run mvn package, the application build a target folder in the modules folders with some aditional folders and two jar files: a snapshot .war and a snapshot-exec.war which one if this i move to my tomcat server? – Bruno César Sep 09 '17 at 21:35
  • For a "usual" Spring Boot application you would not deploy any file to a server, because Spring Boot provides an embedded one. You just use `jar` as your packaging an run the `.jar` file created by `mvn package` like you run any `.jar` file: by executing `java -jar `. – Florian Cramer Sep 09 '17 at 22:28
  • Can you provide your pom.xml? – Feras Wilson Sep 10 '17 at 00:53