我已经在我的src / test / java文件夹中使用不同的包创建了黄瓜测试用例,并希望使用maven创建一个包含所有依赖项和类的jar。编译精细,运行良好。但是,在转换为jar文件时,不存在类/依赖项。后来我使用maven shade插件如下所示,仍然只获得一个Meta-INF文件夹,并且没有任何类。使用eclipse IDe和Maven 3.3.9,selenium 2.53。
maven安装后得到2个jar文件BsMonitor-0.0.1-SNAPSHOT(得到了很多文件,但没有我的类文件)和原始-BsMonitor-0.0.1-SNAPSHOT,两者都没有类但只是一个META-INF文件夹。
对于shade插件,在main class标签下我将它指向包含我的Main方法的类。我不确定这是不是。
同样如图所示,src / Main / Java中没有文件,只有src / test / java中没有文件。如何处理?
我的项目结构:
我的POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cucumber</groupId>
<artifactId>BsMonitor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BsMonitor</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.cucumber.Base.NewMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:1)
最好遵循maven建议的方式,链接希望这有助于https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html