[英]Gradle - Add JavaFX SDK to classpath
I am using gradle in Eclipse , and my gradle.build is pretty basic (adds java plugin, sets repos and not alot more) and I am building a JavaFX program. 我在Eclipse中使用gradle ,并且gradle.build非常基本(添加了Java插件,设置了repos而不是更多),并且正在构建JavaFX程序。 All my code compiles and run correctly with my build scripts with 0 errors.
我的所有代码都可以编译,并且可以使用错误为0的构建脚本正常运行。
I am just annoyed at the fact when I add the JavaFX SDK to my build path libraries, I can see my project has it listed. 当我将JavaFX SDK添加到构建路径库中时,我很生气,我可以看到我的项目中列出了它。 When I sync my project with Gradle, gradle removes this SDK from my classpath file.
当我将我的项目与Gradle同步时,gradle将从我的类路径文件中删除此SDK。
What do I need to add to my build script to stop this from happening and gradle to normally inject it into my .classpath as it does with anything else I add? 我需要向构建脚本中添加什么以阻止这种情况的发生,并像将其与添加的其他内容一样,将其正常注入到.classpath中?
Cheers, 干杯,
PS I'm really new to gradle and groovy and this is my first 'project' working with it. 附注:我真的对gradle和groovy并不陌生,这是我的第一个“项目”。 Apart from this one annoyance, it's been smooth going.
除了这一烦恼之外,一切都很顺利。
Solved this issue: completely forgot classpath is todo witth eclipse and not java/gradle. 解决了这个问题:完全忘记了classpath是用Eclipse而不是Java / gradle做的。
Adding: 添加:
apply plugin: 'eclipse'
eclipse {
classpath.containers 'org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER'
}
to my gradle.build file solved this issue. 我的gradle.build文件解决了这个问题。
I actually found a solution for this via https://groups.google.com/forum/#!topic/javafxports/Fn92C5ysC60 'android forum' while looking up how I could automate the building of eclipse. 我实际上是通过https://groups.google.com/forum/#!topic/javafxports/Fn92C5ysC60'android forum'找到了一个解决方案,同时查找了如何使Eclipse的构建自动化。
Cheers if anyone looked into this. 如果有人对此打气,那就加油打气。
As a side note, as I was confused about this first: A JavaFX project is no different from a Java project and you don't need to specify the fact you're using JavaFX to your ide to be able to execute JavaFX code. 附带说明一下,我对此很困惑:JavaFX项目与Java项目没有什么不同,您无需指定要使用JavaFX的事实就可以执行JavaFX代码。 So I was confused why my IDE had a 'Start a new JavaFX project' and 'Start a new Gradle Project' but no JavaFX/Gradle project.
所以我很困惑,为什么我的IDE有一个“开始一个新的JavaFX项目”和“开始一个新的Gradle项目”,却没有JavaFX / Gradle项目。
You don't 'need' a JavaFX plugin like my project originally had either. 您不需要像我的项目最初那样拥有的JavaFX插件。
To solve your problem, you need JavaFX-Gradle-plugin , it's a plugin that enable JavaFX support on Gradle project. 要解决您的问题,您需要JavaFX-Gradle-plugin ,它是一个在Gradle项目上启用JavaFX支持的插件。
This is the link of plugin: https://github.com/FibreFoX/javafx-gradle-plugin , where you can find all infos and example... 这是插件的链接: https : //github.com/FibreFoX/javafx-gradle-plugin ,您可以在其中找到所有信息和示例...
All of you need is to start a new Gradle project, then add to your file build.gradle this code: 您所需要做的就是开始一个新的Gradle项目,然后将其添加到文件build.gradle这段代码:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
}
repositories {
mavenLocal()
mavenCentral()
}
}
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
dependencies{
// put here your project dependencies
}
apply plugin: 'javafx-gradle-plugin'
// these values are the examples and defaults
// you won't need them all
// configure javafx-gradle-plugin
jfx {
// minimal requirement for jfxJar-task
mainClass = 'YOUR.MAIN.CLASS'
// minimal requirement for jfxNative-task
vendor = 'YOUR NAME OR COMPANY'
// some optional task
jfxAppOutputDir = 'build'
jfxMainAppJarName = 'YOUR APPLICATION NAME.jar'
manifestAttributes = [
"Specification-Version": 1.0,
"Implementation-Version": 1,
"Built-By": "YOUR NAME OR COMPANY",
]
// for a full list of available settings, look the class "JavaFXGradlePluginExtension" on plugin project
}
This is the only plugin that I've found for use JavaFX with Gradle. 这是我发现将JavaFX与Gradle结合使用的唯一插件。 I'm working with Eclipse on project with same problem, and I've solved it a few days ago.
我正在使用Eclipse处理具有相同问题的项目,而几天前已经解决了。
Hope this help, 希望有帮助,
BoGnY BoGnY
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.