声纳测试用例失败 - java

我正在尝试为我的项目之一获得声纳报告。

我已经运行mvn clean install

Running blah.blah.BlahTest1
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Running blah.blah.BlahTest2
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec

当我运行mvn sonar:sonar时,出现以下错误。

[INFO] ------------------------------------------------------------------------
[INFO] Building Component name
[INFO]    task-segment: [org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test]
[INFO] ------------------------------------------------------------------------
[INFO] [surefire:test {execution: default-cli}]
[INFO] Surefire report directory: D:\CodeBase\Project\module\target\surefire-reports
java.lang.NoClassDefFoundError: null
Caused by: java.lang.ClassNotFoundException: null
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: null.  Program will exit.
Exception in thread "main" 
[ERROR] There are test failures.

我不确定从哪里开始寻找。我尝试在Google中搜索找不到与我的问题类似的东西。

请帮助我理解可能是寻找原因的原因。

谢谢。

添加pom文件:删除了一些细节以缩短文件

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--============================================================= -->
    <!--The Basics  -->
    <!--============================================================= -->
    <groupId>###</groupId>
    <artifactId>###</artifactId>
    <packaging>pom</packaging>
    <version>###</version>
    <url>###</url>
    <!--============================================================= -->
    <!--Project Information -->
    <!--============================================================= -->

    <!--============================================================= -->
    <!--Properties -->
    <!--============================================================= -->
    <properties>
        <!--general properties -->
        <svn-base-url>###</svn-base-url>

        <!--versions of 3rd party libraries -->

        <!--plug in versions -->
        <version.jacoco.plugin>0.7.4.201502262128</version.jacoco.plugin>
    </properties>
    <scm>

    </scm>
    <!--============================================================= -->
    <!--Modules -->
    <!--============================================================= -->
    <modules>
    </modules>
    <!--============================================================= -->
    <!--Distribution Management -->
    <!--============================================================= -->
    <distributionManagement>
    </distributionManagement>

    <!--============================================================= -->
    <!--Plugin Repository -->
    <!--============================================================= -->
    <pluginRepositories>
    </pluginRepositories>
    <!--============================================================= -->
    <!--Dependency Management -->
    <!--============================================================= -->
    <dependencyManagement>
    <!--3rd part libraries -->
    </dependencyManagement>
    <!--============================================================= -->
    <!--Dependencies -->
    <!--============================================================= -->
    <dependencies>
    </dependencies>
    <!--============================================================= -->
    <!--Build Information -->
    <!--============================================================= -->
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*</exclude>
                </excludes>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>${version.clean.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${version.compiler.plugin}</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <fork>true</fork>
                        <meminitial>128m</meminitial>
                        <maxmem>512m</maxmem>
                        <compilerArgument>-Xlint:-serial -Xmaxwarns 9999 -Xmaxerrs 9999</compilerArgument>
                    </configuration>
                </plugin>
                <plugin>
                  <groupId>org.jacoco</groupId> 
                  <artifactId>jacoco-maven-plugin</artifactId> 
                  <version>${version.jacoco.plugin}</version> 
                  <configuration>
                    <append>true</append> 
                    <destFile>target/coverage-reports/jacoco-unit.exec</destFile> 
                    <dataFile>target/coverage-reports/jacoco-unit.exec</dataFile> 
                    <includes>
                      <include>path</include> 
                    </includes>
                  </configuration>
                  <executions>
                    <execution>
                      <id>prepare-agent</id> 
                      <goals>
                        <goal>prepare-agent</goal> 
                      </goals>
                    </execution>
                    <execution>
                      <id>report</id> 
                      <phase>prepare-package</phase> 
                      <goals>
                        <goal>report</goal> 
                      </goals>
                    </execution>
                  </executions>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>${version.surefire.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>${version.enforcer.plugin}</version>
                    <configuration>
                        <rules>
                            <requireJavaVersion>
                                <version>1.6</version>
                            </requireJavaVersion>
                            <requireMavenVersion>
                                <version>2.2.0</version>
                            </requireMavenVersion>
                        </rules>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>${version.versions.plugin}</version>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>${version.assembly.plugin}</version>
                    <configuration>
                        <descriptors>
                           <!-- descriptors -->
                        </descriptors>
                    </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-release-plugin</artifactId>
                    <version>${version.release.plugin}</version>
                    <configuration>
                        <goals>deploy</goals>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${version.resources.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>${version.install.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>${version.site.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jxr-plugin</artifactId>
                    <version>${version.jxr.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>cobertura-maven-plugin</artifactId>
                    <version>${version.cobertura.plugin}</version>
                    <configuration>
                        <formats>
                            <format>xml</format>
                        </formats>
                        <instrumentation>
                            <!--Include and exclude -->
                        </instrumentation>
                        <maxmem>512M</maxmem>
                    </configuration>
                    <executions>
                        <execution>
                            <id>clean</id>
                            <phase>pre-site</phase>
                            <goals>
                                <goal>clean</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>instrument</id>
                            <phase>package</phase>
                            <goals>
                                <goal>cobertura</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>${version.pmd.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>${version.findbugs.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>${version.checkstyle.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>dashboard-maven-plugin</artifactId>
                    <version>${version.dashboard.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>${version.buildhelper.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>${version.jaxb2.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>taglist-maven-plugin</artifactId>
                    <version>${version.taglist.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-changelog-plugin</artifactId>
                    <version>${version.changelog.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-scm-plugin</artifactId>
                    <version>1.2</version>
                    <configuration>
                        <connectionType>developerConnection</connectionType>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${version.jar.plugin}</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>${version.exec-maven.plugin}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>${version.antrun.plugin}</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>remove-project-artifact</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>remove-project-artifact</goal>
                        </goals>
                        <configuration>
                            <removeAll>false</removeAll>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId> 
                <artifactId>jacoco-maven-plugin</artifactId> 
            </plugin>
              <!--  Need the argLine in the configuration here otherwise jacoco hook into surefire correctly for unit test coverage -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                  <forkMode>once</forkMode>
                  <argLine>${argLine} -XX:MaxPermSize=256M -Xmx892M -client</argLine>
                </configuration>
            </plugin>   
        </plugins>
    </build>    
</project>

参考方案

我不是Maven专家,但是我有实现,在Maven生命周期中,我执行一些JUnit,以查找代码覆盖率和Sonar。我附上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>

<!-- Project Parent POM -->
<parent>
    <groupId>XXX</groupId>
    <artifactId>XXX</artifactId>
    <version>2.0</version>
</parent>

<!-- Artifacts for the WAR -->
<groupId>XXX</groupId>
<artifactId>XXX</artifactId>
<packaging>war</packaging>
<version>0.1</version>
<name>XXX</name>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.5.3.201107060350</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    ...
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <configuration>
                <destFile>${sonar.jacoco.itReportPath}</destFile>
            </configuration>
            <executions>
                <execution>
                    <id>pre-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.17</version>
                </dependency>
            </dependencies>
            <configuration>
                <argLine>
                    ${argLine} -DAdditional Arguments
                </argLine>
                <includes>
                    <include>**/TestSuite.java</include>
                </includes>
                <skipTests>false</skipTests>
                <forkCount>1</forkCount>
                <reuseForks>true</reuseForks>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
                <skip>false</skip>
            </configuration>
        </plugin>
    </plugins>
</build>


<dependencies>
    <!--Dependencies -->
</dependencies>

<!-- Properties of the dependencies defined above -->
<properties>
    <!-- Versions -->

    <!-- Sonar Properties -->
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jacoco.itReportPath>${project.basedir}/target/jacoco-it.exec</sonar.jacoco.itReportPath>
    <sonar.language>java</sonar.language>   
</properties>

Java中的<<或>>>是什么意思? - java

This question already has answers here: Closed 7 years ago. Possible Duplicate: What does >> and >>> mean in Java?我在一些Java代码中遇到了一些陌生的符号,尽管代码可以正确编译和运行,但对于括号在此代码中的作用却感…

菱形运算符<>是否等于<?> - java

我在util.TreeSet类中发现,其中一个构造函数正在使用具有空泛型类型的新TreeMap调用另一个构造函数。 public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<>(comparator)); } new TreeMap<>是什么意思…

休眠映射<键,设置<值>> - java

我有以下表格:@Entity @Table(name = "events") Event --id --name @Entity @Table(name = "state") State --id --name @Entity @Table(name = "action") Action --id …

无法从ArrayList <String>转换为List <Comparable> - java

当我写下面的代码时,编译器说 无法从ArrayList<String>转换为List<Comparable>private List<Comparable> get(){ return new ArrayList<String>(); } 但是当我用通配符编写返回类型时,代码会编译。private List&l…

缺少Jacoco代码覆盖率和IncompatibleClassChangeError - java

我有一个带有一些Arquillian测试(包括Drone / Graphene测试)的Maven项目。当我使用Maven构建项目时,所有使用Graphene和Drone或Warp的Arquillian测试都将失败,并出现以下异常Running de.mmo.arq.model.diverses.stammdaten.geldinstitut.Geldinst…