JRubyFX

JRubyFX is a pure ruby wrapper for JavaFX 2.2+ with FXML support

Status

JRubyFX master should be usable in its current form and able to run simple FXML apps if used properly (see Issues). FXML syntax in master/1.0 is very different from 0.9 series. Please see the JRubyFX github wiki for more details.

Install

gem install jrubyfx

Manual Build and Install

Build is done using rake/gem/bundler/rdoc. You need JRuby >1.7.4 (in 1.9 mode), Java >1.6 with JavaFX 2.2, but Java 7 is recommended. Building native application packages requires JDK 8.

gem install jrubyfx-fxmlloader
rake install

Once the gem is installed, just run a ruby file that uses it normally.

NOTE: If you don't have JRuby installed as the ruby command, use jruby -S rake instead of rake. If you are using RVM, this does not apply to you (though make sure you rvm use jruby).

If you are reporting bugs or encountering fxml issues: please install master jrubyfx-fxmlloader instead of from rubygems

Creating a Jar

If you want to distribute your application, you can create a jar with embedded JRuby. Place all your sources in a folder, and run (replacing paths as appropriate):

jrubyfx-jarify samples/fxml/ --main samples/fxml/Demo.rb Demo.jar

This jar can then run anywhere there is a JVM with JavaFX. Note than the main file is renamed to jar-bootstrap.rb inside the jar. If you need to detect if you are in a jar, use the JRubyFX::Application.in_jar? method.

You can create native application packages and installers. For now, this requires that you have JDK8 installed, although this may change in the near future. Just pass the --native option. The packaging toolkit can only create packages for the OS it is being used on, so for Windows installers you will need to run it on a Windows machine, for OSX installers you will need to run it on a Mac, etc.

In order for the installer to be created, you will need some additional tools installed on your system. For Windows you need either Inno Setup 5 or later for an EXE or Windows Installer XML (WiX) toolset to generate an MSI. Make sure the WiX toolset's bin folder is on the PATH. No special tools are need to generate a DMG, just a recent version of OSX. For linux, the packager uses dpkg-deb to create DEB installers and rpmbuild for RPM.

If you don't want your application to be called "JarBootstrapMain", I highly suggest passing the --name option with an appropriate string.

To customize the package, for example to change the icons or license pass the -v or --verbose option. This will cause the JavaFX packaging tools to enter verbose mode, and provide more details about the process, including (the important part for customization) the location of a temporary folder where the config resources for the build are held and a list of the resources and the role of each. Copy the contents of this tmp folder into a folder in your project directory (the dir you run jrubyfx-jarify from) where the packaging tools will know to look for them. For example, on linux this would be main_project_dir/package/linux. On OSX, it is main_project_dir/package/macosx. So, if I wanted to use a custom icon, I'd replace the default icon with my own, ensuring it has the same name, and place it inside that linux or macosx folder. Then run the build again. You can find more information on customizing at the official Oracle documentation. This blog post may also be helpful, as he goes through the process of customizing an app for both Windows and OSX.

The JavaFX tools provide far more options than are available from this tool. You can create your own rake tasks and access them directly, however. See this article in the JRuby wiki.

Example: If my project directory is Hello, all my files are in src, I have a dist folder created for my jar file, my main file is called HelloWorldApp.rb, my app's name is "Hello World App", and I want the customization info, the command line would look like this:

jrubyfx-jarify src --main src/HelloWorldApp.rb dist/HelloWorldApp.jar --native --name "Hello World App" -v

Also note that you can do this in code, see samples/fxml/Demo.rb for the rake task usage.

Samples

To run sample:

jruby samples/fxml/Demo.rb

Or, if you have not installed the gem, or are testing edits to jrubyfx.rb:

rake run main_script=samples/fxml/Demo.rb

To run all samples (a nice quick way to make sure you didn't break anything), run:

jruby -I lib samples/test_all_the_samples.rb

Several other files that can be used as examples are in the tests/ folder

Creating Application and Controller

Require the 'jrubyfx' file/gem, and subclass JRubyFX::Application (and JRubyFX::Controller if you are using FXML). At the bottom of the file, call yourFXApplicationClass.launch(). Override start(stage) in the application. See samples/fxml/Demo.rb for commented FXML example, or the fils in samples/javafx for non-FXML (programatic JavaFX, but you should really look into FXML, its better) or see the Getting Started Guide and the Syntax Notes on the JRubyFX github wiki

If you want rdoc, run rake rdoc. Please note that there are lots of generated methods and conventions that are not in the RDoc. Please read the Getting Started Guide or the tutorials.

Issues

  • Use JRubyFX-FxmlLoader's FxmlLoader instead of javafx.fxml.FXMLLoader for maximum Ruby support.
  • FXML support in master for very complex documents is untested. Report bugs against JRubyFX-FxmlLoader with the FXML file if it fails.
  • You must use the provided JavaFXImpl::Launcher to launch the app (aka: call yourFXApplicationClass.launch())
  • Errors loading JavaFX are bugs. Please report if you encounter this issue, tell us your platform, OS, and version of JRuby
  • Jarify command needs the jar executable in your path.
  • Any other difficulties are bugs. Please report them

Contact

Find us in #jruby on freenode.

License

Main code is Apache 2.0. See LICENSE. Some samples in contrib may have other licenses.

Authors

  • Patrick Plenefisch (byteit101)
  • Thomas E Enebo (enebo)
  • Hiro Asari (BanzaiMan or asarih)
  • Jeremy Ebler (whitehat101)
  • Hiroshi Nakamura (nahi)
  • Eric West (e_dub or edubkendo)


JRubyFX

JRubyFX是用于支持FXML的JavaFX 2.2+的纯红宝石封装

状态

JRubyFX主机应该可以使用其当前的形式,并能够运行简单的FXML应用程序,如果正确使用(见问题)。 master / 1.0中的FXML语法与0.9系列非常不同。有关详细信息,请参阅 JRubyFX github wiki

安装

gem install jrubyfx

手动构建和安装

使用rake / gem / bundler / rdoc完成构建。您需要JRuby> 1.7.4(1.9模式),Java> 1.6与JavaFX 2.2,但建议使用Java 7。构建本机应用程序包需要JDK 8。

gem install jrubyfx-fxmlloader
rake install
一旦安装了gem,只需运行一个正常使用的ruby文件。

注意:如果您没有将JRuby安装为 ruby​​ 命令,请使用 jruby -S rake 而不是 rake 。如果 你正在使用RVM,这不适用于你(尽管确保你使用rrm使用jruby )

如果您要报告错误或遇到fxml问题,请执行以下操作:,请安装 master jrubyfx-fxmlloader

创建罐

如果要分发应用程序,可以使用嵌入式JRuby创建一个jar。 将所有来源放在一个文件夹中,并运行(根据需要替换路径):

jrubyfx-jarify samples/fxml/ –main samples/fxml/Demo.rb Demo.jar

然后,这个jar可以在JavaFX的JVM上运行。注意比主文件是 在jar中重命名为jar-bootstrap.rb。如果你需要检测你是否在一个罐子里, 使用JRubyFX :: Application.in_jar?方法。

您可以创建本机应用程序包和安装程序。现在,这需要您 JDK8安装,尽管这可能会在不久的将来发生变化。只需传递 - native 选项。包装工具包只能为正在使用的操作系统创建软件包,因此对于Windows安装程序,您需要在Windows机器上运行它,对于OSX安装程序,您需要在Mac上运行它。

为了创建安装程序,您将需要在系统上安装一些其他工具。对于Windows,您需要使用Inno Setup 5或更高版本的EXE或 Windows Installer XML(WiX)工具集生成MSI。确保WiX工具集的 bin 文件夹位于 PATH 上。不需要专门的工具来生成DMG,只是最新版本的OSX。对于linux,打包程序使用dpkg-deb来创建DEB安装程序和RPM的rpmbuild。

如果您不希望将应用程序称为JarBootstrapMain,我强烈建议您使用适当的字符串传递 - name 选项。

要自定义包,例如更改图标或许可证,通过 -v - verbose 选项。这将导致JavaFX打包工具进入详细模式,并提供有关进程的更多详细信息,包括(定制的重要部分)持有构建配置资源的临时文件夹的位置以及资源列表和每个人的角色。将此tmp文件夹的内容复制到项目目录(运行jrubyfx-jarify的目录)中的文件夹中,包装工具将知道要查找它们。例如,在linux上,这将是 main_project_dir / package / linux 。在OSX上,它是 main_project_dir / package / macosx 。所以,如果我想使用自定义图标,我将用我自己的名称替换默认图标,确保它具有相同的名称,并将其放在该linux或macosx文件夹中。然后再次运行build。您可以在官方Oracle文档中找到有关自定义的更多信息。 这篇博客文章也许是有帮助的,因为他去通过自定义Windows和OSX的应用程序的过程。

JavaFX工具提供的选项远远超出了这个工具的可用性。但是,您可以创建自己的耙子任务并直接访问它们。请参阅JRuby wiki中的本文

示例:如果我的项目目录是 Hello ,我的所有文件都在 src 中,我有一个为我的jar文件创建的 dist 文件夹我的主文件叫做HelloWorldApp.rb ,我的应用程序的名称是Hello World App,我想要自定义信息,命令行将如下所示:

jrubyfx-jarify src –main src/HelloWorldApp.rb dist/HelloWorldApp.jar –native –name "Hello World App" -v

另请注意,您可以在代码中执行此操作,有关耙式任务使用情况,请参阅samples / fxml / Demo.rb。

样本

运行示例:

jruby samples/fxml/Demo.rb

或者,如果您尚未安装宝石,或正在测试编辑jrubyfx.rb:

rake run main_script=samples/fxml/Demo.rb
运行所有样本(一个很好的快速方法,以确保你没有破坏任何东西),运行:

jruby -I lib samples/test_all_the_samples.rb

可以用作示例的其他几个文件位于tests / folder

创建应用程序和控制器

需要’jrubyfx’文件/ gem,子类JRubyFX :: Application(如果您使用FXML,则为JRubyFX :: Controller)。 在文件的底部,调用您的FXApplicationClass .launch()。 覆盖应用程序中的启动(阶段)。有关注释的FXML示例,请参阅samples / fxml / Demo.rb, 或者对于非FXML(编程JavaFX)的samples / javafx中的fils,但是你应该真的 查看FXML,更好)或查看入门指南和有关 JRubyFX github wiki

如果您想要rdoc,请运行 rake rdoc 。请注意,RDOC中没有许多生成的方法和约定。请阅读入门指南或教程。

问题

  • 使用JRubyFX-FxmlLoader的FxmlLoader而不是javafx.fxml.FXMLLoader,以获得最大的Ruby支持。
  • 非常复杂的文档中的主人的FXML支持未经测试。如果JRubyFX-FxmlLoader与FXML文件失败,则报告错误。
  • 您必须使用提供的JavaFXImpl :: Launcher启动应用程序(也称为:call yourFXApplicationClass .launch())
  • 加载JavaFX的错误是错误。请报告您是否遇到此问题,告诉我们您的平台,操作系统和JRuby版本
  • Jarify命令需要路径中的 jar 可执行文件。
  • 任何其他困难都是错误。请报告他们

联系方式

在freenode的#jruby中找到我们。

许可证

主要代码是Apache 2.0。参见许可证。 contrib中的某些示例可能有其他许可证。

作者

  • Patrick Plenefisch(byteit101)
  • Thomas E Enebo(enebo)
  • Hiro Asari(BanzaiMan或asarih)
  • Jeremy Ebler(whitehat101)
  • 中村弘(nahi)
  • Eric West(e_dub或edubkendo)




相关问题推荐