java程序能转变为javafx,如何将intellij中的普通java项目转换为JavaFx项目

I am currently using a normal java project (gradle project) and want to convert this into a JavaFx project without having to reimport the existing sources into a new Javafx project. Is there any way to achieve this?

解决方案

There is nothing to convert.

I don't believe there is any difference in Idea between a "normal" Java project and a JavaFX project.

Sure, in Idea 12.x+ there is a wizard you can use to create a new JavaFX project. But I think that all it does is create a sample hello world application - after initial creation, the way the project works is not any different than any other Java project.

And this is how it should be, JavaFX is just Java. Oracle doesn't differentiate between JavaFX and Java in their distribution, and neither should IDEs in their project types.

I believe, in this case, even if I'm wrong, that I am right enough that it doesn't really matter if I'm wrong.

Update

So I was wrong enough that it matters :-)

Using Idea 13.1.4, if I create a new project using File | New Project | Java, there are the following resource settings (File | Settings | Compiler):

?*.properties;?*.xml;?*.gif;?*.png;?*.jpeg;?*.jpg;?*.html;?*.dtd;?*.tld;?*.ftl

That is, the resources for the project are just set to copy only specific file types. So you could modify it to get the additional file types required in some JavaFX projects by adding resource copying support for fxml and css; i.e, appending ;?*.fxml;?*.css.

The interesting part is that if you create a new project using File | New Project | JavaFX, there are the following resource settings:

!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj

Essentially, it's copying everything which not a source file, a kind of file blacklist set rather than a file whitelist set as is used by other project creation templates. Really weird... Anyway, the resource sets are user configurable, so you can modify them as you see fit and once you do so, you shouldn't have any issues (I believe, but I've been wrong before ;-)

Suggestion - Use 3rd party build tools in conjunction with your IDE

You might be better off basing your build off of a 3rd party tool such as Gradle or Maven. Idea works really well with both these external build tools (and others). The advantages of using a 3rd party tool is:

Projects with those tools follow a convention where resources are placed in a specific resource folder and everything in that folder is treated as a resource to be packaged in your build output. So there is less confusion there.

The resultant projects are more portable and easier to use by other developers who may not be using Idea.

The projects can be built easily by continuous integration build systems like Jenkins.

Both Gradle and Maven have JavaFX specific plugins which provide additional support for packaging JavaFX applications.

Of course, the disadvantage of using a 3rd party build tool, is the complexity (and many quirks) of learning them as sometimes they can be quite the beast. So I think it's a bit of a tradeoff - small, personal exploratory projects don't need them, larger projects or projects you intend to share with others benefit from using such tools.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值