在用户下载程序之前在服务器上编译 Java 程序
我进行了快速搜索,但找不到有关此主题的任何内容。我什至不确定这是否可能,但我很好奇。
是否可以在用户下载程序之前在服务器上编译 Java 程序?我能想到的应用程序是在用户下载程序之前动态修改程序的源代码。这在程序根据用户输入或网站上的设置进行修改的设置中可能会很有帮助,并且这些更改被硬融入到程序中,因此他们下载的是定制且完全可移植的独立程序。我想到的另一个应用程序是,如果每个用户要在程序中使用不同的功能组合,那么它仅使用他们动态需要/想要的功能集进行编译。
我有一些可以测试的程序想法,但这主要是我的学术想法和好奇心。
长话短说,有谁知道有什么技术可以让这样的系统发挥作用吗?
I did a quick search and could not find anything on this topic. I am not even sure if this is possible, but I am curious.
Is it possible to compile a Java program on a server right before a user downloads the program. The application that I can think of for this would be to modify a program's source code on the fly before a user downloads it. This could be helpful in a setup where the program is modified based on user input or settings on a website and those changes are hard baked into the program so what they download is a stand alone program that is customized and fully portable. The other application I thought of would be if each user were to use a different feature combination in a program so it is compiled only with the feature set they need/want on the fly.
I have a few programs ideas that I could test this out with, but this is mostly an academic thought and curiosity of mine.
So long story short, does anyone know of any technologies that could make a system like this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,这是可能的。
只需让下载链接指向某个脚本,该脚本会编译/打包源代码并发送回结果。这可以用 PHP 等语言来实现,只需几行代码。它与验证码非常相似:即时生成唯一数据,通过 URL 检索。
我自己也考虑过这个想法用于协议混淆目的和“软件注册密钥算法”生成。
不过,我建议您将想要重新编译为单独的类/类集的部分分解出来,仅编译这些部分,并根据请求将其与(已编译的)程序的其余部分打包。
Sure, it's possible.
Just let the download link point to some script, that compiles / packages the source and sends back the result. This can be implemented in, for instance PHP, in just a few lines of code. It's quite similar to captchas: On-the-fly generated unique data, retrieved through a URL.
I myself have thought about this idea for protocol obfuscation purposes and for "software registration key algorithm" generation.
I would however recommend you to factor out the parts which you want to be recompiled into a separate class / set of classes, compile only these, and package it with the rest of the (already compiled) program upon request.
我已经使用 Compile API(Java 6 附带)编写了一个库来编译内存中的代码,但我建议您不需要预先生成代码,因为您可以使用生成的代码执行任何操作,而您可以使用动态代码执行此操作。可能会有轻微的性能优势,但我建议您尝试使用动态代码(即带有循环、if 语句和反射的代码)执行您需要的操作,以执行生成的代码首先要做的事情,因为这要简单得多,并且可能会执行以下操作你想要的。
即使您必须生成代码,首先以非生成形式编写代码也是有用的,这样您就可以清楚需要代码做什么。
I have written a library using the Compile API (comes with Java 6) to compile code in ememory but I would suggest you don't need to pre-generate code as anything you can do with generated code you can do with dynamic code. There can be a slight performance advantage, but I suggest you try doing what you need with dynamic code (i.e. code with loops, if statements and reflection) to do what your generated code would do first as this is alot simpler and likely to do what you want.
Even if you must have generated code, it is useful to write the code in a non-generated form first so you are clear as to what you need the code to do.