简体   繁体   English

从同一代码启动两个Java程序

[英]Launch two Java programs from the same code

I have a Java program which is divided into client and server code. 我有一个分为客户端代码和服务器代码的Java程序。 However, for standalone users, I want both the server software and client software to be launch with the click of one button. 但是,对于独立用户,我希望单击一个按钮即可启动服务器软件和客户端软件。 I have had success embedding the http server with the server software. 我已经成功将http服务器嵌入服务器软件。 What I need now is a way to launch the two programs (as two instances) from a single place which can send information to the programs that it has spawned. 我现在需要的是一种从单个位置启动两个程序(作为两个实例)的方法,该方法可以将信息发送到它产生的程序。 How can I achieve this? 我该如何实现?

PS I have used JavaFX for the client program so it is better if I have a way of launching JavaFX programs as well. PS:我已经将JavaFX用于客户端程序,因此,如果我也有启动JavaFX程序的方法,那就更好了。

Can always make a Java program that launches two Process obecjts after building the environment (classpath, correct java home etc taking in to account environment and OS). 始终可以制作一个在构建环境后启动两个Process对象的Java程序(考虑到环境和OS,类路径,正确的Java home等)。 There should be reusable code in java based installers but you would have to comb thru them for what you need. 在基于Java的安装程序中应该有可重用的代码,但是您必须根据需要来梳理它们。

A simple program could just expect certain sub folders to have the server and client programs (along with resources like images etc), build up 2 process objects (makes sense to start the server first, maybe first check if the port the server is to listen on is free, if not, is another instance of server already running etc) 一个简单的程序可能只希望某些子文件夹具有服务器和客户端程序(以及图像等资源),建立2个过程对象(有意义的是首先启动服务器,也许首先检查服务器是否要监听的端口) on是免费的,如果不是,则是服务器的另一个实例已经在运行,等等)

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

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