从正在运行的 java accpilaction 中编译 javacode - 在没有安装 JDK 的系统上 [英] Compile javacode out of a running java accpilaction - on a system that hasn't JDK installed

查看:42
本文介绍了从正在运行的 java accpilaction 中编译 javacode - 在没有安装 JDK 的系统上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个基于客户端服务器的工具.由于IP地址不稳定,我的想法是让服务器应用程序使用正确的服务器IP编译客户端应用程序.

I'm currently writing on a tool that is client server based. Because of unstable IP-Adresses, my idea is to let the server-Application compile a client-application with the right IP of the server.

分步说明:

  1. 服务器应用程序启动.
  2. 用户查看其服务器计算机当前拥有的 IP(可以通过网络浏览器手动完成).
  3. 使用此 IP,他创建(编译)一个客户端,该客户端搜索与此 IP 的连接(一旦启动).
  4. 为了实现这一点,必须在设置 IP 后编译客户端.
  5. 客户端作为后台应用程序运行,没有任何 GUI 或控制台窗口.所以在客户端添加 IP 不是我搜索的内容.最大的新手应该能够运行客户端并完成他们的工作.

我认为我可以解压 javac(从 Java 应用程序中取出),然后将类写入文件(作为完整字符串),然后运行控制台命令,该命令使用 javac.exe 编译一个可运行的 jar文件.但这当然不是那么容易.我的问题是我不想将整个 JDK 文件夹放到服务器应用程序中,只是为了编译客户端.你们中有人知道我如何处理这个问题的正确方法吗?

I tought that I could just unpack javac (out of the Java-application), then write the class to a file (as complete string) and then run a console command, which uses the javac.exe to compile a runnable jar file. But of course it isn't that easy. My problem is that I don't want to put the whole JDK-Folder to the server-application, just to compile the client. Does anyone of you know a proper way how I could handle this?

重要的是,我必须与没有安装 JDK 的计算机打架,只有标准的 JRE 没有编译器(当然).

Important is, that I have to fight with computers, which haven't a JDK installed, just the standard JRE which hasn't a compiler on board (of course).

推荐答案

这绝对不是解决这个问题的好方法.有几种替代方法 会更简单:

That is definitely not a good way of going about this. There are a couple of alternative approaches which would be much simpler:

  1. 将服务器的 IP 地址或主机名作为参数传递给客户端应用程序(例如,通过命令行).这根本不需要对客户端进行任何更改,但需要您通过某种方式传递该参数.

  1. Pass the IP address or hostname of the server to the client application as a parameter (e.g, via the command line). This requires no changes to the client at all, but will require you to have some way of passing that parameter on.

如果您想变得非常聪明,您可以使客户端应用程序的文件名 包含 IP(例如,作为十六进制值:连接到 的客户端127.0.0.1 可能被称为 client-7f000001.jar).不过,您必须确保它没有被重命名.

If you want to get really clever, you could potentially make the filename of the client application contain the IP (e.g, as a hexadecimal value: a client that connected to 127.0.0.1 might be called client-7f000001.jar). You'd have to make sure it didn't get renamed, though.

在客户端 JAR 文件中嵌入一个包含服务器 IP 地址的文本文件.由于 JAR 只是一个 ZIP 存档,因此您不需要编译器来执行此操作.

Embed a text file containing the IP address of the server in the client JAR file. Since a JAR is just a ZIP archive, you don't need a compiler to do this.

这篇关于从正在运行的 java accpilaction 中编译 javacode - 在没有安装 JDK 的系统上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆