将JavaFX 11 Maven项目导入Eclipse [英] Import JavaFX 11 Maven project to Eclipse

查看:469
本文介绍了将JavaFX 11 Maven项目导入Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以配置基于Maven的JavaFX项目,以便可以像在其他Java/Maven项目中一样在(原始)Eclipse中导入该项目并对其进行调试?

Is there any way to configure a Maven-based JavaFX project so that I can import the project in (vanilla) Eclipse and debug it like other Java/Maven projects?

我曾经使用Maven分发项目,通常,团队中的每个人(以及CI服务器)都可以依靠Maven进行打包,测试,运行等. 但是,为了进行调试,可以将项目导入Eclipse并通过主类(与Eclipse的maven插件相对)启动. 一个很好的例子是Spring-Boot.导入这样的项目后,我可以运行或调试主类.

I am used to distribute projects with Maven and typically, everyone in the team (as well as the CI server) can rely on Maven for packing, testing, running it etc. For debugging, however, the project can be imported to Eclipse and started via a main class (as opposed to Eclipse's maven plugin). A nice example is Spring-Boot. After importing such a project, I can just run or debug the main class.

但是对于JavaFX 11,这似乎可以编写一个pom.xml来配置所有必需的依赖项,但是当我将这样的项目导入Eclipse(作为Maven项目)时,它并没有将其配置到可以运行其主要课程.我可以运行"Debug as..Maven build ..",但不能通过主类运行.我知道它依赖于特定于平台的依赖关系,但是如果可以通过vie Maven启动它,应该可以在不配置Eclipse的情况下从Eclipse启动它,不是吗?

For JavaFX 11 however, this seems to work to write a pom.xml that configures all necessary dependencies, but when I import such a project to Eclipse (as Maven project), it does not configure it to the point where I could run its main class. I can run "Debug as..Maven build..", but not via the main class. I understand that it depends on platform-specific dependencies, but if it can be started vie Maven, it should be possible to start it from Eclipse without configuring Eclipse, can't it?

推荐答案

我一直在将Eclipse与Maven项目一起使用,其使用方式与您一直想将其与JFX11一起使用的方式完全相同.如果正确调整启动配置,它将正常工作.可以在这里找到详细信息: https://openjfx.io/openjfx-docs/

I've been using Eclipse with a Maven project in exactly the way you would like to use it all the time with JFX11. It works without problems if you tweak the launch configuration correctly. Details can be found here: https://openjfx.io/openjfx-docs/

到目前为止,最简单的方法是忽略模块系统,并确保所有库(也包括JFX库)都位于类路径而不是模块路径(如果没有该路径,则为默认路径)您项目中的任何module-info.java).然后使用主类将这样的单行代码添加到文件中.

By far the easiest way to get this running is to ignore the module system and make sure that all libraries (also the JFX libraries) end up on the classpath and not the module path (which is the default if you do not have any module-info.java in your project). Then add a single line of code like this to the file with you main class.

class MyJFX11AppLauncher {public static void main(String[] args) {MyJFX11App.main(args);}}

在Eclipse启动配置中,请确保通过此新启动器类启动您的应用程序.这就是在没有大量运行时选项的情况下运行JavaFX应用程序的窍门,否则您将需要所有这些运行时选项才能使所有这些正常运行. (请参阅上面的文档.)

In the Eclipse launch configuration make sure to launch your app via this new launcher class. That does the trick to run the JavaFX app without a whole flood of runtime options which you would need otherwise to get all this working. (See docs above.)

警告!这不是启动JavaFX应用程序的官方方法,但是它对我有用,而且我从未注意到它有任何问题.使用后果自负!

WARNING! This is not the official way to launch a JavaFX app but it works for me and I have never noticed any problem with it. Use at your own risk!

这篇关于将JavaFX 11 Maven项目导入Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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