How to deploy ReactJs app in Apache Tomcat Server
This is a guide to deploy a ReactJs application in a tomcat container, Deploy react JS in tomcat or any servlet container is little bit tricky. Here we will create a React application from scratch and deploy the app to apache tomcat server.
Create a ReactJS application
Prerequisites — You’ll need to have Node >= 8.10 and npm >= 5.6 on your machine
If you are newbie to ReactJS follow the below steps to create a HelloWorld application
npx create-react-app my-app
cd my-app
npm install
npm start
After starting the application, open a browser and hit the below URL . Your application will be rendered
Follow the link below to learn more about ReactJS — https://reactjs.org/docs/create-a-new-react-app.html
Magic happens here
Now let us make the config changes to deploy this application to Apache tomcat server
Open the package.json file in the project root, and add the below entry in the file and save.
“homepage”:”HelloWorld”
npm run build
build folder
Deploy to Apache Tomcat Server
Download a Tomcat server from the below link, if you have one already downloaded we can use that
Copy the build folder to Tomcat webapps folder, rename the folder to HelloWorld
Start the apache tomcat server, by default Tomcat server will be listening to 8080 port
After starting the application, open a browser and hit the below URL . Your application will be rendered
http://localhost:8080/HelloWorld
If you like the article give us a cheer !! Happy coding !