[英]Maven Build JAR for Test Case
i have spring boot selenium web driver project on eclipse using maven. i run the test in scr/test/java
and put all element, pages, configuration in scr/main/java
.我有 spring 引导 selenium web 驱动程序项目在 eclipse 使用 maven。我在
scr/test/java
中运行测试并将所有元素、页面、配置放在scr/main/java
中。
now i want to create executable jar. how to do this?现在我想创建可执行文件 jar。该怎么做? is it possible?
是否可以? i want it to run from cmd like
java -jar mytask.jar
我希望它从 cmd 运行,例如
java -jar mytask.jar
so far i tried using mvn clean install, mvn clean package to generate.jar file.到目前为止,我尝试使用 mvn clean install、mvn clean package 来生成 .jar 文件。 but when i tried to run it, it doesn't work.
但是当我尝试运行它时,它不起作用。 it runs the main in
scr/main/java
.它在
scr/main/java
中运行 main 。 i want to run in scr/test/java
我想在
scr/test/java
中运行
this is my test class:这是我的测试 class:
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.bca.magenta.pages.HomePage;
@SpringBootTest
class ApplicationTests {
@Autowired
HomePage homePage;
@Autowired
WebDriver driver;
@BeforeEach
public void before() {
driver.manage().window().maximize();
}
@Test
public void test() throws InterruptedException {
homePage.testInsert();
}
@AfterEach
public void after() {
driver.quit();
}
}
this is my main class in src/main/java
这是我在
src/main/java
中的主要 class
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
when i run in eclipse as junit. it run as i expected.当我以 eclipse 作为 junit 运行时。它按预期运行。 but how to run this in jar?
但是如何在 jar 中运行呢?
Use the shade plugin , here's an example :使用阴影插件,这里有一个例子:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.sonatype.haven.HavenCli</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.