gpt4 book ai didi

java - 如何使用 Ant 脚本调试 Java 桌面应用程序?

转载 作者:行者123 更新时间:2023-12-02 05:13:33 27 4
gpt4 key购买 nike

我正在编译代码并生成桌面应用程序的 jar。但我无法调试代码。我想放置断点并使用 Eclipse F6 和 F5 函数逐步进行。有什么办法可以做到这一点吗?感谢您的帮助?我的 Ant 脚本如下:

<project name="R - 09 - tester">

<property name="app.name" value="Tester" />
<property name="app.version" value="2.0" />
<property name="dir.root" value="C:/.../trunk" />
<property name="dir.devel" value="${dir.root}/devel" />
<property name="dir.3rdparty" value="${dir.devel}/3rdparty" />
<property name="dir.deploy" value="${dir.root}/deploy" />
<property name="dir.binary" value="${dir.deploy}/bin" />
<property name="dir.class" value="${dir.deploy}/class" />


<property name="jar.xmlbeans" value="${dir.3rdparty}/xmlbeans/xbean.jar" />
<property name="jar.modelmesi" value="${dir.binary}/Model-Mesi-2.0.jar" />
<property name="jar.mesiapi" value="${dir.binary}/Mesi-API-2.0.jar" />
<property name="jar.mesimessages" value="${dir.binary}/Mesi-Messages-2.0.jar" />
<property name="jar.javaFX" value="${dir.3rdparty}/javafx/jfxrt.jar" />

<target name="init.property">
<property name="manifest.created.by" value="..." />
<property name="manifest.implementation.title" value="...." />
<property name="manifest.implementation.vendor" value="..." />
<property name="jar.mainclass" value="main.ApplicationMain" />
<mkdir dir="${dir.class}" />
</target>

<target name="init.application" depends="init.property">
<mkdir dir="${dir.class}/${app.name}" />
<echo message="(OUTPUT) Application JAR File Name: ${app.name}-${app.version}.jar" />

</target>

<target name="clean.build" description="Clean Created Build Files" depends="init.property">
<delete dir="${dir.class}/${app.name}" />
<delete file="${dir.binary}/${app.name}-${app.version}.jar" />
</target>

<target name="clean.all" description="Clean Created All Files" depends="clean.build">
<delete dir="bin" />
<delete dir=".codepro" />
<delete dir=".sonar" />
</target>

<target name="compile.application" depends="init.application">
<!-- compile files on the src path -->
<copy file="src/SceneStyle.css" todir="${dir.class}/${app.name}"/>
<javac debug="true" srcdir="src" destdir="${dir.class}/${app.name}" debuglevel="lines,vars,source" includeantruntime="false">
<classpath>
<pathelement location="${jar.xmlbeans}" />
<pathelement location="${jar.mesiapi}" />
<pathelement location="${jar.modelmesi}" />
<pathelement location="${jar.mesimessages}" />
<pathelement location="${jar.javaFX}" />
<fileset dir="${dir.3rdparty}/jreport">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>

<target name="build" description="Build the Application" depends="compile.application">
<tstamp />
<!-- needed for TODAY -->
<manifestclasspath property="jar.classpaths" jarfile="${dir.binary}/${app.name}-${app.version}.jar">
<classpath>
<pathelement location="${jar.xmlbeans}" />
<pathelement location="${jar.mesiapi}" />
<pathelement location="${jar.modelmesi}" />
<pathelement location="${jar.mesimessages}" />
<pathelement location="${jar.javaFX}" />
<fileset dir="${dir.3rdparty}/jreport">
<include name="**/*.jar" />
</fileset>
</classpath>
</manifestclasspath>

<jar destfile="${dir.binary}/${app.name}-${app.version}.jar" basedir="${dir.class}/${app.name}">
<manifest>
<attribute name="Created-By" value="${manifest.created.by}" />
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-Date" value="${TODAY}" />
<attribute name="Main-Class" value="${jar.mainclass}" />
<attribute name="Class-Path" value="${jar.classpaths}" />
<attribute name="Implementation-Vendor" value="${manifest.implementation.vendor}" />
<attribute name="Implementation-Title" value="${manifest.implementation.title}" />
<attribute name="Implementation-Version" value="${app.version}-b${build.number}" />
</manifest>

</jar>
</target>

<target name="rebuild" description="Rebuild the Application" depends="clean.build,build" />

<target name="run" description="Run the Application" depends="build">
<java jar="${dir.binary}/${app.name}-${app.version}.jar"/>

</target>

最佳答案

您应该使用 <java> 启用远程调试标签。

<java ....>
<jvmarg value="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5555"/>
</java>

现在运行您的 ant 脚本。它将启动 java 进程并等待,直到您与调试器连接到 porr 5555

如果您不想等待更改 suspend=ysuspend=n

关于java - 如何使用 Ant 脚本调试 Java 桌面应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27151867/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com