Toggle navigation


JRuby镜像手册

Version 1.0.0
JRuby,一个采用纯Java实现的Ruby解释器,由JRuby团队开发。它是一个自由软件,在CPL/GPL/LGPL三种许可协议下发布。
JRuby是面向Ruby、基于Java虚拟机(JVM)的一种解释程序,它结合了Ruby语言的简易性和功能强大的JVM的执行机制,包括与Java库 全面集成。Rails彻底加快及简化了Web应用的开发,不过它让人觉得不够成熟,特别是在高端企业级功能方面。另一方面,Java平台及其虚拟机、库和 应用服务器的速度、稳定性和功能方面却一直在提升,现在已被公认为是开发高端服务器。

镜像安装完成后,服务已经自动启动。使用浏览器打开首页demo:http://IP地址,首页正常显示,则表示环境安装成功。

如果安装后,不能访问首页,到管理控制台重启一下服务器,待服务器启动完全完成后再次打开首页。(原因:镜像安装后,首次启动服务没有自动启动,重启一般就解决了,以后重启也都会自动启动)

下面主要列出Linux下常见操作说明

软件目录和版本

软件安装在/data/jruby*(*表示jruby不同的版本号,以下不再单独说明)。

首页对应目录:/data/jruby*/apache2/htdocs,该目录包含首页index等文件。

版本:JRuby 9.1.2.0、Rails 3.2.22、Warbler gem 1.3.2、Apache Tomcat 8.0.35、Subversion 1.8.16、SQLite 3.7.15.1、MySQL 5.5.49

服务启动停止

服务随操作系统自动启动,如果修改配置参数后,需要手工启停服务。

[root@iZ94bojtvkpZ ~]# cd /data/jrubystack-9.1.2.0/
[root@iZ94bojtvkpZ jrubystack-9.1.2.0]# ./ctlscript.sh help
usage: ./ctlscript.sh help
./ctlscript.sh (start|stop|restart|status)
./ctlscript.sh (start|stop|restart|status) mysql
./ctlscript.sh (start|stop|restart|status) apache
./ctlscript.sh (start|stop|restart|status) tomcat

help – this screen
start – start the service(s)
stop – stop the service(s)
restart – restart or start the service(s)
status – show the status of the service(s)

命令举例:

[root@iZ94bojtvkpZ jrubystack-9.1.2.0]# ./ctlscript.sh restart
Syntax OK
/data/jrubystack-9.1.2.0/apache2/scripts/ctl.sh : httpd stopped
Using CATALINA_BASE: /data/jrubystack-9.1.2.0/apache-tomcat
Using CATALINA_HOME: /data/jrubystack-9.1.2.0/apache-tomcat
Using CATALINA_TMPDIR: /data/jrubystack-9.1.2.0/apache-tomcat/temp
Using JRE_HOME: /data/jrubystack-9.1.2.0/java
Using CLASSPATH: /data/jrubystack-9.1.2.0/apache-tomcat/bin/bootstrap.jar: /data/jrubystack-9.1.2.0/apache-tomcat/bin/tomcat-juli.jar
Using CATALINA_PID: /data/jrubystack-9.1.2.0/apache-tomcat/temp/catalina.pid
Tomcat stopped.
/data/jrubystack-9.1.2.0/apache-tomcat/scripts/ctl.sh : tomcat stopped
/data/jrubystack-9.1.2.0/mysql/scripts/ctl.sh : mysql stopped
160712 14:20:25 mysqld_safe Logging to ‘/data/jrubystack-9.1.2.0/mysql/data/mysqld.log’.
160712 14:20:25 mysqld_safe Starting mysqld.bin daemon with databases from /data/jrubystack-9.1.2.0/mysql/data
/data/jrubystack-9.1.2.0/mysql/scripts/ctl.sh : mysql started at port 3306
Using CATALINA_BASE: /data/jrubystack-9.1.2.0/apache-tomcat
Using CATALINA_HOME: /data/jrubystack-9.1.2.0/apache-tomcat
Using CATALINA_TMPDIR: /data/jrubystack-9.1.2.0/apache-tomcat/temp
Using JRE_HOME: /data/jrubystack-9.1.2.0/java
Using CLASSPATH: /data/jrubystack-9.1.2.0/apache-tomcat/bin/bootstrap.jar:/data/jrubystack-9.1.2.0/apache-tomcat/bin/tomcat-juli.jar
Using CATALINA_PID: /data/jrubystack-9.1.2.0/apache-tomcat/temp/catalina.pid
Tomcat started.
/data/jrubystack-9.1.2.0/apache-tomcat/scripts/ctl.sh : tomcat started
Syntax OK
/data/jrubystack-9.1.2.0/apache2/scripts/ctl.sh : httpd started at port 80

下面主要列出Windows下常见操作说明

软件目录和版本

软件安装在C:websoft9jruby*(*表示jruby不同的版本号,以下不再单独说明)。

首页对应目录:C:websoft9jruby*apache2htdocs,该目录包含首页index等文件。

版本:JRuby 9.1.2.0、Rails 3.2.22、Warbler gem 1.3.2、Apache Tomcat 8.0.35、Subversion 1.8.16、SQLite 3.7.15.1、MySQL 5.5.49

服务启动停止

服务随操作系统自动启动,如果手工修改配置参数后,需要重新启停服务,有两种方法。

方法一:在“开始”-> “管理工具”->“服务”中重启jruby***服务。

方法二:在C:websoft9jruby*中找到“manager-windows”。

双击打开“manager-windows”,可以进行服务启停、参数配置。

Linux默认管理员/密码:root/123456

Windows默认管理员/密码:root/websoft9

How can I run a command in the JRuby Stack?

Select your platform for instructions on how to run commands in your stack.

All native installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system. To work correctly, certain environment variables need to be set before accessing different binaries in the stack.

The Bitnami console is a script to load the stack environment. This console is useful to run any command included in the stack: jrubymysqlopenssl, among others.

On Linux:

At the server console, enter the following commands:

$ cd ~/jrubystack-VERSION
$ ./jrubyconsole

On Windows:

From the Start Menu, click the Start -> Bitnami JRuby Stack -> Use JRuby shortcut.

————————————————————————————————————————

Select your platform for instructions on how to install gems in your stack. If you are installing a gem that requires compilation, you will need compilation tools like makeg++ and others. On cloud servers and virtual machines, these compilation tools are already pre-installed. For native installers, you must separately install these tools.

If you want to install a gem in the Bitnami JRuby Stack, run the gem install command. Note that this command should be run only after loading the Bitnami console, as described here. For example, use this sequence of commands to install Rake:

$ ./jrubyconsole
$ jruby -S gem install rake

If you are installing a gem that requires compilation, you will need compilation tools like makeg++ and others. On native installers, these compilation tools can be installed separately as discussed below.

On Linux:
If you are using Ubuntu, install the “build-essential” package via apt as shown below:

$ sudo apt-get install build-essential

If you are using a different Linux distribution, install g++ and build packages separately following the instructions provided by your distribution.

On Windows:
The Bitnami JRuby Stack already includes a Development Kit for Windows users. It is a MSYS/MinGW-based toolkit that enables you to build many of the native C/C++ extensions available for Ruby.

 

NOTE: The osx-gcc-installer is a stripped-down version of Xcode 4.1, which only includes GCC and the required libraries. The limitation of this solution is that it does not include certain headers (such as the Carbon/Cocoa headers found in the main Xcode installation) because of licensing restrictions. This means that some native gems will fail to compile. Registered Apple developers can get the necessary header packs from Apple.

NOTE: Xcode 4.2+ versions use a non-compatible version of GCC. To use these, first install Xcode 4.1 and then upgrade to your desired version, answering “no” when asked to remove prior versions. Once the upgrade is complete, compile using the binary at /usr/bin/gcc-4.2.

 

How to run a Ruby program?

Select your platform for instructions on how to run commands in your stack.

All native installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system. To work correctly, certain environment variables need to be set before accessing different binaries in the stack.

The Bitnami console is a script to load the stack environment. This console is useful to run any command included in the stack: mysqljavaopenssl, among others.

On Linux:
At the server console, enter the following commands:

$ cd ~/jrubyrubystack-VERSION
$ ./jrubyconsole

On Windows:

From the Start Menu, click the Start -> Bitnami JRuby Stack -> Use JRuby Stack shortcut. Alternatively, execute the use_jruby.bat script from your stack installation directory.

 

Once the JRuby console has loaded, execute a JRuby command as you normally would. For example, this command executes a simple Ruby program:

$ jruby my_ruby_script.rb

 

How to install gems in your JRuby Stack?

NOTE: The steps below are only applicable to native installers. For cloud servers and virtual machines, you should create a new Rails project as described here.

When using a native installer, the sample project is located in the installdir/projects/sample folder. Follow these steps:

1. Load the Bitnami console.

$ cd installdir
$ ./jrubyconsole

2. Start the Rails server with the sample application.

$ cd installdir/projects/sample
$ jruby script/rails server

You should see something like this:

  => Booting WEBrick
  => Rails 3.2.22 application starting on http://localhost:3000
  => Call with -d to detach
  => Ctrl-C to shutdown server
  [     ] INFO  WEBrick 1.3.1
  [     ] INFO  ruby 1.9.3 (2015-07-07) [java]
  [     ] INFO  WEBrick::HTTPServer#start: pid=3061 port=3000

You should now be able to access the sample application at http://localhost:3000/ from your browser.

 

How to create your own Rails project?

Select your platform below to learn how to initialize a new Rails project.

To create a new Rails project, load the Bitnami console, change to the installdir directory and initialize a new project as below. Remember to replace the APPNAME placeholder with the actual name of your project.

$ cd installdir
$ ./jrubyconsole
$ jruby -S rails new APPNAME

Next, start the Rails server by running the following command:

$ cd installdir/APPNAME
$ jruby -S bundle exec rails s

This will start the Rails server for your application on port 3000. You can now access the application by browsing to http://localhost:3000 using your Web browser.

TIP: If you see an error on Linux stating “Could not find a JavaScript runtime”, you must add the rubyracer gem (already included in the Bitnami Ruby Stack) into the Gemfile, as below:

...
gem 'sqlite3'
gem 'therubyracer'
...