Java - 运行 来自 RAM 的文件对象

Java - run File-Object from RAM

我正在从 Internet 下载一个文件(How to download and save a file from Internet using Java?) but I dont want the File to be created before it gets runned. So what I thought was : I download the file put it in a file new File("myJar.jar"); and now instead of doing Runtime.getRuntime().exec("java -jar myJar.jar"); <= (I would need to create the file...) I will unzip the jar and get the bytes of every class and put them into the Classloader to run the program. Is this a good way or what would you recommend? Java: How to load Class stored as byte[] into the JVM? <= 如果我每隔 class 从 jar 加载一次,这个 运行 程序会吗?

编辑: 应该这样做是为了让破解者很难获得文件。

编辑 2: 如果它不是一个 jar 而是一个 .exe,那怎么可能呢?当我将 jar 编译为本机代码时,这是必需的,然后它是一个 .exe,所以破解者无法从 jvm 中获取代码。

尝试使用 URLClassLoader that does the job for you. You can later find META-INF/manifest.mf with findResource(...) method, read it, figure out main class, find it 并调用其 main(...) 方法,执行与使用 java -jar ...

完全相同的操作