英文:
How do I install and forget java 9 modules (on Windows)?
问题
Java 9引入了模块,这是对一个不存在的问题的可怕修复。搜索Google关键词“如何安装Java模块”并没有带来有用的结果。
现在,在我屈服于诱惑之前,将整个JDK和JavaFX重新打包成一个单独的jar文件,并将其添加到类路径中(假设那仍然有效),是否有人可以帮我撤销这些白痴所做的事情?
我想要的是让任何的jar文件都可以通过“java -jar *.jar”来运行。无需--module-path,无需--add-modules。
第一部分似乎很简单,将所有jmod文件复制到JDK/jmods中应该会起作用,但在此之后,我需要一种方法来告诉Java运行时始终加载所有模块。
(不,我不想要学习如何“正确”使用模块,我想要一种安装它们然后忘记它们的方法。)
英文:
Java 9 introduced modules, which was a horrible fix for a non-existing problem. Searching google "How to install java modules" doesn't bring up anything useful.
Now, before I give in to the temptation and repackage the whole JDK and JavaFX into a single jar file, and add it to the classpath (assuming that still works), can anyone help me with undoing what these idiots did?
What I want is for any jar to run with "java -jar *.jar". Without --module-path, without --add-modules.
The first part seems easy, copying all jmods into JDK/jmods should work, but after that I need a way to tell the java runtime to always load all modules.
(And no, I don't want to learn how to "properly" use modules, I want a way to install them and forget about them.)
答案1
得分: 2
完全没有必要做你认为太多的任何事情。如果你不想要模块(就像我一样),那就不要使用它们。甚至可以运行非常大的JavaFX应用程序,而无需考虑模块。只需按照以下步骤操作。像往常一样将所有依赖项都放在类路径中(包括JavaFX的jar包)。
然后像这样为你的程序添加一个单独的启动器:
public class MyApp extends Application {
// <其余的JavaFX代码已删除>
}
class MyAppLauncher {
public static void main(String[] args) {
MyApp.main(args);
}
}
现在调用这个启动器,而不是你真正的主程序,就完成了。
英文:
There is absolutely no need to do anything of what you considered to too. If you don't want modules (like me) then just don't use them. You can run even very big JavaFX applications without even thinking about modules. Just do the following. Put all dependencies on your classpath as usual (also the JavaFX jars).
Then add a separate launcher to your program like this:
public class MyApp extends Application {
<rest of the JavaFX code deleted>
}
class MyAppLauncher {public static void main(String[] args) {MyApp.main(args);}}
Now call this launcher instead of your real main and you are done.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论