无法使用maven pom和eclipse一致地创建src/test/java模块jar

无法使用maven pom和eclipse一致地创建src/test/java模块jar,java,maven,jar,Java,Maven,Jar,无法使用maven pom和eclipse目标一致地创建src/test/java模块jar 这是我的pom文件:当我在目标中使用eclipse byrunconfig-->运行时,如果我输入jar:test jar并运行,它会在我的目标文件夹中创建SFDCSearchSuite-0.0.1-SNAPSHOT-tests.jar,其中包含所有测试模块类,但有时它会创建jar,但不包含任何类。 如果我在goals中运行compile assembly:single,它每次都会创建带有所有src/m

无法使用maven pom和eclipse目标一致地创建src/test/java模块jar

这是我的pom文件:当我在目标中使用eclipse byrunconfig-->运行时,如果我输入jar:test jar并运行,它会在我的目标文件夹中创建SFDCSearchSuite-0.0.1-SNAPSHOT-tests.jar,其中包含所有测试模块类,但有时它会创建jar,但不包含任何类。

如果我在goals中运行compile assembly:single,它每次都会创建带有所有src/main/java类的SFDCSearchSuite-0.0.1-SNAPSHOT-jar-with-dependencies.jar

如何创建与所有测试模块类一致的测试SFDCSearchSuite-0.0.1-SNAPSHOT-tests.jar

谁能帮我把解决方案发过来,谢谢

<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>SFDCSearchSuite</groupId>
<artifactId>SFDCSearchSuite</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.42.2</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>2.42.2</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.6</version>
    </dependency>   
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
    </dependency>

</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/test/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.package.ClasseName</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <id>test-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins> <!-- This plugin's configuration is used to store Eclipse m2e settings only. 
                It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-compiler-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.3.2,]
                                    </versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                        <goal>testCompile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

4.0.0
SFDCSearchSuite
SFDCSearchSuite
0.0.1-快照
org.seleniumhq.selenium
硒爪哇
2.42.2
org.seleniumhq.selenium
硒铬驱动器
2.42.2
通用编解码器
通用编解码器
1.6
org.apache.maven.plugins
maven资源插件
2.4.3
src/main/java
**/*.爪哇
src/test/java
**/*.爪哇
maven编译器插件
3.1
1.6
1.6
maven汇编插件
com.package.ClasseName
带有依赖项的jar
maven jar插件
试验罐
包裹
试验罐
org.eclipse.m2e
生命周期映射
1.0.0
org.apache.maven.plugins
maven编译器插件
[2.3.2,]
编译
测试编译
我得到了答案:

mvn clean install -DskipTests

Add this in your pom.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
  </plugin>
mvn干净安装-DskipTests
将此添加到pom.xml中
maven汇编插件
包裹
单一的
带有依赖项的jar

为什么要从资源中排除
src/main/java
和`src/test/java`?这是默认情况。为什么不简单地通过
mvncleanpackage
调用Maven呢?为什么要调用
mvn compile assembly:singe
,这毫无意义。我不想在创建jar时运行测试方法,这就是原因