一个非常愚蠢的提示:创建新的 Ruby 应用程序,将其放在您的 java 项目附近,然后将以下内容放入 main.rb
PROJECT_DIR = "MyJavaApp"
# These must be relative to java project's dir or absolute paths
CLASSPATH = %w[dist/lib/*.jar /usr/share/some/other/lib.jar]
SUDO_BIN = "gksudo"
# Append your app's jar file into cp!
MAIN_CLASS = "com.andrew.myapp.Main"
# Put your own opts here (-Xmx, -Xms, etc)
JVM_OPTS = "-client"
###############################################
# Calculating project's root. 1st dir is a root of Ruby project, second is a common root
projroot = File.expand_path(File.dirname(__FILE__) + "/../.."
java_args = JVM_OPTS
cp = []
# It uses globbing to expand *.jar style stuffs
CLASSPATH.each do |path|
cp += path.start_with?("/") ? Dir[path] : Dir[File.join(projroot, PROJECT_DIR, path)]
end
java_args += "-classpath " + cp.join(File::PATH_SEPARATOR) + " "
# The heart of our work...
system(SUDO_BIN + " java " + java_args + " " + MAIN_CLASS)
将 ruby 项目设置为主项目。
我没试过,但肯定只有错别字。
我知道,这不是最佳解决方案,但 NB 在内部启动 java 项目,似乎没有提供配置选项来执行此操作。
顺便说一句:这个解决方案需要将 Ruby on Rails 插件安装到 NetBeans 中。当您的 java 程序正在运行时,该脚本不会退出。
重要提示:此脚本假定它在 Unix 兼容的操作系统下运行(绝对路径以 '/' 开头)!