batch-file - 如何为放心项目创建 .bat 文件?
问题描述
我正在开发一个包含 testng.xml 文件的 Rest-Assured 项目。我正在尝试通过批处理运行 testng.xml 文件。但这给了我错误-
无法找到或加载主类 org.testng.TestNG
以下是批处理文件的代码:-
cd C:\Users\workspace\RestAssured
set projectPath=C:\Users\workspace\RestAssured
java org.testng.TestNG "%projectPath%\testng.xml"
pause
我经历了许多批处理文件创建解决方案,但我仍然无法复制它。而且,在某些解决方案中,我看到他们还添加了类路径,例如 - set classpath=C:\Users\workspace\RestAssured\bin
。但是这个 bin 文件夹在我的项目中不存在。
而且,假设我的项目位于 C 盘位置。如何为不同的用户动态取项目路径?
解决方案
You need to ensure that you set the class path properly.
Here's what you need to do:
- Download the latest version of TestNG
7.0.0
from here. - Download the dependencies that TestNG and have them made available in a folder (say lib). The easiest way of figuring out the actual download URLs is by doing
http://repo1.maven.org/maven2" + groupId + "/ + artifactId + "/" + version
(replace all.
with/
)
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.21</version>
</dependency>
Once you have everything in your lib folder, create a batch file wherein you set the classpath to refer to all the jars in the lib folder,
cd C:\Users\workspace\RestAssured set projectPath=%cd% java -classpath "lib/*" org.testng.TestNG "%projectPath%\testng.xml" pause
This should take care of all of your questions.
推荐阅读
- bash - zsh 以编程方式填充命令内容
- java - Mongodb java驱动错误
- gradle - 从存储库下载并执行 jar 作为 Gradle 构建的第一步
- python - 两个不同形状的张量相减的结果是什么意思?
- android - Android adb:无法建立连接,因为目标机器主动拒绝它
- r - 呈现边距时 facet_grid 中的颜色和形状美学
- c# - EF Core 2.0 更新一对零或一子实体会导致错误
- javafx - 如何使用 Gluon 插件在 JavaFX 中写入/读取
- python - PyCryptoDome 版本 3.6.6 引发 TypeError: Object type
不能传递给 C 代码 - amazon-web-services - Athena 数据库级访问控制