创建 ANT 脚本以部署到 glassfish,运行 junit 测试,然后取消部署

发布于 2024-08-18 16:37:47 字数 547 浏览 5 评论 0原文

大家好,我有一个使用 Netbeans 构建的 j2ee 应用程序。我的任务是修改 build.xml,以便在应用程序构建后,ANT 将应用程序部署到服务器,在应用程序上运行 Junit 任务,然后取消部署应用程序。到目前为止,我已经部署和取消部署工作,但在运行 junit 任务时遇到了一些问题。

我在 Netbeans 中有一个客户端项目,我的 junit 任务就在其中。我的问题是,当构建这个项目时,它不会将我的 junit 测试编译到 .jar 中。当我运行 ant junit 任务并且 ANT 无法找到适合 junit 测试的 .class 文件时,这会导致问题。

在 Netbeans 项目属性中,它允许我设置“源包文件夹”和“测试包文件夹”。如果我将“test”文件夹添加到“源包文件夹”中并构建项目,它将编译测试并将它们包含在 jar 中。这是可行的,但是它阻止我将 junit 测试作为 netbeans 中的测试来运行,从而减慢开发速度。

有没有人有解决这样的问题的经验?我可能忽略了一个简单的解决方案,所以如果有人有建议,我将不胜感激。提前致谢。

-布拉德

Hey guys, I have a j2ee app which I am building with Netbeans. My task is to modify the build.xml so that after the app builds, ANT deploys the app to a server, runs Junit tasks on the app, and then un-deploys the app. So far I have the deploy and un-deploy working but I'm running into some trouble running the junit tasks.

I have a client project in Netbeans where my junit tasks lie. My trouble is that when this project is built, it doesn't compile my junit tests into the .jar. This causes problems when I run my ant junit tasks and ANT cannot find the appropriate .class files for the junit tests.

In the Netbeans Project Properties it allows me to set "Source Package Folders" and "Test Package Folders". If I add the "test" folder into the "Source Package Folders" and build the project it compiles the tests and includes them with the jar. This works, however it prevents me from running my junit tests as tests in netbeans which slows development.

Has anyone had any experience with solving such a problem? There may be a simple solution I am overlooking so if anyone has a word of advice I would appreciate it. Thanks in advance.

-Brad

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上得阳光 2024-08-25 16:37:47

如果我明白你在问什么,

你不需要将测试类编译到 jar 中。只需将它们编译到某个目录中,例如“类”。然后只需将此目录包含在 junit 任务的文件集嵌套元素中即可。

一个简单的例子,

<target name="junit">
  <junit printsummary="true">
    <classpath>
      <pathelement location="${classes.dir}"/>
    </classpath>

    <test name="test.class.TestClass"/>
  </junit>
</target>

If I understand what you're asking,

You shouldn't need to compile the test classes into the jar. Just compile them into some directory, say 'classes'. Then just include this directory in the fileset nested element for the junit task.

A simple example,

<target name="junit">
  <junit printsummary="true">
    <classpath>
      <pathelement location="${classes.dir}"/>
    </classpath>

    <test name="test.class.TestClass"/>
  </junit>
</target>
梦旅人picnic 2024-08-25 16:37:47

必须将我的 junit 任务指向正确的类路径。指向 .class 文件的确切目录(project1/classes/com/blah/blah2/blah3),这是不正确的。将类路径设置为project1/classes 并且它起作用了。新手错误。

Had to point my junit task to the correct classpath. Was pointing to the exact directory of the .class files(project1/classes/com/blah/blah2/blah3) which is incorrect. Set classpath to project1/classes and it worked. Noob mistake.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文