简体   繁体   English

如何在私有网络中部署 Java Web 服务

[英]How to Deploy a Java Web Service in a Private Network

I was able to create a JAVA Rest API Web Service using SpringBoot.我能够创建一个 JAVA Rest API ZC6E190B284633C3C48E39E5509Z ZC6E190B284633C3C48E39E55094 How do I deploy it so not only my localhost can access it but other computers in the private LAN as well.如何部署它,不仅我的本地主机可以访问它,而且私有 LAN 中的其他计算机也可以访问它。

I dont want to officialy publish it outside.我不想在外面正式发布。 Is Glassfish the tool for this? Glassfish 是这个工具吗?

I want to have an endpoint like我想要一个像

 https://privatewebservice.net/api/

in the private network that other people can use.在其他人可以使用的专用网络中。

Thanks.谢谢。

Deploy the rest on your tomcat server on port 80 and in other PCs in the private LANs update host file for privatewebservice.net to point to your PC's IP in the LAN将 rest 部署在 tomcat 服务器上的端口80和私有 LAN 中的其他 PC 上,更新 privatewebservice.net 的host文件,以指向privatewebservice.net中 PC 的 ZA12A3079E14CED46E69BA52B8A90

It needs to run an a servlet container(aka web server).它需要运行一个servlet 容器(又名 web 服务器)。 There are many;有许多; Jetty, Tomcat, Glassfish etc. That servlet container will start and host your application and make it available via it's port(s). Jetty、Tomcat、Glassfish 等。该 servlet 容器将启动并托管您的应用程序,并通过其端口使其可用。

You can run this process on any physical or virtual machine that is visible on your LAN.您可以在 LAN 上可见的任何物理机或虚拟机上运行此过程。 You could even use your own machine for this if it's visible to your LAN (barring firewall/network rules blocking the traffic).如果您的 LAN 可以看到它,您甚至可以使用您自己的机器(除非防火墙/网络规则阻止流量)。

To make it available to your LAN from your machine, find your machines internal LAN IP address (run ifconfig on Linux or ipconfig on Windows) and try accessing the app via that IP from your browser.要从您的机器上将其提供给您的 LAN,请找到您的机器内部 LAN IP 地址(在 Linux 上运行ifconfig或在 Windows 上运行ipconfig )并尝试通过该 ZA12A3079E14CED46E69BA52B8A90B 访问该应用程序。 If other machines on your LAN can see your machine, they should be able to access it too via that IP address (likely you will also have an internal DNS name for your machine which would be cleaner to use in case your IP address changes).如果 LAN 上的其他机器可以看到您的机器,他们也应该能够通过该 IP 地址访问它(您的机器可能还会有一个内部 DNS 名称,以防您的 ZA12A3079E14CED46E69BA5B211 地址发生变化时使用它会更清晰)。

Obviously that's only good for development and testing.显然,这只对开发和测试有好处。 Generally for internal hosted applications for your company you would have a machine running somewhere that you could deploy the app to to make it accessible by others on your LAN.通常,对于您公司的内部托管应用程序,您会在某个地方运行一台机器,您可以部署该应用程序以使其可供 LAN 上的其他人访问。

It's worth noting that Spring Boot by default comes with an embedded server/servlet container.值得注意的是,Spring Boot 默认带有一个嵌入式服务器/servlet 容器。 By default this is Tomcat, but can be changed to say Jetty, via configuration and changing default dependencies in your maven POM file or Gradle build file.默认情况下,这是 Tomcat,但可以通过配置和更改 maven POM 文件或 Gradle 构建文件中的默认依赖项来更改为 Jetty。 The default will be fine unless you have some specific reason to change it.除非您有特定的理由更改它,否则默认值会很好。

To use this embedded server, use one of either Maven or Gradle Spring Boot plugins which will provide a set of tasks that can be used to build an executable Java jar file for the application that will run the application on the embedded server, and the application within it. To use this embedded server, use one of either Maven or Gradle Spring Boot plugins which will provide a set of tasks that can be used to build an executable Java jar file for the application that will run the application on the embedded server, and the application在其中。 This can then be run with something like java -jar myapp.jar然后可以使用java -jar myapp.jar类的东西运行它

Technically speaking this would probably be the easiest way to deploy the application.从技术上讲,这可能是部署应用程序的最简单方法。 With the only major requirement on the machine you are deploying to being a compatible version of Java.对您要部署的机器的唯一主要要求是成为 Java 的兼容版本。 Although I'd recommend wrapping that app in a Docker image that already has Java on it and use Docker to run the docker image as a container. Although I'd recommend wrapping that app in a Docker image that already has Java on it and use Docker to run the docker image as a container. This means your applications' dependencies(including Java and it's specific version) are housed within the docker image/container and also means the machine that will run the app could host many different applications resource efficiently(RAM, CPU etc), with each managing their own dependencies.这意味着您的应用程序的依赖项(包括 Java 及其特定版本)位于 docker 映像/容器中,也意味着运行该应用程序的机器可以有效地托管许多不同的应用程序资源(RAM、CPU 等),每个应用程序资源都管理它们自己的依赖。 The machine hosting the app would then just need Docker installed on it, and doesn't get polluted with any other applications dependencies.托管应用程序的机器只需要在其上安装 Docker,并且不会受到任何其他应用程序依赖项的污染。

follow this step:请按照以下步骤操作:

1- generate a war file of your Spring-boot project API - see here how to do 1-生成您的 Spring-boot 项目 API 的战争文件 -看这里怎么做

2- deploy it on tomcat server see here how to do 2-将其部署在 tomcat 服务器上,请参见此处如何做

3- replace your localhost with your @adress ip (where the server is on and where the project is deployed) 3-用您的@adress ip替换您的localhost (服务器所在的位置和项目的部署位置)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM