有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用Maven进行java JUnit测试。jar找不到主类

我在JUnit上有一个Maven项目,用Selenium和Cucumber在web浏览器上执行自动测试。 我让Maven编译一个。jar包含所有依赖项。 所以我想要的是当我点击。jar执行测试并给出输出。包含测试结果的json文件

波姆。xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>TestingAutomation</groupId>
    <artifactId>TestingAutomation</artifactId>
    <version>0.0.1</version>
    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <scope>test</scope>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>StartTests</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

StartTests。爪哇:

import org.junit.runner.JUnitCore;

public class StartTests {

    public static void main(String args[]) {
        JUnitCore.main("Runner");
    }

}

跑步者。爪哇:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/main/resources/features")

public class Runner {
}

所以,当我运行StartTests时。来自InteliJ的java这就是我得到的:

JUnit version 4.12
.Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 32181
Only local connections are allowed.
feb 05, 2017 11:17:04 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
feb 05, 2017 11:17:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
...
1 Scenarios (1 passed)
3 Steps (3 passed)
0m8.098s


Time: 8,14

OK (4 tests)


Process finished with exit code 0

当我执行项目的Maven构建时,Maven正确地创建了所有依赖项。jar文件,但当我双击它时,什么也没发生。 我试图通过命令行(Windows环境)执行它:

java -jar TestingAutomation.jar

我得到的回报如下:

JUnit version 4.12
.E
Time: 0,001
There was 1 failure:
1) initializationError(Runner)
java.lang.NoClassDefFoundError: org/jboss/marshalling/Unmarshaller

这是舱单。生成的MF文件:

Manifest-Version: 1.0
Built-By: MyName
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_121
Main-Class: StartTests

共 (0) 个答案