Maven2 + JMeter +具有依赖关系的 JUnit

发布于 2024-09-08 08:06:45 字数 173 浏览 1 评论 0原文

我想在 JMeter 中运行我的 JUnit 测试。使用 maven-jar-plugin,我可以使用测试创建一个 jar,以便将其放入 JMeter 的类路径 ($JMETER_HOME/lib/junit) 中。问题是我的测试有很多 Maven2 没有放入 jar 中的依赖项,包括项目的主类、其他项目的类和外部库。我该怎么做?

I'd like to run my JUnit tests in JMeter. Using maven-jar-plugin I can create a jar with my tests in order to put it inside the JMeter's classpath ($JMETER_HOME/lib/junit). The problem is that my tests have a lot of dependencies that Maven2 doesn't put into the jar, including the main classes of the project, classes from other projects and external libraries. How can I do this?

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

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

发布评论

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

评论(2

顾挽 2024-09-15 08:06:45

您可以使用 fatjar 插件

You can use the fatjar plugin.

当梦初醒 2024-09-15 08:06:45

正如 iwein 提到的,您可以使用 maven-fatjar-plugin ,它将将所有依赖的 JAR 放入您的 JAR 工件中,并创建适当的 MANIFEST 条目以将它们包含在您的类路径中。

另一种选择是您可以使用 maven-shade-plugin ,它会简单地从依赖 JAR 中取出所有“.class”文件,并将它们直接包含在您的 JAR 中。这称为 UBER-JAR。我更喜欢这种方法有几个原因:

  1. 这通常会导致 JAR 稍小一些。
  2. 我有其他已经操作 MANIFEST(包括 Classpath 属性)的插件,并且我不想有机会生成不正确的清单。
  3. 创建一个 UBER-JAR 真是太好了,不容错过;)

As iwein has mentioned, you may use the maven-fatjar-plugin which will put all the dependent JAR's inside of your JAR artifact and create the appropriate MANIFEST entries to include them on your classpath.

Another option is that you can use the maven-shade-plugin which will simply take all of the ".class" files out of the dependecy JARs and include them directly in your JAR. This is called a UBER-JAR. There are a couple of reasons which I prefer this approach:

  1. This often leads to slightly smaller JARs
  2. I have other plugins which already manipulate the MANIFEST (including the Classpath property) and I don't want to chance having an incorrect manifest being generated.
  3. Creating an UBER-JAR is just too good to pass up ;)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文