所以我第一次在JRuby中创建了一个应用程序。现在我无法理解如何最终确定应用程序,即。如何提供最终用户可以执行的.jar
文件。
我知道编译到.class
文件,可以通过命令行调用,但这不是非常用户友好。
如何轻松访问我在JRuby中编写的应用程序给最终用户?
答案 0 :(得分:0)
如何轻松访问我用JRuby编写的应用程序 最终用户?
您可以尝试安装rawr gem,看看是否可以使用它。
1 )为项目创建所有必需的rawr文件(这是在安装rawr gem之后):
~/jruby_programs$ mkdir proj1
~/jruby_programs$ cd proj1
~/jruby_programs/proj1$ rawr install
然后你得到一堆输出。这会创建这个目录结构:
../proj1
├── Rakefile
├── build_configuration.rb
├── lib
│ └── java
│ └── jruby-complete.jar
└── src
└── org
└── monkeybars
└── rawr
├── Main.java
└── Path.java
2 )将您的源代码放在src /目录中,例如
./src
├── hello_jruby.rb
└── org/
#hello_jruby.rb
puts 'hello'
require 'java'
java_import 'java.util.TreeSet'
set = TreeSet.new
set.add "foo"
set.add "Bar"
set.add "baz"
set.each do |v|
puts "value: #{v}"
end
3 )创建jar文件:
~/jruby_programs/proj1$ rake rawr:jar
我最初使用rake rawr:base_jar
,因为这是rawr docs指示你应该做的,但这对我不起作用。当我执行jar文件时(见下一步),我不断收到错误:
线程“main”中的异常java.lang.NoClassDefFoundError: org / jruby / RubyInstanceConfig at org.monkeybars.rawr.Main.main(Main.java:21)引起: java.lang.ClassNotFoundException:org.jruby.RubyInstanceConfig
4 )执行jar文件:
~/jruby_programs/proj1$ java -jar package/jar/proj1.jar
这是我的输出:
Add 'src/' to $:
hello
value: Bar
value: baz
value: foo
不幸的是,我不知道如何摆脱第一线。 $:
是一个ruby全局变量,其同义词为$LOAD_PATH
。将以下内容添加到hello_jruby.rb
的顶部不起作用:
$LOAD_PATH << '/src'
以下是我必须对build_configurationl.rb文件进行的调整(如果默认值不适合你,你只需要取消注释部分):
# Generated by Rawr version 1.7.0
configuration do |c|
# The name for your resulting application file (e.g., if the project_name is 'foo' then you'll get foo.jar, foo.exe, etc.)
# default value: "proj1"
#
#c.project_name = "proj1"
# Undocumented option 'output_dir'
# default value: "package"
#
#c.output_dir = "package"
# The type of executable to create (console or gui)
# default value: "gui"
#
c.executable_type = "console"
# The main ruby file to invoke, minus the .rb extension
# default value: "main"
#
c.main_ruby_file = 'hello_jruby'
# The fully-qualified name of the main Java file used to initiate the application.
# default value: "org.monkeybars.rawr.Main"
#
#c.main_java_file = "org.monkeybars.rawr.Main"
# A list of directories where source files reside
# default value: ["src"]
#
#c.source_dirs = ["src"]
# A list of regexps of files to exclude
# default value: []
#
#c.source_exclude_filter = []
# The base directory that holds Mirah files, or subdirectories with Mirah files.
# default value: "src"
#
#c.mirah_source_root = "src"
# Whether Ruby source files should be compiled into .class files. Setting this to true currently breaks packaging
# default value: false
#
#c.compile_ruby_files = false
# A list of individual Java library files to include.
# default value: []
#
#c.java_lib_files = []
# A list of directories for rawr to include . All files in the given directories get bundled up.
# default value: ["lib/java"]
#
#c.java_lib_dirs = ["lib/java"]
# A list of files that will be copied into the `<output_dir>/jar` folder. Note that the files maintain their directory path when copied.
# default value: []
#
#c.files_to_copy = []
# Undocumented option 'source_jvm_version'
# default value: 1.7
#
c.source_jvm_version = 1.6
# Undocumented option 'target_jvm_version'
# default value: 1.7
#
c.target_jvm_version = 1.6
# Undocumented option 'jvm_arguments'
# default value: ""
#
#c.jvm_arguments = ""
# Undocumented option 'java_library_path'
# default value: ""
#
#c.java_library_path = ""
# Undocumented option 'extra_user_jars'
# default value: {}
#
#c.extra_user_jars[:data] = { :directory => 'data/images/png',
# :location_in_jar => 'images',
# :exclude => /*.bak$/ }
# Undocumented option 'verbose'
# default value: false
#
#c.verbose = false
# Undocumented option 'mac_do_not_generate_plist'
# default value: false
#
#c.mac_do_not_generate_plist = false
# working directory specified in plist file
# default value: "$APP_PACKAGE"
#
#c.mac_plist_working_directory = "$APP_PACKAGE"
# Undocumented option 'mac_icon_path'
# default value: nil
#
#c.mac_icon_path = nil
# Undocumented option 'windows_icon_path'
# default value: nil
#
#c.windows_icon_path = nil
end