在eclipse中调试ant任务

如果要在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,这时候在控制台就会正常输出,并且可以加入断点调试了。

你可能感兴趣的:(java,eclipse,游戏,unix,ant)