2006년 4월 24일 월요일

ruby on rails Eclipse 連携

参考サイト
http://www.napcs.com/howto/railsonwindows.html


Setting up a Rails Development Environment on Windows Using EclipseBy Brian Hogan

Last updated on February 10, 2006 10:14 PM

It looks like the current version of RDT works correctly now. I have rebuilt the entire package from scratch once again to ensure that all of the links are up to date. Things are working now with Eclipse 3.1.2 but the Web Tools pieces require more manual work than before.

I also added a Downloads section where I'll be placing some templates and helper files to speed up the process.

Please, as always, provide some feedback. I can't answer emails about issues not directly related to the setup of this plugin.

If you feel so inclined, a small donation would be much appreciated to help cover bandwidth costs. Thanks for the donations so far.


--------------------------------------------------------------------------------

This is a quick yet detailed guide on how to set up a very easy-to-use development environment for Ruby On Rails. This guide is for Windows users but there's no reason that it couldn't be adapted for Linux users as well. The guide assumes that you already have a working database installed or available and that you have Ruby installed to c:
uby.



Lastly, this is not a guide on how to get started with Ruby on Rails! This is simply one method to create a useful IDE for Rails development.

Download and install Ruby and Rails
Install Eclipse
Configure Eclipse for Rails
Install the Ruby Developer Tools package
Configure the RDT plugin
Launching External Rails Scripts within Eclipse (Now with downloadable goodness! )
Configure Eclipse to Create Rails Projects
Configure Eclipse to Launch WEBrick server
Configure Eclipse to Create Rails Models
Configure Eclipse to Create Rails Controllers
Configure Eclipse to Generate Scaffold for Controllers and Views
Setting up the Favorites
Working with Rails Projects in Eclipse
Configure WEBrick's Output for Eclipse
Create a new Rails Project
Show All Files
Install the DBEdit Eclipse plugin
Connect to a Database
Install Web Developer Tools for Eclipse (Updated!)
Configure Eclipse to handle you View files
Add code hints for the views
Debugging within Eclipse
Setting up Breakpointer
Using Breakpointer
Installing SubClipse
Troubleshooting (Updated!)
Downloads (New!)
Screenshots

--------------------------------------------------------------------------------

Download and install Ruby and Rails
I am operating under the assumption that you're going to use the One-Click Ruby Installer created by Curt Hibbs. If you don't, then you're going to have to modify these instructions yourself.

Download and install the One-Click Ruby Installer for Windows
http://rubyforge.org/projects/rubyinstaller/
These instructions assume you have installed this to c:
uby (the default location)
Open a command prompt and type
gem install rails --include-dependencies

--------------------------------------------------------------------------------

Install Eclipse
Download Eclipse 3.1.2 SDK from http://www.eclipse.org/downloads/index.php
Direct Download
Unzip the files to C:javaeclipse
Make a shortcut to C:javaeclipseeclipse.exe
Start Eclipse and set the workspace to C:javaworkspace
One user had trouble with using the default workspace location for Eclipse, and setting it to a simple path with no spaces solved the problem

--------------------------------------------------------------------------------

Configure Eclipse for Rails
Install the Ruby Developer Tools package
The Ruby Developer Tools plugin is a great set of tools that turn Eclipse into a nice Ruby IDE. The current version (0.6.0 as of this writing) now supports Eclipse 3.1. However, I will continue to use the nightly build for this tutorial.

Launch Eclipse
Choose Help->Software Updates->Find and Install
Choose "Search for new features to install" and select Next
Select "New Remote Site",
Use the name “Ruby Developer Tools”
Use http://updatesite.rubypeople.org/release for the URL
You can use http://updatesite.rubypeople.org/nightly if you wish to use the most current nightly build.
Press OK
Check RDT and push Next
Select the feature RDT and push Next. You should confirm any messages relating to installing unsigned plugins. RDT will be installed and be available after restart.
Configure the RDT plugin
Select Windows > Prefrences > Ruby
Select Installed Interpreters
Click Add
Enter Ruby as the interpreter name (You might want to include the version number if you know it)
Enter the path to your ruby.exe file (usually c:
uby?in
ubyw.exe)
Select OK
Configure the rest of your Ruby settings and then select OK to save the settings.



--------------------------------------------------------------------------------

Launching External Rails Scripts Within Eclipse
You should know that hese settings are tied to your workspace. If you change workspaces then you will need to reconfigure these options. Hopefully the fine developers of RDT will build these into the plugin at some point so they appear on the context menus.

At this point, you're going to want to open the Ruby perspective. To do this, go to Window -> Open Perspective -> Other and choose Ruby

If you don't want to go through the trouble of creating these external tools, you can download this file and unzip it to the root of your c: drive. The files should then extact to c:javaworkspace.metadata.pluginsorg.eclipse.debug.core.launches (assuming you've followed along so far). Be sure to set up the favorites once you import these settings!


Configure Eclipse to Create Rails Projects
Select Run -> External Tools -> External Tools
Select "Program" from the configuration tree
Select New to create a new program
Enter “Create Rails Application in Project” as the name
Enter C:
uby?in
ails.cmd for the Location
Enter ${project_loc} for the Working Directory
Enter ../${project_name} for the Arguments
Select the refresh tab and check Refresh Resources Upon Completion
Select the Common tab
Find the section for Display in Favorites Menu
Check the box next to External Tools
Select Apply
Configure Eclipse to Launch WEBrick server
Select Run -> External Tools -> External Tools
Select "Program" from the configuration tree
Select New to create a new program
Enter “Start WEBrick” as the name
Enter C:
uby?in
uby.exe for the Location
For the Working Directory, use
${project_loc}
Enter scriptserver for the Arguments
Select the refresh tab and check Refresh Resources Upon Completion
Select the Common tab
Find the section for Display in Favorites Menu
Check the box next to External Tools
Select Apply

Configure Eclipse to Create Rails Models
Select Run -> External Tools -> External Tools
Select "Program" from the configuration tree
Select New to create a new program
Enter “Generate Model” as the name
Enter C:
uby?in
uby.exe for the Location
For the Working Directory, use
${project_loc}
Enter for the arguments
script/generate model ${string_prompt:Model name} -f
Select the refresh tab and check Refresh Resources Upon Completion
Select the Common tab
Find the section for Display in Favorites Menu
Check the box next to External Tools
Select Apply
Configure Eclipse to Create Rails Controllers
As many have noted, you could simply duplicate the previous entry and simply change the arguments

Select Run -> External Tools -> External Tools
Select "Program" from the configuration tree
Select New to create a new program
Enter “Generate Controller” as the name
Enter C:
uby?in
uby.exe for the Location
For the Working Directory, use
${project_loc}
Enter for the arguments
script/generate controller ${string_prompt:Controller name} -f
Select the refresh tab and check Refresh Resources Upon Completion
Select the Common tab
Find the section for Display in Favorites Menu
Check the box next to External Tools
Select Apply
(You could just copy the "generate model" example above and change the argument).
Configure Eclipse to Generate Scaffold for Controllers and Views
As many have noted, you could simply duplicate the previous entry and simply change the arguments

Select Run -> External Tools -> External Tools
Select "Program" from the configuration tree
Select New to create a new program
Enter “Generate Scaffold” as the name
Enter C:
uby?in
uby.exe for the Location
For the Working Directory, use
${project_loc}
Enter for the arguments
script/generate scaffold ${string_prompt:Model name} ${string_prompt:Controller name} ${string_prompt:Actions separated with spaces} -f

Select the refresh tab and check Refresh Resources Upon Completion
Select the Common tab
Find the section for Display in Favorites Menu
Check the box next to External Tools
Select Apply
Setting Up the Favorites
Sometimes, all of these external commands won't show up under the External Commands icon. We can fix that by making them "Favorites".

Select Run > External Tools > Organize Favorites
Add each external tool that you want to appear on your menu of External Tools
Select Add...
Select the tools you wish to add to your menu and press OK
Use the Up and Down buttons to change the order of the items in the menu
Select OK to save the items

--------------------------------------------------------------------------------

Working with Rails Projects in Eclipse
Configure WEBrick's Output for Eclipse
For some strange reason, WEBrick's output doesn't always get piped to Eclipse's console. We can hack this a bit to make this work for us. We need to add these two lines to the Rails server script:

Provided that you've installed Ruby to c:
uby as instructed above, you can navigate to

C:
ubylib
ubygems1.8gems
ails-0.13.1?in

and edit the server file with a good text editor (anything except for notepad or wordpad).

Add this to the second line of the script:

$stdout.sync=true
$stderr.sync=true

Alternatively, you could just add these two lines to WEBrick once you've created your Rails project by modifying the server file under /scripts in your Rails project.

Create a new Rails Project
Select File > New > Other : Ruby > Ruby Project
Enter a name for your project.
This name will be the name you'll use for your Rails project name when you generate the Rails application files
Make sure to use the Eclipse Workspace for the project contents!
Select the project in the Ruby Resources view
Go to Run -> External Tools and choose Create Rails Project. A few seconds later, your Eclipse Console should show the results of the file creation and your file project tree should be populated with your ruby files.
At this point, you'll want to edit your config/database.yml file with your database properties.
Show All Files
Under Ruby Resources, select the down arrow icon and deselect Show Ruby Files Only so you can see all the files in your project and not just the .rb files (If you don't see Ruby Resources, it's most likely because you didn't change to the Ruby perspective. (Eclipse defaults to the Java perspective!)


--------------------------------------------------------------------------------

Install the DBEdit Eclipse plugin
The DBEdit plugin for Eclipse will allow you to view and edit your database tables from Eclipse as well as run various SQL statements against your database.

Shut down Eclipse
Download the DBEdit plugin version 1.0.3_1 from http://prdownloads.sourceforge.net/dbedit/dbedit_1.0.3_1.bin.dist_3.X.zip?download
Unzip the file to your c:javaeclipse folder. The file should place new files in your features and plugins folder.
Download and the appropriate driver for your database
MySQL
http://www.mysql.com/products/connector/j/
Microsoft SQL Server
http://www.microsoft.com/downloads/details.aspx?familyid=9F1874B6-F8E1-4BD6-947C-0FC5BF05BF71&displaylang=en

SQLite:
If anyone gets this to work for Windows, please send me instructions!
Extract the contents of this driver to c:javadrivers
Launch Eclipse
Select Window -> Show View -> Other
Select DBEdit and choose Tables
Connect to a Database
Connecting to a database is pretty straight-forward. I'll use MySQL for an example. In this article, I assume you're using MySQL 4.1 and that you have installed the appropriate driver.

Right-click anywhere in the whitespace of the Tables pallette and select Connection -> Configure from the popup menu
Select New
Enter a name for the connection in the Name field
Select the Classpath tab and press Add to Archive. Navigate to your drivers folder and select the appropriate driver jar file.
For MySQL, choose mysql-connector-java-3.1.12-bin.jar
Select the Commom tab
Select com.mysql.jdbc.Driver for the Driver
Enter jdbc:mysql://host/dbname for your database
Enter your database username
For MySql, remove the entry in the Schema field!
Enter your passwod and select Save Password
Press Connect to save and connect to the database.
You can go to Window -> Show View -> Other ->DBEdit ->Instant SQL to bring up a SQL editor panel. Here you can execute statements against your database!

--------------------------------------------------------------------------------

Install Web Developer Tools Plugin for Eclipse
There is a great plugin bundle for JSP development that we can take advantage of for our Rails development. The WTP plugin has a very versatile CSS, XML, and HTML editor

Download the following files:
EMF SDK version 2.1.1 or higher emf-sdo-xsd-SDK-2.1.1.zip
GEF SDK 3.1.1 or higher GEF-SDK-3.1.1.zip
JEM SDK 1.1.0.1 or higher JEM-SDK-1.1.0.1.zip
Download the Web Tools plugin from http://www.eclipse.org/downloads/download.php?file=/webtools/downloads/drops/R-1.0-200512210855/wtp-1.0.zip (~24 MB)
Unzip each file to C:java, overwriting any files.
Restart Eclipse.
Now, when you open your CSS or HTML files, you'll be able to use auto complete for elements and attributes, as well as create templates.

Opening the Properties view will let you inspect the attributes and properties of the element you select, and opening the Outline view will show you a representation of your document model.

Configure Eclipse to handle your Rails Presentation files
Eclipse can handle your rhtml files with syntax highlighting! All you have to do is associate the .rhtml extention with the JSP editor. Once you do that, you can add templates for all of the ActionView helper functions to make development even easier.

Select Window -> Preferences
Expand the General section
Select the Content Types option
Expand Text
Select JSP
Select Add
Enter *.rhtml and press OK
Select Add
Enter *.rxml and press OK
Press OK to save the changes
Add Code Hints for the Views
Now, let's add the Rails Link_to tag to the templates library

Selct Window -> Preferences
Expand the Web and XML section
Expand the JSP Files section
Select JSP Templates
Select New
Enter link_to for the name
The context should be ALL JSP
Automatically Insert should be checked
Enter the following for the pattern:
<%= link_to "${url}", :controller=>"${controller}", :action=>"${action}", :id=>"${id}" %>

Create a new .rhtml file and press CTRL+Spacebar

Your Link_to tag should be in that list. When you type the < character, your list of options should appear. Type link to filter the list of results.

When the template is first inserted, the cursor is placed at the url variable, if you hit tab, it will cycle to the next variable in the list.

You can repeat these steps with other helper tags to speed up development. To get you started, I've provided this starter template. Import this into the JSP Templates section via the Import button.



Debugging in Eclipse
Ruby on Rails has some interesting techniques to debug projects. One technique is the Breakpointer script. The Breakpointer connects an IRB session to your running web application.

Setting up Breakpointer
Select Run -> External Tools -> External Tools
Select New to create a new program
Enter “Start Breakpointer ” as the name
Enter C:
uby?in
uby.exe for the Location
For the Working Directory, use
${project_loc}
Enter script?reakpointer for the Arguments
Select the refresh tab and check Refresh Resources Upon Completion
Select the Common tab
Find the section for Display in Favorites Menu
Check the box next to External Tools
Select Apply
Using Breakpointer
In your project, place the following line of code in any method where you want to stop code execution:
breakpoint
Start up WEBrick:
Go to Run -> External Tools ->Start WEBrick
Start up Breakpointer
Go to Run -> External Tools ->Start Breakpointer
Open a browser and navigate to your project (should be at port 3000)
Once you hit your breakpoint, return to Eclipse and you should see an IRB console that you can use to inspect your local variables, objects, request data and session data.
To stop processing the breakpoint and allow the application to continue, type exit in the console. Breakpointer will begin waiting for a new breakpoint.

--------------------------------------------------------------------------------

Installing SubClipse
If you use Subversion (and you should if you're serious about Rails development) then you can install the SubClipse SubVersion client plugin.

Visit http://subclipse.tigris.org/install.html and follow their directions, or simply follow the same process as RDT and use their update site at http://subclipse.tigris.org/update

Choose Help->Software Updates->Find and Install
Choose "Search for new features to install" and select Next
Select "New Remote Site ",
Use the name “SubClipse”
Use the URL: http://subclipse.tigris.org/update
Press OK
Check SubClipse and push Next
Select the feature RDT and push Next. You should confirm any messages relating to installing unsigned plugins. RDT will be installed and be available after restart.

--------------------------------------------------------------------------------



Troubleshooting
DBEdit gives me errors when I attempt to connect to MySQL
"Fetching children of MySQL" is a common error that I've seen. It seems to be related to the version of DBEdit that you use. SourceForge isn't very helpful with the proper version; sometimes you get lucky. If you get this error, uninstall DBEdit and redownload a new version.
I used Cygwin and all the paths in your tutoral arewrong. You should change them or make a note about this.
You're on your own. This guide uses a specific method. It can easily be adapted for other uses, such as Cygwin or even Linux. However, please understand that I can't support all of those configurations. Compared to developing useful web applications, configuring these plugins should be pretty easy.
When I try to run one of the external programs, I get an error stating something about "not valid in prolog"
You probably set up all of your external apps as Ant Buids instead of programs.

The breakpointer hangs up on me... I can't exit out
Just hit the red stop button on the console to kill the breakpointer. Do the same for the console that contains WEBrick.

When I run one of the external programs, the message says "variable references empty selection"
It usually means that the project isn't selected. Just click on the project name before you run one of the programs.

I've set up SubClipse but whenever I try to open one of the SubClipse views, it says my workspace path is invalid and needs to be changed. The suggested path for the change is the same path I'm currently using!
SubClipse is picky. It wants the drive letter to be capitalized. Change your workspace path from c:javaworkspace to C:javaworkspace and restart Eclipse
Downloads
externals.zip
External Programs launchers for
Create Rails Structure in Project
Generate Model
Generate Controller
Generate Scaffold for Model and Controller
Generate Migration
Install Plugin via SVN
Rake
Start Breakpointer
Start Webrick Server
Open Explorer in Project Folder
Command Prompt
Start Console
rails-model-controller.xml
Contains code templates for various Ruby on Rails code methods. Import this into Ruby Templates
rails-rhtml.xml
Contains code templates for various Rails helpers used in views. Import into JSP Templates


--------------------------------------------------------------------------------

That about does it. I'll keep looking for other things to add to this procedure since this is the method I am now using for my development environment. If anyone has any feedback that I should add, please send it to railsdev@napcs.com

Thanks to Tom Davies for his comments regarding project locations and his tips about the Rails templates.

Thanks to Chris Williams for the information about WEBrick's output.

Thanks to everyone on the RDT team for working so hard on a great plugin.


--------------------------------------------------------------------------------

Brian Hogan is the owner of New Auburn Personal Computer Services, a small web design company that specializes in standards-based design and accessibility for the disabled. He has been developing web sites for ten years. He also works at the University of Wisconsin-Eau Claire where he oversees development of various web-based applications.


Site design and content copyright © 2003 New Auburn Personal Computer Services, All rights reserved. Unauthorized duplication or republication in any form is not allowed.

2006년 4월 17일 월요일

eclipse external Tool

Eclipse 에서 포커스가 잡혀 있는 파일 업로드시
포커스가 잡힌 파일명을 돌려주는 Arguments
${file_prompt}

2006년 4월 4일 화요일

L2,L3,L4

http://cafe.naver.com/yjk017654/221 님의 글을 퍼왔습니다.


L2스위치, L3스위치,L4스위치 |

http://cafe.naver.com/yjk017654/221

예를 들어 A에서 보낸 팻킷이 포트 1로 들어왔다고 합시다.

그러면 L2 스위치는 포트 1에 A가 붙어있다는 정보를 얻게 됩니다.

그래서 나중에 A로 보내져야할 팻킷이 들어오게 되면 포트 1로 내보내게 됩니다.

L3의 경우는 L2와 달리 매우 넓은 범위까지 다루게 됩니다.

그래서 오가는 팻킷을 관찰해서는 충분한 정보를 얻을 수가 없습니다.

그래서 L3 스위치끼리 통신을 하면서 정보를 축적하게 됩니다.

예를 들어 포트 1에 연결되어 있는 스위치가 여기에는 팻킷이 많이 몰린다는

내용을 보낸다면, 그 내용을 받은 스위치는 팻킷을 포트 1 대신 다른 포트로

보내게 됩니다.



L4스위치

여러대의 서버에 똑같은 컨텐츠를 탑재하는 경우는 L4에서 서버의 부하를 체크해서 가장

여유있다고 판단되는 쪽으로 보내게 됩니다.(정책이 여러개 있는데, 이방식을 가장 많이 사용합니다.)

일반 기업에서 ERP서버나 업무용서버를 운영할 때 많이 사용하는 방식입니다.

서버별로 컨텐츠가 다르다면, L4에서 정책을 세워서 해당 서비스에 대한 요청이 오면 등록된 서비스로

보내주어서 전체 부하를 분산시키는 방식을 사용합니다. 대형 포탈의 경우 이런 방식을 사용하겠죠.

그리고 대부분 DB서버는 L4를 거치지 않고 웹서버와 직접 연결시켜서 사용합니다. DB서버 분산하는게 쉽지 않기 때문에 DB를 L4에 물리는 경우는 드물죠.


세그먼트(segment)에 대해 설명드리면, 한 컴퓨터에서 발생한 신호가 수신자에 상관없이 전달되는 범위를 말합니다. 즉, 내 컴퓨터에서 자료를 보내려고 신호를 내보내면 이 신호가 일정 지역내의 모든 컴퓨터에게 전달이 되는데 그 범위를 말합니다. 그런데, 하나의 세그먼트에서는 동시에 2개의 신호가 전달될 수 없습니다. 예를 들면, 두사람이 동시에 자기 얘기만 하면 무슨소린지 모르고 충돌이 발생하듯이 하나의 세그먼트 내에서 동시에 2개 이상의 전기적인 신호가 발생하면 충돌이 발생합니다.
그럼, 여기서 한가지 생각해 보시면, 하나의 세그먼트가 컴퓨터 1000대로 구성이 되어 있다고 보면 1000대중에서 내 컴퓨터가 자료를 보내려고 하면 많은 시간을 기다려야 할 수도 있고, 충돌이 자주 발생할 수도 있습니다. 그래서~ 세그먼트를 분리시키고자 등장한 장비가 브리지(스위치는 브리지를 개량한 장비)입니다.
브리지(bridge)는 한마디로 요약하면 세그먼트를 분리시켜주는 장비입니다. 예를 들면 1000대의 컴퓨터를 100대씩 묶어서 10개의 세그먼트을 만들어 주는 장비 입니다. 이렇게 분리된 세그먼트에서 자료 교환을 중재하는 역할을 브리지가 하게 됩니다.
예를 들어 세그먼트1에 있는 컴퓨터가 세그먼트1에 있는 컴퓨터로(즉, 같은 세그먼트)데이터를 전송하면 이 신호가 다른 세그먼트에 전송이 되지 못하도록 신호를 차단하구요, 세그먼트1에서 세그먼트2로 데이터를 보내면 브리지가 이 신호를 받아서 세그먼트2로 보내줍니다. 이렇게 하면 세그먼트가 분리되어서 컴퓨터끼리 자료 교환하는데에 충돌이나 기다림(병목현상?)이 줄어들겠지요.
이제, 스위치와 라우터에 차이점을 설명 드리면.. 세그먼트를 분리시킨다는 의미에서는 같다고 보시면 됩니다. 차이점은.. 어떤걸 기준으로 분리를 시키느냐 입니다.
스위치에 여러가지 포트(하나의 포트를 하나의 세그먼트로 보셔도 될겁니다.)가 있는데, 각 포트에 어떤 컴퓨터가 연결이 되어 있는지 판단하는 것은 MAC(Media Access Control)주소 입니다. 간단히 말하면 LAN카드 번호 입니다. 이 번호는 공장에서 나올때부터 고유하게 지정된 번호로써 전세게 LAN카드가 다 다른 번호를 가지고 있습니다. 스위치는 이 번호를 가지고 스위치 장비 내부에 '표'를 하나 만들어 놓고, 포트1에는 어떤 MAC주소가 있으며, 포트2에는 어떤 MAC주소가 있는지 적어 놓습니다. 그래서, 이 표를 기준으로, 스위치로 들어오는 신호를 읽어 들여서 같은 포트의 MAC주소를 목적지로 하고 있으면 다른 포트로 데이터를 보내지 않고, 다른 포트의 MAC주소를 목적지 주소로 가지고 있으면 그곳으로 연결 시켜 줍니다.
라우터는 세그먼트를 구분하는 기준이 IP입니다. 라우터도 내부적으로 표를 만들어 놓는데 기준이 IP입니다. 따라서, 라우터로 들어오는 신호를 읽어들여서 목적지가 같은 포트(즉, 같은 세그먼트)의 IP이면 다른 포트로 신호를 보내지 않으며 다른 포트의 세그먼트의 컴퓨터가 목적지 IP이면 그 포트로 연결시켜 주는 역활을 합니다.
라우터의 역할을 보시면 알겠지만, IP를 기준으로 세그먼트를 나눕니다. 그래서, 인터넷과 독립적으로 LAN을 구축할 경우 라우터는 필요 없습니다. 하지만, 인터넷과 연결시켜서 LAN을 구축할 경우 반드시 필요한 장비가 라우터 입니다