如何安装并忽略 Java 9 模块(在 Windows 上)?

huangapple go评论88阅读模式
英文:

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 {
   &lt;rest of the JavaFX code deleted&gt;
}

class MyAppLauncher {public static void main(String[] args) {MyApp.main(args);}}

Now call this launcher instead of your real main and you are done.

huangapple
  • 本文由 发表于 2020年4月5日 02:43:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/61033077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定