5

I am trying to build a ReactJS application which i would like to host on a tomcat server. I already used the command npm run build and the build is ready.. Where do i copy these files in my tomcat server? DO i need to create another application and deploy it on the server which invokes the React Application?

Manjot Singh
  • 51
  • 1
  • 3
  • 1
    This post might be helpful, https://stackoverflow.com/questions/40030580/how-to-run-a-react-app-on-tomcat – KungWaz Jan 21 '19 at 06:57
  • 1
    Also, this post https://medium.com/@mukundmadhav/build-and-deploy-react-app-with-spring-boot-and-mysql-6f888eb0c600#d8c5 – Victor Jul 23 '20 at 11:36

1 Answers1

1

Follow below steps:

  1. Goto 'webapp' folder in tomcat and create a folder(mostly your project name)
  2. Copy the files from your ReactJs build folder to the folder created in tomcat(note: your build folder should have index.html)
  3. Launch the url http : //localhost:< port > /< folder-name> in browser. By default port will be 8080

Instead if you have WAR file, you can go to http://localhost: < port > /manager/html and deploy it.

Rakesh Makluri
  • 647
  • 4
  • 10
  • 1
    I was facing similar requirements. I copied the build folder into webapps. In webapps now I have a folder named build and the contents of build folder inside that. But still I am unable to launch my application via tomcat – Geo Thomas May 27 '20 at 13:54
  • 2
    did you try this http : //localhost:< port >/build ? – Rakesh Makluri May 27 '20 at 16:59
  • 2
    I applied this steps but when i launch url i am getting 404 not found error – mertaksu Jul 13 '20 at 18:58
  • I am trying this solution and my react app searching for files in static folder in tomcat's root folder. when I add homepage in package.json file get searching get routed to folder. but still app is not working – Ashiq Apr 20 '21 at 06:45
  • @mertaksu for 404 this helps: https://stackoverflow.com/questions/41246261/react-routing-is-able-to-handle-different-url-path-but-tomcat-returns-404-not-av/41249464#41249464 – mostafa.S Oct 09 '21 at 11:44