eclipse 调试 ant中运行的java

如果要在gameGarden下开发游戏的话,因为游戏会运行在sandbox中,服务端和客户端都将用ant任务来启动,这给开发调试带来了很多的困难。下面介绍一种可以在eclipse中调试ant任务的方法。

 

首先在build.xml中复制server任务到一个新的任务,比如叫做server-debug,在启动虚拟机的时候加入下面的这条语句。

 

<jvmarg value="-Xrunjdwp:transport=dt_socket,address=5005,server=y"/>

 

Xml代码 
  1. <!-- a target for running the game server in debug mode -->  
  2. <target name="server-debug" depends="compile" description="Runs a test server.">  
  3.   <propertyfile file="${deploy.dir}/classes/toybox.properties">  
  4.     <entry key="resource_dir" value="${deploy.dir}"/>  
  5.     <entry key="resource_url" value="file://${deploy.dir}"/>  
  6.   </propertyfile>  
  7.   <!-- we have to convert basedir to forward slashes to make it work as a URL -->  
  8.   <path id="codedir"><pathelement location="${basedir}/../lib"/></path>  
  9.   <pathconvert targetos="unix" property="basedir.unix" refid="codedir"/>  
  10.   <!-- we also have to stick an extra / in front of basedir.unix to make -->  
  11.   <!-- things work on windows, fortunately it does not booch things on unix -->  
  12.   <echo file="${deploy.dir}/server.policy">  
  13.     grant codeBase "file:///${basedir.unix}/../lib/-" {  
  14.         permission java.security.AllPermission;  
  15.     };  
  16.   </echo>  
  17.   <java classname="com.threerings.toybox.server.ToyBoxServer" fork="true">  
  18.     <classpath refid="classpath"/>  
  19.     <sysproperty key="java.security.manager" value=""/>  
  20.     <sysproperty key="java.security.policy" value="${deploy.dir}/server.policy"/>  
  21.     <sysproperty key="game_conf" value="${app.name}.xml"/>  
  22.     <jvmarg value="-Xrunjdwp:transport=dt_socket,address=5005,server=y"/>  
  23.   </java>  
  24.   <delete file="${deploy.dir}/classes/toybox.properties"/>  
  25.   <delete file="${deploy.dir}/server.policy"/>  
  26. </target>    

 

这时候在eclipse中调出ant视图,运行该server-debug任务,这会儿只会在控制台会输出

 

Console代码 
  1. Buildfile: D:/Java/threerings/gardens/projects/games/five/build.xml  
  2. prepare:  
  3. compile:  
  4. server-debug:  
  5. [propertyfile] Updating property file: D:/Java/threerings/gardens/projects/games/five/dist/classes/toybox.properties  
  6.      [java] Listening for transport dt_socket at address: 5005  

 

 

然后在菜单中选择run-->debug configurations...选择remote java application,在port这一栏里填入前面加到jvm参数中的5005,再点击apply和debug,这时候在控制台就会正常输出,并且可以加入断点调试了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值