简体   繁体   English

Intellij IDEA Java项目通过.bat文件执行

[英]Intellij IDEA java project execute through .bat file

I'm developing a selenium and TestNG project and I want to use Jenkins to run tests from .bat files. 我正在开发一个硒和TestNG项目,我想使用Jenkins从.bat文件运行测试。

I found some tutorials but all of them using Eclipse IDE. 我找到了一些教程,但所有教程都使用Eclipse IDE。 eg: http://learn-automation.com/selenium-integration-with-jenkins/ 例如: http : //learn-automation.com/selenium-integration-with-jenkins/

In Intellij IDEA I couldn't find any lib (jar files) folder and the file structure is slightly different than the Eclipse. 在Intellij IDEA中,我找不到任何lib(jar文件)文件夹,并且文件结构与Eclipse略有不同。

I was able to run through a POM.XML file but I really want to know how to build .bat file to run my testng.xml file. 我能够运行一个POM.XML文件,但我真的很想知道如何构建.bat文件来运行我的testng.xml文件。 (From the beginning) (从一开始就)

Compiling and Running java project from command line without any build automation tools (ANT, Maven, gradle) could get really complicated, however you can do that. 在没有任何构建自动化工具(ANT,Maven,gradle)的情况下从命令行编译和运行Java项目可能会变得非常复杂,但是您可以这样做。

To compile and run I guess following should work. 为了进行编译和运行,我猜下面的方法应该可行。

To compile, I am not sure where class file will be generated but you can check help of javac command. 要进行编译,我不确定会在哪里生成类文件,但是可以检查javac命令的帮助。

javac -classpath "[jarname with specified path]" [java filename]

This will execute the class files. 这将执行类文件。

java -cp "path-to-jar/testng.jar:path_to_your_test_classes" org.testng.TestNG testng.xml

Now you can use this two command in batch file or directly use in jenkins. 现在您可以在批处理文件中使用这两个命令,也可以直接在jenkins中使用。

However the easy and better approach will be to use Maven. 但是,简单,更好的方法是使用Maven。 There are lots of online blogs and video tutorial about how to setup up Maven project or convert existing project into maven. 关于如何设置Maven项目或将现有项目转换为Maven的在线博客和视频教程很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM