使用Rawr打包Slick2d JRuby应用程序:缺少类或大写包名称

时间:2013-04-11 10:21:24

标签: 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命令,也会发生同样的情况。

  5. 为什么“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
    

    项目arborescence:

    - 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默认值。

1 个答案:

答案 0 :(得分:1)

基本上问题是LWJGL原生文件需要与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"
]