因为正在做的项目最终要deploy到Tomcat,并且要用到Tomcat中的security role,所以找到了一种方法可以在Tomcat
+Eclipse的环境debug Grails Application.
Environment:
- Windows XP
- Eclipse 3.5
- Tomcat 6.0.20
1. Install Eclipse
相信大家都知道怎么做
2. Install Tomcat 6.0.20, configure Tomcat plugin in Eclipse
preferences->Tomcat, set your Tomcat home
3. Install Sysdeo Tomcat plugin V321
http://www.eclipsetotale.com/tomcatPlugin.html
4. Create a Grails app
5. Create grails-app/conf/BuildConfig.groovy
import grails.util.GrailsUtil
appName="yourProjectName";
switch (GrailsUtil.getEnvironment()) {
case "production":
grails.war.exploded=false;
grails.project.work.dir = "${grailsSettings.grailsWorkDir}/
projects/${appName}/stage-production";
break;
case "development":
grails.war.exploded=true;
grails.project.work.dir = "${grailsSettings.grailsWorkDir}/
projects/${appName}/stage-development";
break;
case "test":
grails.war.exploded=false;
grails.project.work.dir = "${grailsSettings.grailsWorkDir}/
projects/${appName}/stage-test";
break;
}
6. Modify build.xml, change grails macro to be the following:
<macrodef name="grails">
<attribute name="script" />
<attribute name="args" default="" />
<attribute name="env" default="production" />
<sequential>
<grailsTask script="@{script}" args="@{args}"
classpathref="grails.classpath" environment="@{env}">
<compileClasspath refid="compile.classpath" />
<testClasspath refid="test.classpath" />
<runtimeClasspath refid="app.classpath" />
</grailsTask>
</sequential>
</macrodef>
7. Modify build.xml, change
<property name="web.deploy.properties" value="${basedir}/
deploy.properties" />
<property name="rpm.version" value="1" />
<property name="rpm.release" value="1" />
<target name="war" depends="-init-grails" description="-->
Creates a WAR of a Grails application">
<grails script="Clean" />
<property file="${web.deploy.properties}" />
<grails script="War" args="${
ant.project.name}-${deploy.env}-$
{rpm.version}-${rpm.release}.war" env="${deploy.env}" />
</target>
<target name="-init-dev">
<copy file="${basedir}/deploy-dev.properties" tofile="$
{web.deploy.properties}" overwrite="true" />
</target>
<target name="war-dev" depends="-init-dev,war" description="Build war
for development" />
8. create deploy-dev.properties
deploy.env=development
9. Run Ant task, war-dev
You will see the task generate unpacked war in the path you configured
in BuildConfig.groovy.
10. Create your projectName.xml under tomcat_home/conf/Catalina/
localhost
<?xml version="1.0" encoding="UTF-8"?>
<Context path="yourProjectName" docBase="yourProjectWorkingDir/stage"
privileged="true"
antiResourceLocking="false"
antiJARLocking="false"
reloadable="true">
</Context>
11. Now, you are able to debug Grails app in Tomcat, and Eclipse.
Click Sysdeo Tomcat Run button, put a break point in your controller,
your will see how the debug works.
希望这些内容对大家有用。
Xinwangw