如何在javafxports-Application中使用外部Jars [英] How to use external Jars in javafxports-Application
问题描述
我用javafxports和gradle在netbeans中编写了一个javafx andoid应用程序。我将依赖项添加到gradel,但现在我不知道如何将jar添加到我的项目或在我的应用程序代码中使用它。 。 。
你知道我怎么能用它吗?我试着在www上搜索几个小时...
好的我试过了但是我没理解...
<我完全按照你所说的做了但netbeans仍然说:
包io.netty.bootstrap不存在
我创建了一个文件夹unter src / android /调用libs并在那里添加我的jar ...
这是我的依赖项:
dependencies {
编译fileTree(dir:'src / android / libs',包含:['* .jar'])
编译文件('src / android / libs / netty-all -4.0.29.Final.jar')
}
最终解决方案:
- 您必须添加:
编译'io.netty:netty-all :4.0.24.Final'
到build.gradle文件。 (netty JAR-Libary示例) - 我将Libary(netty)复制到主文件夹中名为libs的文件夹中,而不是sry等等。创建文件夹(如果不存在)
- 编写代码,您将看到,导入有效。
感谢JoséPereda的时间和最终解决方案!
根据编辑过的问题,这些是一些建议用于处理JavaFXPorts项目的依赖项。
依赖项和build.gradle文件
根据这个,默认依赖配置编译$ c $支持c>和
运行时
,jfxmobile插件为每个支持的平台添加额外配置,如 androidCompile
或 desktopRuntime
。
要访问第三方依赖项,应该添加一个给定的存储库:
存储库{
jcenter()
}
依赖项{
compile'groupId: artifactId:版本'
}
从 jcenter()
是'mavenCentral()`的超集,您可以使用表单中的任何maven依赖项of:
< dependency>
< groupId> org.glassfish< / groupId>
< artifactId> javax.json< / artifactId>
< version> 1.0.4< / version>
< / dependency>
as compile'groupId:artifactId:version'
。所以在这种情况下:
依赖项{
compile'org.glassfish:javax.json:1.0.4'
}
本地文件
使用文件
来访问本地罐子:
依赖{
编译文件('lib / my-jar.jar')
}
在项目内的 lib
文件夹中有 my-jar.jar
,但在外面 src
文件夹。
如果你想添加几个罐子:
依赖关系{
编译fileTree(dir:'lib',包括:['* .jar'])
}
NetBeans的Gluon插件
build.gradle $ c}中的任何更改后$ c>文件,需要重新加载项目,因此会考虑新的更改,并检索新的依赖项。
在项目视图下,右键单击项目根目录并选择重新加载项目
。
同时检查依赖项
文件夹,那些应该包含构建中包含的jar。
由于这些文件夹中有几个,你可以看到例如为Android编译
包括 android.jar
和 jfxdvk-8u60-b3.jar
。 主要
的编译应该包含为 compile
定义的所有jar。
样品
这些是的一些项目build.gradle
包含依赖项,因此它们是从JavaFXPorts开始的好方法。
- HelloPlatform 和其他样本。
- 2048FX
- SMSTracker
- HelloCharm
i write a javafx andoid application in netbeans with javafxports and gradle. I added the dependencies to gradel, but now i dont know how to add the jars to my project or to use it in my app-code. . .
Do you know how i can us it? I tried searching the www for hours ...
Ok i tried it but i dont get it ...
I did exactly what you said but netbeans still says: package io.netty.bootstrap does not exist
I created a folder unter src/android/ called libs and add my jar there ...
Here are my dependencies:
dependencies {
compile fileTree(dir: 'src/android/libs', include: ['*.jar'])
compile files('src/android/libs/netty-all-4.0.29.Final.jar')
}
FINAL SOLUTION:
- You have to add:
compile 'io.netty:netty-all:4.0.24.Final'
to the build.gradle file. (Example for netty JAR-Libary) - I copy the Libary (netty) to an Folder called "libs" in my main Folder not in sry and so on. Create the folder if not exist
- Write your code and you will see, import works.
Thank you to José Pereda for the time and the final solution!
Based on the edited question, these are a few suggestions for working with dependencies on a JavaFXPorts project.
Dependencies and build.gradle file
According to this, the default dependency configurations compile
and runtime
are supported, and the jfxmobile plugin adds extra configurations for each supported platform like androidCompile
or desktopRuntime
.
To access third party dependencies, from a given repository this should be added:
repositories {
jcenter()
}
dependencies {
compile 'groupId:artifactId:version'
}
Since jcenter()
is a superset of 'mavenCentral()`, you can use any maven dependency that was in the form of:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
as compile 'groupId:artifactId:version'
. So in this case:
dependencies {
compile 'org.glassfish:javax.json:1.0.4'
}
Local files
Accesing local jars can be done using files
:
dependencies {
compile files('lib/my-jar.jar')
}
having my-jar.jar
at a lib
folder inside your project, but outside the src
folder.
If you want to add several jars:
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
}
Gluon plugin for NetBeans
After any change in the build.gradle
file, it is necessary to reload the project, so the new changes are taken into account, and the new dependencies are retrieved.
Under the Projects view, right click on the Project root and select Reload Project
.
Check also the Dependencies
folders, those should contain the jars included in the build.
Since there are several of these folders, you can see for instance that Compile for android
includes android.jar
and jfxdvk-8u60-b3.jar
. Compile for main
should contain all the jars defined for compile
.
Samples
These are some projects where the build.gradle
contains dependencies, so they are a good way to start with JavaFXPorts.
- HelloPlatform and other samples.
- 2048FX
- SMSTracker
- HelloCharm
这篇关于如何在javafxports-Application中使用外部Jars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!