java - 如何在 JMH 中使用外部 JAR
问题描述
我的 Java 项目使用了一些外部 JAR。为了对项目进行基准测试,我如何将这些添加到 JMH?
-cp
例如,我应该使用选项将它们添加到 java 命令行吗?(这实际上导致我的环境中找不到类错误)
解决方案
您可以像在任何其他项目中一样使用 jar。你可能调用了-cp
错误的主类,它应该是org.openjdk.jmh.Main
. 这是maven 的示例。请注意pom.xml
.
我将在这里从 POM 复制重要部分:
..
<dependencies>
..
<!-- This is the lib I want to add -->
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.0.3.RELEASE</version>
</dependency>
..
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
...
推荐阅读
- arm - L2 Cache Miss 是否等同于 ARMv7 A15 上的“L2 Data Cache Refill”?
- r - Rstudio 不会加载 Rcmdr
- javascript - 从文件夹导入 webpack 排除不必要的模块
- c# - 为什么第一个插入在 Cassandra 中胜过第二个插入?
- awk - awk 行到多列
- c++ - C++中的向量初始化
- java - 我需要一个例子来实现通用多态性(尤其是包含)
- php - 如何连接 mssql 服务器并使用 php 获取值
- angular - *ngIf Firestore 与查询集合 / angularfire2
- wordpress - cPanel Webmail 迁移——如何迁移多个电子邮件帐户及其文件夹?