首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Rawr打包Slick2d JRuby应用程序:缺少类或大写包名

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

Stack Overflow用户
提问于 2013-04-11 10:21:24
回答 1查看 1.1K关注 0票数 1

我正在用JRuby编写一个使用Slick2D库的游戏。我不知道如何使Rawr宝石正确地捆绑我的应用程序,没有错误。

  1. 我负责rake rawr:jar。正确生成包,没有错误。
  2. 然后java -jar package/jar/mygame.jar运行应用程序。
  3. 我运行rake rawr:bundle:app会生成一个MacOSX应用程序,没有错误。
  4. 打开package/osx/mygame.app失败时出错: 线程"main“中的(`org.newdawn.slick.AppGameContainer')异常:(NameError)缺少类或大写包名 如果我将package目录移到其他地方并尝试使用java -jar package/jar/mygame.jar命令,也会发生同样的情况。

为什么"org.newdawn.slick.AppGameContainer“会丢失,而所有其他声明似乎都正常呢?

下面是应用程序源代码:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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

植树造林项目:

代码语言:javascript
复制
- 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 :我从存档中获得了代码,提供了这里,并将其更改为符合Rawr默认值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-11 16:18:44

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

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

这个错误的不冗长有点误导人。

将其添加到build_configuration.rb中将有效:

代码语言:javascript
复制
# 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"
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15946325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档