如何注册和部署JavaFX应用程序到一个单一的.JAR? [英] How can I sign and deploy a JavaFX application into a single .JAR?

查看:705
本文介绍了如何注册和部署JavaFX应用程序到一个单一的.JAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还在学习的JavaFX的来龙去脉。一个主要的区别是,在dist文件夹中(除了库),我觉得除了.jar文件,HTML文件和JNLP文件,既不也不其中没有任何用处,我(这将是一个桌面应用程序)。

I'm still learning the ins and outs of JavaFX. One major difference is that in the dist folder (in addition to the library) I find besides the .jar file, an HTML file and a JNLP file, neither nor of which is any use to me (this will be a desktop application).

我发现下面的(属性,因为敏感/不相关的信息省略):

I found the following (Properties omitted because of sensitive/irrelevant information):

<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>

<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
    <zipgroupfileset dir="dist" includes="*.jar"/>
    <zipgroupfileset dir="dist/lib" includes="*.jar"/>

    <manifest>
        <attribute name="Main-Class" value="${main.class}"/>
    </manifest>
</jar>

<zip destfile="${store.jar}">
    <zipfileset src="${store.dir}/temp_final.jar"
    excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
    <delete file="${store.dir}/temp_final.jar"/>

    <delete     dir = "${build.output.dir}"/>
    <mkdir      dir = "${build.output.dir}"/>

    <signjar
                jar = "${store.jar}"
          signedjar = "${build.output.dir}/${FileName}"
              alias = "${comodo.key.alias}"
          storepass = "${comodo.key.storepass}"
           keystore = "${comodo.key.store}"
          storetype = "PKCS12"
            keypass = "${comodo.key.pass}"
             tsaurl = "${timestamp.url}"/> 

这是为了建立无论是可执行的主JAR和所有相关的库成可以从任何位置运行单个.JAR,然后采取并签署该JAR,并将其移动到签名目录中。

This was intended to build both the "executable" MAIN JAR and all dependent libraries into a single .JAR that could be run from any location, and then take and sign that JAR and move it into a "signed" directory.

这对于任何JAR库或Swing GUI的应用程序JAR工作正常,但是当我试图用JavaFX应用程序它borked同样的事情:

This works fine for any JAR library or Swing GUI application JAR, but when I tried the same thing with a JavaFX application it borked:

Error: Could not find or load main class com.javafx.main.Main

我不完全惊讶地发现它不能正常工作,但它是一个有点问题。我做了有可能部署一个自足的应用程序的一些研究,但将不符合我们的需要。我的雇主购买一些牺牲一个科摩多证书,我很快就撞上了墙中出现,因为苹果的恶作剧了(除非我在这个presumption误),你必须加入他们的开发者俱乐部的低成本低每年$ 100(不会发生)。我真的不做苹果平台开发专。我做Java开发。无论如何,如果我是正确的,这将不是我们的工作,因此适用于Windows,Linux和Mac一个自包含部署了(同样,如果我是正确的)。

I'm not entirely surprised to find it NOT work, but it is a bit of a problem. I did some research on possibly deploying a "self-contained" application but that will not suit our needs. My employer procured at some expense a Comodo certificate, and I quickly ran into a wall in which it appears that because of Apple shenanigans (unless I am mistaken in this presumption) you have to join their developer club for the low low cost of $100 a year (not happening). I don't really do development for the apple platform SPECIFICALLY. I do Java development. Anyway, if I am correct that will not work for us so a self-contained deployment for Windows, Linux and Mac is out (again, if I am correct).

我希望这是简单的东西。

I'm hoping that this is something simple.

那么,如何申请我为编制包含所有依赖库到code-签名的JAR到JavaFX应用程序的JAR创建Ant脚本?

So how do I apply the ANT script I created for compiling a JAR containing all dependent LIBs into a code-signed JAR to a JavaFX application?

编辑1:好了,所以肯定是说话太快。不是很接近的答案。我试着FRANKENSTEIN我所知道的有关编译和定期签署JAR文件,使所有的库都包含和符号是成功的成什么样我已经能够挑选出的手动。我已经是一个大杂烩和失败。我得到除主.jar文件中的所有内容.jar文件。反正这是Ant脚本code:

EDIT 1: Okay so definitely spoke too soon. Not very close to an answer. I've tried to frankenstein what I know about compiling and signing regular JAR files so that all libs are included and that the sign is successful into what I've been able to pick out of the manual. What I have is a hodgepodge and a failure. I get a .JAR file with everything in it except for the main .JAR file. Anyway this is the ANT script code:

属性:

<property  name = "name"
          value = "APPNAME"/>

<property  name = "file"
          value = "APPJAR"/>

<property  name = "MC" 
          value = "MAINPACKAGE.MAINCLASS" />

<property  name = "released.dir"
          value = "released"/>

<property  name = "compiled.dir"
          value = "${released.dir}/compiled"/>

<property  name = "stored.dir"
          value = "${released.dir}/stored"/>

<property  name = "signed.dir"
          value = "${released.dir}/signed"/>

其他的一切:

<delete dir = "${released.dir}"/>
        <mkdir dir = "${compiled.dir}"/>

        <fx:jar destfile = "dist/compiled.jar">
            <fx:platform javafx = "8.0+" j2se = "8.0"/>
            <fx:application      name = "${name}"
                            mainClass = "${MC}"/>

            <fileset dir = "build/classes"/>

            <fx:resources>
                <fx:fileset dir = "dist" includes = "lib/*.jar"/>
            </fx:resources>
        </fx:jar>

        <fx:signjar keystore = "${comodo.key.store}"
                       alias = "${comodo.key.alias}"
                   storetype = "PKCS12"
                     keypass = "${comodo.key.pass}"
                   storepass = "${comodo.key.storepass}"
                         jar = "dist/compiled.jar"
                     destdir = "${compiled.dir}"/>

        <mkdir dir = "${stored.dir}"/>

        <jar       destFile = "${stored.dir}/temp_final.jar"
            filesetmanifest = "skip" >
            <zipgroupfileset      dir = "${compiled.dir}"
                             includes = "compiled.jar"/>

            <zipgroupfileset      dir = "dist/lib"
                             includes = "*.jar"/>

            <manifest>
                <attribute name = "Main-Class"
                          value = "${main.class}"/>
            </manifest>
        </jar>

        <zip destfile = "${stored.dir}/${file}">
            <zipfileset src = "${stored.dir}/temp_final.jar"
                   excludes = "META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
        </zip>

        <delete file="${stored.dir}/temp_final.jar"/>

        <mkdir dir = "${signed.dir}"/>

        <signjar
            keystore = "${comodo.key.store}"
               alias = "${comodo.key.alias}"
           storetype = "PKCS12"
              tsaurl = "${timestamp.url}"
             keypass = "${comodo.key.pass}"
           storepass = "${comodo.key.storepass}"
                 jar = "${stored.dir}/${file}"
             destdir = "${signed.dir}"/>

这就是我要显示我的时间。如果任何人都可以从收集这个东西,可以让我在正确的轨道上(如果我还差得远,我不觉得我),这将是超真棒。

And that's what I have to show for my time. If anyone can glean something from this that may put me on the right track (if I am even close, which I don't feel like I am), that would be super awesome.

推荐答案

扑我的头骨和其中的内容为某事很难认出连贯的思想我已经成功地合成了完成我已经设置了任务的脚本浆后去完成。这其中大部分是来自其他国家的人民捐款和咨询文档。其他主要的贡献是发现这里(线程上的最后一个评论,它链接到另外一个SO回答,但有这么回答是没有多大帮助我)。要感谢我从中能提取液的部分的一切。我希望这是其他人谁需要/想完成这个任务有帮助的。

After bashing my skull and the contents therein into a slurry of something hardly recognizable as coherent thought I have managed to compose a script that accomplishes the task I have set out to accomplish. Most of this is taken from other peoples contributions and from consulting the docs. The other major contribution is found here (The last comment on the thread, it links to another SO answer, but that SO answer wasn't much help to me). Thanks go to everything from which I was able to extract the parts of the solution. I hope this is helpful for everyone else who needs/wants to accomplish this task.

总之:首先第一件事情:属性:

Anyway: First things first: Properties:

<property name = "JFXProject.name"
         value = "PROJECT"/> <!-- Put your own project name here -->
<property name = "JFXMainClass"
         value = "MAINPACKAGE.MAINCLASS"/> <!--Put your own main class here -->
    <!-- don't edit below this line -->
<property name = "JFX.src.dir"
         value = "src"/>
<property name = "JFX.lib.dir"
         value = "dist/lib"/>
<property name = "JFX.build.dir"
         value = "release/JFXBuild"/>
<property name = "JFX.sign.dir"
         value = "release/JFXSign"/>
<property name = "store.dir"
         value = "release/store"/>
<property name = "sign.dir"
         value = "release/sign"/>
<property name = "comodo.key.store"
         value = "PATH-TO-YOUR-CERTIFICATE" /> <!-- You can name this what you like, but you want to make sure the value points to your certificate or JKS file -->

<property name = "comodo.key.storepass"
         value = "PASSWORD"/> <!-- Above applies here. Make sure it's the right password -->

<property name = "comodo.key.alias"
         value = "ALIAS"/> <!-- Make sure it's your right alias. You can find out how to find that information from [here][3] -->

<property name = "comodo.key.pass"
         value = "PASSWORD"/> <!-- In my own experience this was the same as the storepass but it may be different for you -->

<property name = "timestamp.url"
         value = "TIMESTAMPURL"/> <!-- This will vary for you depending on your certificate. -->

您可以更改属性名称的东西,如果你想要更多的对你有意义,但要确保它们在整个脚本是一致的。

You can change the property names to something more meaningful to you if you want but make sure that they are consistent throughout the script.

接下来,我们要清理掉最后的构建:

Next, we want to clean out the last build:

<target name = "JFXClean">
    <echo>Cleaning ${JFX.build.dir}...</echo>
    <delete dir = "${JFX.build.dir}"/>
    <delete dir = "${JFX.sign.dir}"/>
    <delete dir = "${store.dir}"/>
    <delete dir = "${sign.dir}"/>
</target>

然后,我们想要一个新的干净的构建,重新创建目录...

Then we want to re-create the directories for a new clean build...

<target name = "JFXInit" depends = "JFXClean">
    <echo>Creating the build directory...</echo>
    <mkdir dir = "${JFX.build.dir}"/>
    <mkdir dir = "${JFX.sign.dir}"/>
    <mkdir dir = "${store.dir}"/>
    <mkdir dir = "${sign.dir}"/>
</target>

这部分重要的是获得一个有效的JavaFX的JAR文件:

This part is critical to get a functioning JavaFX JAR file:

<target name = "JFXBuild" depends = "jar, JFXInit">
    <fx:jar destfile = "${JFX.build.dir}/${JFXProject.name}.jar">
        <fx:application name = "${JFXProject.name}"
                   mainClass = "${JFXMainClass}"/>
        <fileset dir = "build/classes"/>
    </fx:jar>
</target>

这将正确地存储所有部件放入在JAR地点(包括您的任何CSS和JFXML文件。如果你没有创建一个应用程序JFXML这可能不是必要的。我不知道我还没有测试了它。

This will store all parts correctly into their locations in the JAR (including any CSS and JFXML file you may have. If you aren't creating a JFXML application this may not be necessary. I don't know I haven't tested it out.

然后,我们要签署的JavaFX的JAR:

Then we want to sign the JavaFX JAR:

<target name = "JFXSign" depends = "JFXBuild">
    <fx:signjar  keystore = "${comodo.key.store}"
                    alias = "${comodo.key.alias}"
                storetype = "PKCS12" <!-- This is necessary for me, but may not be for you if you are not using a PFX file -->
                  keypass = "${comodo.key.pass}"
                storepass = "${comodo.key.storepass}"
                      jar = "${JFX.build.dir}/${JFXProject.name}.jar"
                  destdir = "${JFX.sign.dir}"/>
</target>

在有2个以上的目标是把手采购拉链,然后建立了拉链,另一个决赛演唱的最后一坛子:

After that there are 2 more targets that handle sourcing a zip and then setting up that zip, and one final for singing the last jar:

<target name = "build" depends = "JFXSign">
    <jar destfile = "${store.dir}/temp_final.jar"
  filesetmanifest = "skip">
        <zipgroupfileset dir = "${JFX.build.dir}"
                     includes = "*.jar"/>
        <zipgroupfileset dir = "${JFX.lib.dir}"
                    includes = "*.jar"/>
        <manifest>
            <attribute name = "Main-Class"
                      value = "${JFXMainClass}"/>
        </manifest>
    </jar>
</target>

<target name = "store" depends = "build">
    <zip destfile = "${store.dir}/${JFXProject.name}.jar">
        <zipfileset src = "${store.dir}/temp_final.jar"
               excludes = "META-INF/*sf, META-INF/*.DSA, META-INF/*RSA"/>
    </zip>
    <delete file = "${store.dir}/temp_final.jar"/>
</target>

<target name = "BuildStoreAndSign" depends = "store">
    <signjar
         keystore = "${comodo.key.store}"
            alias = "${comodo.key.alias}"
        storetype = "PKCS12" <!-- This is necessary for me, but may not be for you if you are not using a PFX file -->
           tsaurl = "${timestamp.url}"
          keypass = "${comodo.key.pass}"
        storepass = "${comodo.key.storepass}"
              jar = "${store.dir}/${JFXProject.name}.jar"
          destdir = "${sign.dir}"/>
    <delete dir = "${JFX.compile.dir}"/>
    <delete dir = "${JFX.build.dir}"/>
    <delete dir = "${JFX.sign.dir}"/>
    <delete dir = "${store.dir}"/>
</target>

我真的不能解释一大堆这一点,因为我无处关于这个问题的专家附近。我基本能够提取什么,我一直在寻找从这个例子code和来源我找到了感觉,并把它一起得到这样的:
那是半有用的信息最后一个位是的这个,但请注意这不会使用一个-JAR(我用一个罐子尝试过,但没有奏效。这不是把在CSS或应用它)。

I can't really explain a whole lot of this because I'm nowhere near an expert on this subject. I was able to basically extract the sense of what I was looking at from the example code and the sources I found and put it together to get this: One final bit of information that was semi-helpful was this, but please note this does NOT use one-jar (I tried it with one-jar but it didn't work. It wasn't bringing in the CSS or applying it).

此外,有点警告:这为我工作。我不能保证它会为你,但我想用它修补周围会产生类似的结果,以矿(运行一个.JAR JavaFX应用程序在任何你把它)。

Also, a bit of warning: This worked for me. I can't guarantee it will for you, but I imagine tinkering around with it would produce results similar to mine (a single .JAR JavaFX application that runs where ever you put it).

这篇关于如何注册和部署JavaFX应用程序到一个单一的.JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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