How to deploy and run Javaweb projects at development time that are separated from the front and back ends

Source: Internet
Author: User

In the development of large-scale Java EE project, the front-end separation of the framework has become the mainstream of the industry, the traditional single-machine deployment before and after the end of the same project less and fewer projects. The backend of this type of Javaweb project usually uses a microservices architecture, the backend is decomposed into a number of small projects, and then the Dubbo+zookeeper or Springcloud is used to build the microservices, the front end is a separate project, and the foreground request is invoked through the microservices. However, unlike traditional Web projects, how does this kind of front-end separation project be deployed and run in development?

When the current backend is detached, the backend project is bound to be loaded under Tomcat's WebApp directory, but how can the front-end resource yard be accessed? Here is an example of the Tomcat middleware, which explores how to deploy and run a project with a front-end separation when developing such a project, that is, how the backend project deploys after Tomcat to access static resources at runtime (not on-line deployment).

There are two main scenarios: 1. Use nginx locally to process these static resources. 2, unified static resources into a javaweb application, and the auto-generated war package the subsequent end of the project was dropped into Tomcat. Here is a detailed description

First, use Nginx to access static resources.

Install Nginx locally and modify the nginx.conf, modify the relevant configuration, change the resources of the Web Access port, and configure the following:

server {Listen80;server_name localhost;CharSet utf-8;#access_log Logs/host.access.log Main;Location/{Proxy_passHttp://tomcat_pool;Proxy_redirectOffProxy_set_header HOST$host;Proxy_set_header X-real-ip$remote _addr;Proxy_set_header x-forwarded-for$proxy _add_x_forwarded_for;Client_max_body_size10m;Client_body_buffer_size128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4K; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k;} location ~. *\. ( Html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|woff|woff2|ttf|eot|map) $ {root D:\ workspaces\esop-html; index index.html;}            

The Listen object changes to your local tomcat access port, and the root in the bottom location changes to the position of the static resource in your front-end project, so you can implement a project that deploys only the backend to access the front-end pages.

Second, convert the front-end project to a dynamic Web project, and then drop the project into Tomcat

This solution eliminates the local installation and configuration of Nginx, but also only for the development phase of the project deployment run and debug, really in the production environment usually the front-end project will be deployed on different servers.

    • If it is IntelliJ idea, after importing the front-end project, right-click on the project Add framework support-to Web application, this will convert the front-end project to a Javaweb project, Then put the static resources in the generated web directory.
    • In the case of Eclipse, you can create a new Javaweb project and then place the static resource in the Web or webcontent directory, or import the front-end project directly, then convert the project to a dynamic Web project through Project facts and tick the relevant configuration such as JS.

Then, when you run the project, add the back-end war package and the front-end war package to the deployment to run.

How to deploy and run Javaweb projects at development time that are separated from the front and back ends

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.