[英]Create JavaFX self-contained application (with custom JDK) in Eclipse
正如標題所示,我想創建一個自包含的JavaFX應用程序,使用其他JDK / JRE而不是系統默認值。 Netbeans能夠做到這一點,但是,我還不知道如何在Eclipse中這樣做。
通過使用e(fx)clipse ,您可以生成構建文件( build.fxbuild
)。 使用Netbeans,需要將以下內容添加到build.xml
以在jar中包含自定義JDK(這只是Oracle的示例):
<target name="-post-jfx-deploy">
<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
nativeBundles="all"
outdir="${basedir}/${dist.dir}" outfile="${application.title}">
<fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
<fx:resources>
<fx:fileset dir="${basedir}/${dist.dir}" includes="BrickBreaker.jar"/>
</fx:resources>
<fx:info title="${application.title}" vendor="${application.vendor}"/>
</fx:deploy>
</target>
那么,這在Eclipse中是否可行? 如果是這樣,我如何將JDK與jar捆綁在一起?
任何幫助是極大的贊賞!
編輯:從控制台添加構建輸出
我正在使用YOSMite的Mac OSX 10.10.1。
Buildfile: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build.xml
setup-staging-area:
[delete] Deleting directory /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/externalLibs
[delete] Deleting directory /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/project
[delete] Deleting directory /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/projectRefs
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/externalLibs
[copy] Copying 1 file to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/externalLibs
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/project
[copy] Copying 4 files to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/project
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/projectRefs
do-compile:
[delete] Deleting directory /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/src
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/libs
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/classes
[copy] Copying 1 file to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/libs
[copy] Copying 4 files to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/src
[javac] Compiling 1 source file to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/classes
[copy] Copying 3 files to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/classes
init-fx-tasks:
do-deploy:
[copy] Copying 1 file to /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/dist/libs
[mkdir] Created dir: /Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/build/build/classes/META-INF
No base JDK. Package will use system JRE.
Bundler Mac Application Image skipped because of a configuration problem: Main application jar is missing.
Advice to fix: Make sure to use fx:jar task to create main application jar.
Bundler DMG Installer skipped because of a configuration problem: Main application jar is missing.
Advice to fix: Make sure to use fx:jar task to create main application jar.
Bundler PKG Installer skipped because of a configuration problem: Main application jar is missing.
Advice to fix: Make sure to use fx:jar task to create main application jar.
Bundler Mac App Store Ready Bundler skipped because of a configuration problem: Main application jar is missing.
Advice to fix: Make sure to use fx:jar task to create main application jar.
BUILD SUCCESSFUL
Total time: 2 seconds
編輯:添加生成的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="OctoCash Updater" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
<target name="setup-staging-area">
<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />
<mkdir dir="externalLibs" />
<copy todir="externalLibs">
<fileset dir="/Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater/lib">
<filename name="gson-2.3.1.jar"/>
</fileset>
</copy>
<mkdir dir="project" />
<copy todir="project">
<fileset dir="/Users/RobinTrietsch/EclipseProjects/octocash-updater/OctoCash Updater">
<include name="src/**" />
</fileset>
</copy>
<mkdir dir="projectRefs" />
</target>
<target name='do-compile'>
<delete dir="build" />
<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />
<!-- Copy project-libs references -->
<copy todir="build/libs">
<fileset dir="externalLibs">
<include name="gson-2.3.1.jar"/>
</fileset>
</copy>
<!-- Copy project references -->
<!-- Copy project sources itself -->
<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*"/>
</fileset>
</copy>
<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="UTF-8">
<classpath>
<fileset dir="build/libs">
<include name="*"/>
</fileset>
</classpath>
</javac>
<!-- Copy over none Java-Files -->
<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
<delete file="dist"/>
<delete file="deploy" />
<mkdir dir="dist" />
<mkdir dir="dist/libs" />
<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="OctoCash Updater.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
</fx:resources>
<fx:application id="fxApplication"
name="OctoCash"
mainClass="octocash.updater.Main"
toolkit="fx"
/>
<mkdir dir="build/classes/META-INF" />
<fx:jar destfile="dist/OctoCash Updater.jar">
<fx:application refid="fxApplication"/>
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes"/>
<manifest>
<attribute name="Implementation-Vendor" value="Barotech"/>
<attribute name="Implementation-Title" value="OctoCash"/>
<attribute name="Implementation-Version" value="1.0"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<mkdir dir="deploy" />
<!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
<fx:deploy
embedJNLP="false"
extension="false"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="OctoCash Updater" nativeBundles="all"
updatemode="background" >
<fx:info title="OctoCash Updater" vendor="Barotech"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
</fx:deploy>
</target>
這是一個老問題,但我遇到了這個問題。 我很難找到解決方案。 通過閱讀很多不同的東西,我設法找到了解決方案。 我使用Netbeans但它應該適用於Eclipse。
在Netbeans中,我瀏覽了項目中的文件,直到找到名為project.properties的文件。 然后我打開文件,然后轉到以dist.jar =開頭的行。 接下來,我重命名jar文件,使其與我的項目主文件具有完全相同的名稱。
在我的情況下,我的主要名稱是helloworld,我的dist.jar是名稱hello world.jar我將其重命名為helloworld.jar並保存了文件。 然后我重建了項目並重新創建了本機安裝程序。 之后它運作良好。
你選擇什么作為包裝格式? 如果選擇“全部”,它將生成一個包含JRE的自包含安裝程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.