[-- Install and configure Ruby support in netbeans 6.0 --]

Source: Internet
Author: User
Tags glassfish ruby on rails netbeans
Document directory
  • Add a MySQL database
  • Add a java db (Derby) Database
Download Ruby support


If you have not installed the netbeans 6.0 IDE, open the netbeans ide 6.0 download page and download the IDE versions that contain Ruby support. If you already have netbeans ide 6.0, but there is no ruby support in netbeans ide 6.0, follow these steps to add Ruby support to the IDE.

  1. If you use proxy to access the Internet, you can select Tools> options in the main menu, select manual proxy settings, enter the name and port number of your HTTP Proxy Server, and click OK.
  2. Select Tools> plugins from the main menu.
  3. In the Plugins dialog box, click the available plugins tab and use the scroll bar to view the ruby class, as shown in ).


  4. Select the ruby and rails check box to add Ruby support to netbeans IDE.
  5. (Optional) Select the jruby and rails distribution check box to download and install the jruby software and the Ruby on Rails framework.
  6. (Optional) Select the ruby experimental hints check box to display additional source code prompts.
  7. Click the Install button.

    A netbeans ide installer is displayed.

  8. Click Next in the netbeans ide installer.
  9. Read the license agreement, select the I accept the terms in all license agreements radio button, and click Next.
  10. Click the Install button.
  11. After the installation is complete, you can select restart ide now to restart ide immediately, or you can select restart ide later and then click Finish.
Configure the IDE to use your own Ruby installation (optional)


When you create or open a ruby project in the IDE for the first time, the IDE checks whether other Ruby versions are installed in addition to the jruby software bundled with the IDE ). If yes, the IDE will display a dialog box asking which software to use.

If you decide to install Ruby later, follow these steps to configure the IDE to use Ruby.

  1. Select Tools> options from the main menu of IDE.
  2. Click Ruby and, if necessary, click the platform tab.

    If you have not enabled or created a ruby project, the IDE displays a choose Ruby interpreter dialog box when you first access the platform tab, as shown in ). If this dialog box is not displayed, perform Step 5.


  3. Select the Ruby interpreter you want to use. If the list does not contain the Ruby interpreter you want, click the other button.
  4. Click Close.
  5. If you have selected other in the previous step or the Ruby interpreter dialog box does not appear, click the Browse button to locate the ruby library and then click open.
  6. Click OK to close the Options dialog box.

For information about how to get Ruby software, go to [url] www.ruby-lang.org [/url], instantrails.rubyforge.org, and locomotive.raaum.org.

Manage gem


GEM is a third-party Ruby library. IDE provides the ruby gems manager to add and maintain the gem.

To open the manager, choose tools> Ruby gems from the main menu. Click the installed tab to view the gem list, it contains the gem installed for the registered Ruby platform (see the previous section to obtain information about using your own Ruby by switching the IDE Ruby platform ). If you are using jruby platform and IDE with jruby and rails distribution plug-ins, the list contains activerecord-jdbc gem and rails framework (as shown in ). Click the new GEMS tab to view which gems can be added to Ruby platform.


Note:Rubygems wiki page provides information on how to enable the ruby gems manager to manage the local Ruby gem repository.

For more information about Ruby gems, visit [url] www.ruby-lang.org/en/libraries/#/url#. For more information about rails, see rubyonrails.org. View jruby-extras.rubyforge.org/activerecord-jdbc.to obtain information about activerecord-jdbc gem.

Use the database server through jruby


You can use the following two methods to access the database through the jruby on Rails application.

  • MySQL adapter.MySQL adapter is included in jruby. This MySQL adapter is just as simple as a local Ruby on Rails application.
  • JDBC adapter.As mentioned above, jruby and rails distribution plug-ins include activerecord-jdbc gem. Ruby on Rails Applications can access database servers that provide JDBC 3.0 compatible drivers through activerecord-jdbc gem, such as MySQL, PostgreSQL, Oracle, HSQLDB, and java db (also known as Derby ). The JDBC driver must be a pure Java driver. At the time of writing this article, activerecord-jdbc cannot work with the SQLite JDBC driver.

    To use JDBC connection, the database server must have a JDBC 3.0 client driver. For example, you can download the MySQL ctor/J driver for MySQL. Must be inJRuby/libFolder contains a copy of the JDBC driver. Depending on the installation location, the folder will be in one of the following two locations.

    • Netbeans-install-Dir/ruby1/jruby-1.0.1/lib
    • Netbeans-user-Dir/jruby-1.0.1/JRuby/lib

    To find the location for jruby installation, select Tools> options from the main menu, click Ruby, and then click the platform tab.

    Note:The java db database server is bound to the glassfish application server, and itsDerbyclient. JarPut inGlassfish-install-Dir/Javadb/libFolder.

    To use the JDBC adapter in the Ruby on Rails project, you can select the ACCESS database using JDBC check box (as shown in) when creating the project ).


    When this check box is selected, IDE places the following statementsEnvironment. RbFile.

    Sample Code 1: Set the JDBC Environment
    if RUBY_PLATFORM =~ /java/
      require 'rubygems'
      gem 'ActiveRecord-JDBC'
      require 'jdbc_adapter'
    end

    When you access a database using a JDBC adapterDatabase. ymlConfigure the database (as shown below ).

    Sample Code 2: configure a JDBC database
      adapter: mysql
      database: my_development_database
      username: fred
      password: pfm
      host: localhost

    When you create Ruby in the rails project, IDE adds the configuration toDatabase. ymlFile, the database server is selected in step 2 of the wizard (4. If the database server you are using is not displayed in the drop-down list, you canDatabase. ymlFile to edit the database configuration.

Note:If the host file of your operating system does not containLocalhost, Available127.0.0.1. Note that in some systems, lower-case letters should be used for database settings.

Add Database


Some netbeans tutorials require that you create a database to store the data tables used in this tutorial. The procedure for creating a database varies with the database server. The following describes how to create MySQL and java db databases.

Add a MySQL database
  1. If the database server has not been started, start the server.
  2. (Optional) follow these steps to create a user.
    1. At the command prompt, enter the following command:


      mysql -uUser -p

      If the user does not have a password, it can be omitted.-P. Otherwise, enter the password when prompted. In the MySQL database, the user must have an imageRootCreate global user privileges or insert privileges.

    2. Use the following syntax to create a user.

      CREATE USER 'fred'@'localhost'
      identified by 'pfm';

    3. (Optional) use the following syntax to specify access privileges. In this example, the user obtains all the privileges of all databases on the local host database server.

      GRANT ALL PRIVILEGES ON *.* TO 'fred'@'localhost';

    4. InputQuitPress enter to exit the command prompt.
  3. To create a database, you can use the following syntax in the command prompt status:

    mysqladmin -u fred -p create mydb_dev

    If the user does not have a password, it can be omitted.-P. Otherwise, enter the password when prompted. If you have not created a user, you can userootAs the user name.

For more information about creating mysql users and databases, see MySQL reference manual.

Add a java db (Derby) Database

If you have installed an IDE version containing the glassfish application server, the IDE is configured to access the java db database provided by glassfish. To add a java db database in the IDE, follow these steps.

  1. On the main menu of IDE, choose tools> java db database> Create Database.
  2. In the create java db database dialog box, enter the database name, user name, and password (optional), as shown in.


  3. To specify different locations for the database, click the Settings button. In the java db Settings dialog box, click Select database storage location browse, find the folder to store the database, and click open. Click OK to close the JAVA DB Settings dialog box.
  4. Click OK. IDE creates a database and adds a node in the database area of the Services window, as shown in ).


Register a database server with IDE


You do not have to register it with IDE before using the database server in the ruby project. However, after doing so, you can create and View tables, And you can practice SQL commands directly in the IDE. Some netbeans rubytu torial requires the use of IDE to register a database.

Note:If the IDE version containing the glassfish server is installed, the IDE automatically registers for the java db database.

Follow these steps to use ide to register a MySQL database server and establish a connection between the IDE and the database instance.

  1. If no JDBC 3.0 compatible Driver (such as MySQL ctor/J driver) is available on the database server ).
  2. In the Services window, expand databases, right-click the drivers node, and select new driver in the pop-up window.

    The new JDBC driver dialog box appears.

  3. Click Add, find and select the JAR file of the driver, and then click open.

    In the new JDBC driver dialog box, the settings of the selected driver are displayed.

  4. Click OK to close the new JDBC driver dialog box.

    IDE adds a database server node under the drivers node, as shown in. Now you can establish a connection with the MySQL database instance.

  5. To create a connection between the IDE and the database instance (the example of mydb_development database described in the preceding section), right-click the node of the database and select new connection.

    The new database connection dialog box appears.

  6. Select the driver you want from the name drop-down list, such as MySQL (connector/J driver ).
  7. Use the format in the Database URL text box as an example to enter the database URL in the text box. For example,JDBC: mysql: // localhost: 3306/mydb_development.
  8. If required, enter the user name and password, as shown in ).


  9. Click OK.
  10. After the connection is established, click OK to close the dialog box.

    IDE adds a node to the connection under the database node. The flag card of the node shows that the connection is enabled. The flag card indicates that the connection is disconnected when IDE is run next time. To reconnect, right-click the node and select connect. If required, enter the password and click OK.

Deploy the jruby application to the glassfish Application Server


By default, the jruby application runs in the webrick browser. To deploy a jruby application to the glassfish application server, you can package the application and its dependency into a web archive (WAR) file, then, provide the war file to the Application Server (follow these steps ).

  1. The deployed application uses the production database. OpenDatabase. ymlFile to ensure that the configuration of the product database is correct.
  2. When you create a jruby application, the "add rake targets to support application server deployment" option is displayed, as shown in ). If you plan to deploy in glassfish, select this check box.


    If your existing jruby project does not provide the rake target. Follow these steps to add the goldspike plug-in to this project. The rake task added by this plug-in can create war files.

    1. In the projects window, right-click the node of the project and select the rails plug-in from the shortcut menu.
    2. In the rails plugins dialog box, click the new plugins tab.
    3. Select a goldspike entry and click the Install button.
    4. Click OK to start installation.
    5. Close the installation and rails plugins dialog boxes.
    6. Right-click the node of the project and choose run rake task> refresh list from the context menu.
  3. To package an application as a war file, right-click the project node and choose run rake task> war> standalone> Create.

    IDE creates a war file and places it in the top folder of the project.

  4. If you are using a JDBC adapter, you can put a copy of The JDBC client driver of the database serverGlassfish-install-Dir/LibAnd then run (or re-run) The glassfish server.

    During replication, you must use the JDBC adapter unless you are connecting to the MySQL database.

  5. Put a copy of the recently created War file into the autodeploy folder of glassfish. For exampleProjects-Folder/Myrubyapp. WarCopyGlassfish-install-Dir/Domains/domain1/autodeploy.
  6. Enter the URL of the application in the Web browser. For example,Http: // localhost: 8080/myrubyapp.

This article from: http://www.netbeans.com.cn/simple/index.php? T244.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.