Last updated by admin 5 years ago

IDE ?? {excerpt:hidden=true}IDE Integration {excerpt}

Eclipse???? {excerpt:hidden=true}Eclipse Integration {excerpt}

Grails?????????????? {excerpt:hidden=true}Importing a Grails Project {excerpt}

{excerpt:hidden=true}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. {excerpt} Grails?????.project ?.classpath ???????????Eclipse????????????????????????"?????..."????"??????????????????"?????? "??..."?????????????. {excerpt:hidden=true}Then immediately click "Ok" followed by "Finish" and your project will be set-up. {excerpt} "??"????? "Ok"?????????????????????.
{excerpt:hidden=true}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. {excerpt}?????????????????? ->??… ->Java ->????? ->??????? ->??… ???Grails??????????????????????GRAILS_HOME??????????????
{excerpt:hidden=true}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: {excerpt} ???JSP???????????jetty???????????????????JDK?tools.jar???????????????????????????? http://nuin.blogspot.com/2005/05/launch-jetty-from-eclipse-solving.html

Grails?????????????? {excerpt:hidden=true}Running a Grails application {excerpt}

{excerpt:hidden=true}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. {excerpt} Grails??Eclipse?????????????????????????????"??"???????"???????"????????"Java????????"???????????????????????"??"?????????Grails ????????? Eclipse ???????? Eclipse ?????????????????????????????? {excerpt:hidden=true}If you are getting exceptions like {excerpt} ????????????????
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:hidden=true}then you need to do is run the ant target: {excerpt} ???ant???????????????
grails dev package
{excerpt:hidden=true}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. {excerpt}

Eclipse???????????? {excerpt:hidden=true}Step Debugging with Eclipse {excerpt}

{excerpt:hidden=true}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: {excerpt} ??????Groovy EclipseEclipse?????????????????????Grails????????????????????????????????????? {excerpt:hidden=true}
  • 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.{excerpt}
  • ??????????????( {{BookController.groovy}} ?????)???????????????????? {excerpt:hidden=true}
        • 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.{excerpt}
  • "Grails??????????????"????????????????"?????????"??????????????????? {excerpt:hidden=true}
        • Load your browser and navigate to the action that calls the code.{excerpt}
  • ?????????????????? {excerpt:hidden=true}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. {excerpt}
Eclipse??????????????????????????????????????????????????Grails???????????????????Grails??????????????????????? {excerpt:hidden=true}_Note: With Eclipse 3.2 and latest Groovy Eclipse plug-in this doesnt work on Windows OS.Refer to_ http://jira.codehaus.org/browse/GRAILS-277 _for description. _ {excerpt}

??????????????? {excerpt:hidden=true}Adding domain classes etc. {excerpt}

{excerpt:hidden=true} You can configure grails as an "External Tool", allowing you to create domain classes etc. from within Eclipse: {excerpt} grails????????????????Eclipse??????????????????????{excerpt:hidden=true}
  1. Select "Run > External Tools > External Tools...".
  2. Enter a name of "Grails".
  3. Browse the filesystem for the location of grails or grails.bat.
  4. Set the working directory to "${project_loc}".
  5. Set the arguments as "${string_prompt}".
  6. Under the "Refresh" tab, set to refresh the "project containing the selected resource" upon completion.
  7. Under the "Common" tab, tick "Display in favorites menu".{excerpt}
  8. "?? > ????? > ?????… "????
  9. ?????????"???????"?????????????"Grails"????
  10. ?????????"????????????..."???grails.bat ???grails???????
  11. ???????????"${project_loc}" ????
  12. ???"${string_prompt}"????
  13. "??"????"???????????"??????"??????????????????"????
  14. "??"????"?????????????"??"?????"?????????????????"UTF-8"????{excerpt:hidden=true} 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: {excerpt}
????Grails?????????????(?????????????)??"Grails"???????????????{excerpt:hidden=true}
    1. Choose "Grails" from the external tools drop-down.
    2. Enter "create-domain-class" in the dialogue box.
    3. In the console window, follow the prompts as normal.
    4. Open your new class from grails-app/domain.{excerpt}
  1. ???????????????????"Grails"????
  2. ??????????"create-domain-class"????
  3. ????????????????????
  4. grails-app/domain ????????????

?????????? {excerpt:hidden=true}Troubleshooting {excerpt}

{excerpt:hidden=true}If you getting following error every time you save *.groovy file in project: {excerpt} 1) *.groovy???????????????????????????
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:hidden=true}
  • 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{excerpt}
  • ??????????????????????? "??????" ?????????
  • "Groovy Builder"?????????????"????"?????
  • "Java Compiler/Building" ?????"Enable project specific settings"??????????
  • "??????"?"???????????"??"*.groovy"???????????","???";"????????
  • ???????????????????
  • ????????????????????????????"*.groovy"???????????????
2) If Eclipse complains that it can not find the sources where breakpoitns are set ensure the following:
  • 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
3) Few other recommendations:
  • Make sure to add all the libraries from grails-app/lib folder to the project
  • 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.
  • Make sure to use the same JDK for tools.jar as well as the runtime
  • 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.