java - 使用 Rawr 打包 Slick2d JRuby 应用程序 : missing class or uppercase package name

标签 java ruby jruby packaging slick2d

我正在用 JRuby 编写一个使用 Slick2D 库的游戏。 我不知道如何让 Rawr gem 正确地捆绑我的应用程序而不会出现错误。

  1. 我运行rake rawr:jar。包已正确生成,没有错误。
  2. 然后java -jar package/jar/mygame.jar 运行应用程序。
  3. 我运行 rake rawr:bundle:app 生成了一个 MacOSX 应用程序,没有错误。
  4. 打开package/osx/mygame.app失败并出现错误:

    线程“main”org.jruby.exceptions.RaiseException中出现异常:(NameError)缺少类或大写包名称(`org.newdawn.slick.AppGameContainer')

    如果我将 package 目录移动到其他位置并尝试 java -jar package/jar/mygame.jar 命令,也会发生同样的情况。

为什么“org.newdawn.slick.AppGameContainer”会丢失,而所有其他声明似乎都工作得很好?

<小时/>

这是应用程序源代码:

require 'java'
require 'lib/java/lwjgl.jar'
require 'lib/java/slick.jar'

java_import org.newdawn.slick.BasicGame
java_import org.newdawn.slick.GameContainer
java_import org.newdawn.slick.Graphics
java_import org.newdawn.slick.Image
java_import org.newdawn.slick.Input
java_import org.newdawn.slick.SlickException
java_import org.newdawn.slick.AppGameContainer

class PongGame < BasicGame  
  def render(container, graphics)
    @bg.draw(0, 0)
    @ball.draw(@ball_x, @ball_y)
    @paddle.draw(@paddle_x, 400)
    graphics.draw_string('RubyPong (ESC to exit)', 8, container.height - 30)
  end

  def init(container)
    @bg = Image.new('bg.png')
    @ball = Image.new('ball.png')
    @paddle = Image.new('paddle.png')
    @paddle_x = 200
    @ball_x = 200
    @ball_y = 200
    @ball_angle = 45
  end

  def update(container, delta)
    input = container.get_input
    container.exit if input.is_key_down(Input::KEY_ESCAPE)

    if input.is_key_down(Input::KEY_LEFT) && @paddle_x > 0
      @paddle_x -= 0.3 * delta 
    end

    if input.is_key_down(Input::KEY_RIGHT) && @paddle_x < container.width - @paddle.width
      @paddle_x += 0.3 * delta 
    end 

    @ball_x += 0.3 * delta * Math.cos(@ball_angle * Math::PI / 180)   
    @ball_y -= 0.3 * delta * Math.sin(@ball_angle * Math::PI / 180) 

    if (@ball_x > container.width - @ball.width) || (@ball_y < 0) || (@ball_x < 0)
      @ball_angle = (@ball_angle + 90) % 360
    end

    if @ball_y > container.height
      @paddle_x = 200
      @ball_x = 200
      @ball_y = 200
      @ball_angle = 45
    end

    if @ball_x >= @paddle_x && @ball_x <= (@paddle_x + @paddle.width) && @ball_y.round >= (400 - @ball.height)
      @ball_angle = (@ball_angle + 90) % 360
    end
  end
end

app = AppGameContainer.new(PongGame.new('RubyPong'))
app.set_display_mode(640, 480, false)
app.start
<小时/>

Rawr build_configuration.rb 文件:

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: "mygame"
  #
  #c.project_name = "mygame"

  # 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 = "gui"

  # The main ruby file to invoke, minus the .rb extension
  # default value: "main"
  #
  c.main_ruby_file = "pong"

  # 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.7

  # Undocumented option 'target_jvm_version'
  # default value: 1.7
  #
  #c.target_jvm_version = 1.7

  # 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
<小时/>

项目树状:

- mygame/
  |
  |- lib/
  |  |- java/
  |     |- lwjgl.jar
  |     |- slick.jar
  |
  |- src/
  |  |- pong.rb
  |  |- org/
  |     |- monkeybars/
  |        |- rawr/
  |           |- Main.java
  |
  |- ball.png
  |- bg.png
  |- build_configuration.rb
  |- libjinput-osx.jnilib
  |- liblwjgl.jnilib
  |- openal.dylib
  |- paddle.png
  |- Rakefile
<小时/>

PS:我从提供的存档中获取了代码 here并更改它以满足 Rawr 默认值。

最佳答案

基本上,问题是 LWJGL native 需要与 mygame.jar 位于同一文件夹中。

这样,当您运行 rake rawr:bundle:app 时,它们就会捆绑在应用程序中,并且将包目录移动到其他位置也可以工作。

该错误的简洁性有点误导。

将其添加到 build_configuration.rb 中即可:

# A list of files that will be copied into the `<output_dir>/jar` folder.
c.files_to_copy = [
  "libjinput-osx.jnilib",
  "liblwjgl.jnilib",
  "openal.dylib"
]

关于java - 使用 Rawr 打包 Slick2d JRuby 应用程序 : missing class or uppercase package name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15946325/

相关文章:

ruby-on-rails - 在 Rspec 请求测试中使用 Session、Cookies 或 Current_something

java - 如何从 Java 调用/使用 MRI Ruby?

ruby - 你如何在 JRuby 中将 float 四舍五入到小数点后两位?

java - JBox2D 坐标不匹配

java - 为地址创建 hashCode 和 equals

ruby - 如何创建 thor::group 生成器作为 my_command 的参数

用于桌面应用程序的 Ruby gui

java - 有没有一种有效的方法来重构这个 Android SQLite 数据库处理程序?

java - applicationContext.xml 正在从 src/main/resources 复制到/WEB-INF/classes

ruby - 从外部前置后如何调用原始方法