IDE 統合
Eclipseとの統合
| Excerpt |
|---|
|
Eclipse Integration |
Grailsプロジェクトのインポート方法
| Excerpt |
|---|
|
Importing a Grails Project |
| Excerpt |
|---|
|
Grails automatically creates Eclipse project and classpath files for you, so to import a Grails project just right-click in the "Package Explorer" and select "Import" then "Existing project into Workspace" and "Browse" to the location of your project. |
Grailsは自動で、.project と.classpath ファイルを生成します。Eclipseのパッケージ・エクスプローラで右側クリックをして"インポート..."を選択、"既存のプロジェクトをワークスペースへ"を選択した後 "参照..."でプロジェクトの位置を指定.
| Excerpt |
|---|
|
Then immediately click "Ok" followed by "Finish" and your project will be set-up. |
"終了"を押した後 "Ok"を押せばプロジェクトがセットアップされます.
| Note |
|---|
| Excerpt |
|---|
| You need to create an Eclipse classpath variable called GRAILS_HOME that points to the location where you installed Grails for the project to build successfullly by going to Windows -> Preferences... -> Java -> Build path -> Classpath Variables -> New. | 正常にビルドするためには、ウインドウ ->設定... ->Java ->ビルドパス ->クラスパス変数 ->新規... より、Grailsをインストールした場所を表すクラスパス変数「GRAILS_HOME」を作成する必要が有ります。 |
| Excerpt |
|---|
|
Also, if you are using JSP you will need to add your JDK's tools.jar library to your project classpath otherwise jetty will display compilation errors. See this page for info: |
また、JSPを使用するのであれば、jettyでのコンパイルエラーを回避するために、JDKのtools.jarライブラリの設定が必要です。詳しくは以下のページを参照:
http://nuin.blogspot.com/2005/05/launch-jetty-from-eclipse-solving.htmlGrailsアプリケーションを実行させる
| Excerpt |
|---|
|
Running a Grails application |
| Excerpt |
|---|
|
Grails also automatically creates an Eclipse run configuration for you. To run the project you are in use the "Run" dropdown to open the "Run" dialog then under "Java Applications" find the name of your project select it and click "Run". The Grails application will load embedded inside Eclipse, any changes made inside the Eclipse project can be auto-reloaded. |
Grailsは、Eclipseの実行定義を自動で作成します。プロジェクトを実行するには、"実行"メニューより、"構成および実行"ダイアログを開き"Javaアプリケーション"以下にある、実行したいプロジェクト名を選択して"実行"ボタンをクリック。Grails アプリケーションは Eclipse 内部で実行され、 Eclipse プロジェクト内で変更したすべての内容を
自動でリロードします。
| Excerpt |
|---|
|
If you are getting exceptions like |
もし以下のような例外が発生したら
| Code Block |
|---|
org.mortbay.util.MultiException[java.io.FileNotFoundException: {yourpath}/tmp/war]
at org.mortbay.http.HttpServer.doStart(HttpServer.java:731)
at org.mortbay.util.Container.start(Container.java:72)
at grails.util.GrailsMain.main(GrailsMain.java:67)
|
| Excerpt |
|---|
|
then you need to do is run the ant target: |
以下のantターゲットを実行してください:
| Code Block |
|---|
grails dev package
|
| Excerpt |
|---|
|
which will package up grails into the tmp/war directory in the same way as the "grails run-app" command will. This is then used as the base for eclipse to execute. |
Eclipseでステップ・デバッグする
| Excerpt |
|---|
|
Step Debugging with Eclipse |
| Excerpt |
|---|
|
You can step debug a Grails application if you install the latest build of the Groovy Eclipse plug-in. What you need to do is the following: |
最新ビルドの
Groovy EclipseEclipseプラグインをインストールすることによって、Grailsアプリケーションをステップ・デバッグすることが出来ます。方法は以下を実行:
| Excerpt |
|---|
|
- Open up the Groovy file you want to debug (lets say a controller called
BookController.groovy) then set a break point on the line you want to stop at.
|
- デバッグしたいファイルを開き(
BookController.groovy だとします)ブレークポイントを停止したい行にセット。 | Excerpt |
|---|
|
- Now debug the application in the same way as you did in the above section on "Running a Grails application" except with the "Debug" menu.
|
- "Grailsアプリケーションを実行させる"で行ったことと同じ方法で、今回は"構成およびデバッグ"にて、アプリケーションをデバッグ実行。
| Excerpt |
|---|
|
- Load your browser and navigate to the action that calls the code.
|
- ブラウザーで該当のアクションをロード
| Excerpt |
|---|
|
Eclipse should then stop at the appropriate place and you can then inspect variables and step through the code. If you have the Grails source code set-up on your Source path you can step into that code too. |
Eclipseで、適切な位置に停止することができ、変数を検証したり、コードをステップ・デバッグすることができます。Grailsソースコードをソースパスに設定すれば、Grailsソースコードもステップインすることができます。
ドメインクラスの追加、その他、
| Excerpt |
|---|
|
Adding domain classes etc. |
| Excerpt |
|---|
|
You can configure grails as an "External Tool", allowing you to create domain classes etc. from within Eclipse: |
grailsを外部ツールとして定義できます、Eclipseでドメインクラスの作成などが可能になります:
| Excerpt |
|---|
|
- Select "Run > External Tools > External Tools...".
- Enter a name of "Grails".
- Browse the filesystem for the location of grails or grails.bat.
- Set the working directory to "${project_loc}".
- Set the arguments as "${string_prompt}".
- Under the "Refresh" tab, set to refresh the "project containing the selected resource" upon completion.
- Under the "Common" tab, tick "Display in favorites menu".
|
- "実行 > 外部ツール > 外部ツール... "を選択。
- プログラム以下に、"新規の起動構成"で新規起動構成作成、名前に"Grails"と入力。
- ローケーションの、"ファイル・システムの参照..."より、grails.bat 又は、grailsを場所を設定。
- 作業ディレクトリーを、"${project_loc}" に設定。
- 引数を"${string_prompt}"に設定。
- "更新"タブ内、"完了時にリソースを更新"にチェック、"選択されたリソースを含むプロジェクト"を選択。
- "共通"タブ内、"お気に入りのメニューに表示"内の"外部ツール"にチェック。コンソールエンコードを"UTF-8"に設定。
| Excerpt |
|---|
|
You can then run Grails by clicking the down arrow next to the external tool icon (run with a suitcase) and selecting "Grails", for example: |
これで、Grailsの起動を外部ツールアイコン(スーツケース付きのアイコン)より"Grails"を選択で出来るようになります。| Excerpt |
|---|
|
- Choose "Grails" from the external tools drop-down.
- Enter "create-domain-class" in the dialogue box.
- In the console window, follow the prompts as normal.
- Open your new class from grails-app/domain.
|
- 外部ツールのドロップダウンメニューより"Grails"を選択。
- ダイアログボックスに"create-domain-class"を入力。
- コンソールウインドウにて、通常通り操作。
- grails-app/domain より新しいクラスを開く。
トラブルシーティング
| Excerpt |
|---|
|
If you getting following error every time you save *.groovy file in project: |
1) *.groovyファイルを保存する際に、以下のようなエラーがでる場合:
| Code Block |
|---|
An internal error occurred during: "Building workspace".
BUG! exception in phase 'conversion' in source unit '...' Error:
duplicate class declaration for name: ... and class:
org.codehaus.groovy.ast.ClassNode@...[name:...]
|
check following instruction:
以下の内容を確認してください:
| Excerpt |
|---|
|
- Right click on package explorer's project name and open "Properties..." dialog.
- Select "Builders" and make sure that "Groovy Builder" is checked.
- Select "Java Compiler/Building" and check "Enable project specific settings".
- Append ".groovy" to "Filtered Resources" text field, to prevent ".groovy" files being copied to the output directory. Note that the path separator is "," not ";"
- Apply changes and close dialog.
- Clean your project. Make sure that the output directory doesn't contain "*.groovy" files
|
- パッケージ・エクスプローラで右側クリックをして "プロパティー" ダイアログを開く。
- "Groovy Builder"にチェックがさせているか、"ビルダー"内を確認。
- "Java Compiler/Building" を選択して"Enable project specific settings"にチェックをいれる。
- "出力フォルダ"の"フィルターするリソース"に、"*.groovy"を追加。セパレーターは","です、";"ではありません。
- 変更を適用して、ダイアログを閉じます。
- プロジェクトをクリーンします。アウトプットディレクトリに"*.groovy"ファイルが含まれないのを確認。
| Excerpt |
|---|
|
2) If Eclipse complains that it can not find the sources where breakpoitns are set ensure the following: |
2) Eclipseからブレークポイントがセットされたところにソースが見つからないといわれた場合は以下を確認してください。
- Step filtering is enabled for groovy.*, org.codehaus.* (more about this http://groovy.codehaus.org/Debugging+with+Eclipse )
- Build out put for the project is in a separate folder (say /bin ). Make sure this is present for Project->Properties->Groovy Project Properties
| Excerpt |
|---|
|
3) Few other recommendations: |
3) その他、下記のことをおすすめします。
| Excerpt |
|---|
|
- Make sure to add all the libraries from grails-app/lib folder to the project
|
- grails-app/libに入っている全てのライブラリをEclipseのプロジェクトに追加したか確認。
| Excerpt |
|---|
|
- Using verbose logging/tracing through log4j.properties until everything works from the Eclipse IDE. Sometimes if some library is not found, unless it is printed in the console, it is difficult to find out what went wrong.
|
- Eclipse IDE上で全て正常に動くまでlog4j.propertiesのverbose logging/tracingを使用すること。いくつかのライブラリが見つからない場合、もしくはコンソールに出力された場合、間違った箇所を特定することが困難になります。
| Excerpt |
|---|
|
- Make sure to use the same JDK for tools.jar as well as the runtime
|
- ランタイムと同様、tools.jarに同じJDKを必ず使用してください。
| Excerpt |
|---|
|
- Sometimes "launch configuration" generated by grails is not in sync with the way ant's build.xml works. In Grails 0.3 ensure that following VM parameters (do note not program arguments, but VM arguments ) are set "-Dorg.mortbay.xml.XmlParser.NotValidating=true". Without this there will be XML Parser exception thrown when launched from the IDE.
|
- 時々、grailsから生成された"launch configuration"が ant の build.xml と同期しない場合があります。Grails 0.3の場合はVMのパラメータ(プログラムのargumentsではなくVMのarguments)が"-Dorg.mortbay.xml.XmlParser.NotValidating=true"のように設定されているか確認してください。この設定が無い場合、IDEからの起動時にXML Parserの例外が投げられる場合があります。