我有用于运行自动化测试的页面对象模型,并且在页面包 org.jbehave.web.webdriver.pages.test 下有一个Java类。我只想使用基于maven pom文件构建的jar文件来运行特定的test.java类。我应该在pom文件中的哪里添加我的主类,并且只运行特定的类?
我尝试在该阶段添加它,但出现错误,因为“在可用目标map-stories-as-paths中的插件org.jbehave:jbehave-maven-plugin:4.0.3中找不到目标'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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jbehave-web-webdriver</groupId>
<artifactId>jbehave-web-webdriver</artifactId>
<version>1.0</version>
<name>JBehave WebDriver Stories</name>
<description>
</description>
<properties>
<jbehave.webapp.name>trader-runner</jbehave.webapp.name>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jbehave.web</groupId>
<artifactId>jbehave-web-selenium</artifactId>
<version>3.6-beta-2</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>4.0.4</version>
<classifier>resources</classifier>
<type>zip</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.20</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>4.0.3</version>
<executions>
<execution>
<id>run-stories</id>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.java2s.ide.App</mainClass>
<configuration>
</configuration>
</execution>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
<configuration>
<viewDirectory>target/jbehave/view</viewDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.3</version>
</dependency>
</dependency>
</dependencies>
</plugin> -->
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<versionRange>[3.9.1,)</versionRange>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
答案 0 :(得分:0)
如果您要运行Java程序,并且您的项目是基于Maven的,则可以使用阴影类型构建jar文件。它可以帮助您拥有一个胖子jar,将所有依赖项添加到其中。 **此外,您也可以在其基础标签中指定主类,例如:**
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MAIN_CLASS_ADDRESS</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
例如名为HaveCli的类的“ org.sonatype.haven.HaveCli”。