如果要在gameGarden下开发游戏的话,因为游戏会运行在sandbox中,服务端和客户端都将用ant任务来启动,这给开发调试带来了很多的困难。下面介绍一种可以在eclipse中调试ant任务的方法。
首先在build.xml中复制server任务到一个新的任务,比如叫做server-debug,在启动虚拟机的时候加入下面的这条语句。
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=5005,server=y"/>
<!-- a target for running the game server in debug mode -->
<target name="server-debug" depends="compile" description="Runs a test server.">
<propertyfile file="${deploy.dir}/classes/toybox.properties">
<entry key="resource_dir" value="${deploy.dir}"/>
<entry key="resource_url" value="file://${deploy.dir}"/>
</propertyfile>
<!-- we have to convert basedir to forward slashes to make it work as a URL -->
<path id="codedir"><pathelement location="${basedir}/../lib"/></path>
<pathconvert targetos="unix" property="basedir.unix" refid="codedir"/>
<!-- we also have to stick an extra / in front of basedir.unix to make -->
<!-- things work on windows, fortunately it does not booch things on unix -->
<echo file="${deploy.dir}/server.policy">
grant codeBase "file:///${basedir.unix}/../lib/-" {
permission java.security.AllPermission;
};
</echo>
<java classname="com.threerings.toybox.server.ToyBoxServer" fork="true">
<classpath refid="classpath"/>
<sysproperty key="java.security.manager" value=""/>
<sysproperty key="java.security.policy" value="${deploy.dir}/server.policy"/>
<sysproperty key="game_conf" value="${app.name}.xml"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=5005,server=y"/>
</java>
<delete file="${deploy.dir}/classes/toybox.properties"/>
<delete file="${deploy.dir}/server.policy"/>
</target>
这时候在eclipse中调出ant视图,运行该server-debug任务,这会儿只会在控制台会输出
Buildfile: D:\Java\threerings\gardens\projects\games\five\build.xml
prepare:
compile:
server-debug:
[propertyfile] Updating property file: D:\Java\threerings\gardens\projects\games\five\dist\classes\toybox.properties
[java] Listening for transport dt_socket at address: 5005
然后在菜单中选择run-->debug configurations...选择remote java application,在port这一栏里填入前面加到jvm参数中的5005,再点击apply和debug,这时候在控制台就会正常输出,并且可以加入断点调试了。
本文介绍如何在eclipse环境下调试ant任务,通过在build.xml文件中修改server任务并加入特定参数,实现通过控制台输出进行调试,并提供详细步骤和配置说明。
248

被折叠的 条评论
为什么被折叠?



