title: Maven throws "Error injecting and NoClassDefFoundError",when i trying to build archive .sar inside .ear
body: <p>I have maven project.
  My ear archive consist from jar and war. And he builds without error.
  Problems began when i try to add .sar package to project. And he more not building. He throws exception.
  I need sar archive for using MBean, if you know other ways for using MBean, say me.
  Because i'm new with jmx.</p>
  
  <p>Pom hierarchy:</p>
  
  <pre><code>pom.xml(super)
  --pom.xml(ear)
  --pom.xml(war)
  --pom.xml(jar)
  --pom.xml(sar)
  </code></pre>
  
  <p>Sar hierarchy:</p>
  
  <pre><code>src
  --main
  ----java
  ------org.myproject
  --------MyMBean.java
  --------MyService.java
  ----resources
  ------META-INF
  --------jboss-service.xml
  pom.xml
  </code></pre>
  
  <p>super pom:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;org.myproject&lt;/groupId&gt;
      &lt;artifactId&gt;logic&lt;/artifactId&gt;
      &lt;version&gt;2.0&lt;/version&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
      &lt;properties&gt;
          &lt;logic.version&gt;2.0&lt;/logic.version&gt;
          &lt;modul-jar.version&gt;2.0&lt;/modul-jar.version&gt;
          &lt;logic-ear.version&gt;2.0&lt;/logic-ear.version&gt;
          &lt;web-war.version&gt;2.0&lt;/web-war.version&gt;
      &lt;/properties&gt;
  
      &lt;modules&gt;
          &lt;module&gt;modul-jar&lt;/module&gt;
          &lt;module&gt;logic-ear&lt;/module&gt;
          &lt;module&gt;web-war&lt;/module&gt;
          &lt;module&gt;mbean-sar&lt;/module&gt;
      &lt;/modules&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>ear pom:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;parent&gt;
          &lt;artifactId&gt;logic&lt;/artifactId&gt;
          &lt;groupId&gt;org.myproject&lt;/groupId&gt;
          &lt;version&gt;2.0&lt;/version&gt;
      &lt;/parent&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;artifactId&gt;logic-ear&lt;/artifactId&gt;
      &lt;groupId&gt;org.myproject&lt;/groupId&gt;
      &lt;version&gt;2.0&lt;/version&gt;
      &lt;packaging&gt;ear&lt;/packaging&gt;
  
      &lt;dependencies&gt;
          &lt;!-- war ejb sar --&gt;
          &lt;dependency&gt;
              &lt;artifactId&gt;web-war&lt;/artifactId&gt;
              &lt;groupId&gt;org.myproject&lt;/groupId&gt;
              &lt;version&gt;2.0&lt;/version&gt;
              &lt;type&gt;war&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;artifactId&gt;modul-jar&lt;/artifactId&gt;
              &lt;groupId&gt;org.myproject&lt;/groupId&gt;
              &lt;version&gt;2.0&lt;/version&gt;
              &lt;type&gt;ejb&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;artifactId&gt;mbean-sar&lt;/artifactId&gt;
              &lt;groupId&gt;org.myproject&lt;/groupId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
              &lt;type&gt;sar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;!-- sar plugin --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-packaging-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.plexus&lt;/groupId&gt;
              &lt;artifactId&gt;plexus-archiver&lt;/artifactId&gt;
              &lt;version&gt;2.1.2&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>sar pom</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;parent&gt;
          &lt;artifactId&gt;logic&lt;/artifactId&gt;
          &lt;groupId&gt;org.myproject&lt;/groupId&gt;
          &lt;version&gt;2.0&lt;/version&gt;
      &lt;/parent&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;artifactId&gt;mbean-sar&lt;/artifactId&gt;
      &lt;groupId&gt;org.myproject&lt;/groupId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;jboss-sar&lt;/packaging&gt;
  
      &lt;dependencies&gt;
          &lt;!-- mbean --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;jboss&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-system&lt;/artifactId&gt;
              &lt;version&gt;4.2.3.GA&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.mx&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-j2se&lt;/artifactId&gt;
              &lt;version&gt;6.0.0.GA&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;jboss-packaging-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.2&lt;/version&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;jboss-sar&lt;/id&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;sar&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;primaryArtifact&gt;false&lt;/primaryArtifact&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Exception</p>
  
  <pre><code>[INFO] --- jboss-packaging-maven-plugin:2.2:sar (jboss-sar) @ mbean-sar ---
  31.10.2012 16:39:14 org.sonatype.guice.bean.reflect.Logs$JULSink warn
  WARNING: Error injecting: org.codehaus.mojo.jboss.packaging.SarMojo
  java.lang.NoClassDefFoundError: Lorg/codehaus/plexus/archiver/jar/JarArchiver;
      at java.lang.Class.getDeclaredFields0(Native Method)
      at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
      at java.lang.Class.getDeclaredFields(Class.java:1743)
      at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:651)
      at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:358)
      at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:155)
      at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:585)
      at com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:542)
      at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:528)
      at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:833)
      at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:758)
      at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:255)
      at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:204)
      at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:954)
      at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:987)
      at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:950)
      at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1000)
      at org.sonatype.guice.bean.reflect.AbstractDeferredClass.get(AbstractDeferredClass.java:45)
      at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:84)
      at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:52)
      at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.java:70)
      at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:100)
      at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.onProvision(PlexusLifecycleManager.java:138)
      at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:108)
      at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:55)
      at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:68)
      at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45)
      at com.google.inject.internal.InjectorImpl$3$1.call(InjectorImpl.java:965)
      at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1011)
      at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:961)
      at com.google.inject.Scopes$1$1.get(Scopes.java:59)
      at org.sonatype.guice.bean.locators.LazyBeanEntry.getValue(LazyBeanEntry.java:83)
      at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexusBean.java:49)
      at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:253)
      at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:245)
      at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:455)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:92)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
      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:84)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
      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:290)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
      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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.archiver.jar.JarArchiver
      at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
      ... 63 more
  
  [INFO] ------------------------------------------------------------------------
  [INFO] Reactor Summary:
  [INFO]
  [INFO] logic ............................................. SUCCESS [0.159s]
  [INFO] modul-jar ......................................... SUCCESS [0.469s]
  [INFO] web-war ........................................... SUCCESS [0.259s]
  [INFO] mbean-sar ......................................... FAILURE [0.282s]
  [INFO] logic-ear ......................................... SKIPPED
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 1.350s
  [INFO] Finished at: Wed Oct 31 14:03:10 GMT+04:00 2012
  [INFO] Final Memory: 7M/16M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.codehaus.mojo:jboss-packaging-maven-plugin:2.2:sar (default-sar) on project mbean-sar
  : Execution default-sar of goal org.codehaus.mojo:jboss-packaging-maven-plugin:2.2:sar failed: A required class was miss
  ing while executing org.codehaus.mojo:jboss-packaging-maven-plugin:2.2:sar: Lorg/codehaus/plexus/archiver/jar/JarArchive
  r;
  [ERROR] -----------------------------------------------------
  [ERROR] realm =    plugin&gt;org.codehaus.mojo:jboss-packaging-maven-plugin:2.2
  [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
  [ERROR] urls[0] = file:/C:/Users/birukov/.m2/repository/org/codehaus/mojo/jboss-packaging-maven-plugin/2.2/jboss-packagi
  ng-maven-plugin-2.2.jar
  [ERROR] urls[1] = file:/C:/Users/birukov/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
  [ERROR] Number of foreign imports: 1
  [ERROR] import: Entry[import  from realm ClassRealm[project&gt;org.myproject:mbean-sar:1.0, parent: ClassRealm[maven.api, p
  arent: null]]]
  [ERROR]
  [ERROR] -----------------------------------------------------: org.codehaus.plexus.archiver.jar.JarArchiver
  </code></pre>
  
  <p>I tryed to place jboss-packaging-maven-plugin plugin and dependency in super-pom, ear-pom and sar-pom. This has no effect.
   I many think about missing and duplicate artifacts. Where problems?</p>