如何解决Maven中的未知工件类型[test-jar]错误?

时间:2014-08-12 11:36:45

标签: maven

尝试使用Maven构建耳朵时出现此错误。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.4.2:generate-application-xml (default-generate-application-xml) on project cargooceanear: Failed to initialize ear modules: Unknown artifact type[tes
t-jar] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.4.2:generate-application-xml (default-generate-application-xml) on project cargooceanear: Failed to i
nitialize ear modules
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to initialize ear modules
        at org.apache.maven.plugin.ear.AbstractEarMojo.execute(AbstractEarMojo.java:240)
        at org.apache.maven.plugin.ear.GenerateApplicationXmlMojo.execute(GenerateApplicationXmlMojo.java:85)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more
Caused by: org.apache.maven.plugin.ear.UnknownArtifactTypeException: Unknown artifact type[test-jar]
        at org.apache.maven.plugin.ear.util.ArtifactTypeMappingService.getStandardType(ArtifactTypeMappingService.java:151)
        at org.apache.maven.plugin.ear.EarModuleFactory.newEarModule(EarModuleFactory.java:74)
        at org.apache.maven.plugin.ear.AbstractEarMojo.execute(AbstractEarMojo.java:230)
        ... 22 more

2 个答案:

答案 0 :(得分:3)

问题:maven-ear-plugin会出错:  [INFO] Failed to initialize ear modules Embedded error: Unknown artifact type[zip]

原因:传递依赖项中的zip或不受支持的文件

解决方案:在Windows中,首先打开cmd,cd项目的根目录,然后在cmd中键入mvn dependency:tree,找到与marven-ear-冲突的传递依赖项插件。

e.g。未知拉链 + - com.sun.xml.ws:samples:zip:2.2.10:compile 意味着

<groupId>com.sun.xml.ws</groupId>
<artifactId>samples</artifactId>

e.g。 改变耳朵:将排除在你的依赖中

<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
... 
<exclusions>
<exclusion>     
<groupId>com.sun.xml.ws</groupId>       
<artifactId>samples</artifactId>          
</exclusion>          
... 
</exclusions>
</dependency>

同样适用于+ - com.sun.xml.ws:release-documentation:zip

答案 1 :(得分:2)

基本上这个错误是由于类型&#34; test-jar&#34;的依赖关系或传递依赖性造成的。

e.g。

<dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>jackrabbit-data</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
</dependency> 

选项A:如果&#34; test-jar&#34;在pom.xml 中的依赖项中找到,然后添加&#34; test-jar&#34;目标是maven-jar-plugin。

 <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <version>2.4</version>
   <configuration>
      .............
   </configuration>
   <executions>
     <execution>
       <goals>
         <goal>test-jar</goal>
       </goals>
     </execution>
   </executions>
 </plugin>

选项B:如果&#34; test-jar&#34;在传递依赖中找到然后必须在pom.xml中将其排除以修复此错误。

<dependency>
    <groupId>mygroup</groupId>
    <artifactId>myartifact</artifactId>
    <version>${myartifact-release-version}</version>
    <type>ejb</type>
     <exclusions>
        <exclusion>
           <groupId>org.apache.jackrabbit</groupId>
           <artifactId>jackrabbit-data</artifactId>
        </exclusion>
     </exclusions>                
 </dependency>