Jörg Henne schrieb:
Jörg Henne schrieb:
Hi,

has anybody actually successfully used the JBoss server SAR? The problem I'm seeing, is that lots of the JARs included in the sar (e.g. shared-ldap-0.9.6-SNAPSHOT.jar) are created using Maven and contain a META-INF/maven/<groupId>/<artifactId>/pom.xml file. This file (as any file ending in .xml below META-INF) causes the JARDeployer to reject the file. With the missing jars, however, the service obviously can't be started. I currently don't see an easy way to either filter the JARs to exclude the pom.xml or convice the JARDeployer to accept jars with a pom.xml.

Any help would be greatly appreciated.

Thanks
Joerg Henne
D'oh. I finally found
http://issues.apache.org/jira/browse/DIRSERVER-331
How about tweaking the SAR mojo to strip the included jars?

Joerg Henne
The attached patch does the trick (submitted this to http://jira.codehaus.org/browse/MOJO-377, too).

Joerg Henne
Index: .
===================================================================
--- .   (revision 1841)
+++ .   (working copy)
@@ -17,6 +17,8 @@
  */
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -23,6 +25,9 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
@@ -30,6 +35,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
 
 public abstract class AbstractSarMojo
     extends AbstractMojo
@@ -176,7 +182,29 @@
                     if ( "jar".equals( type ) && ! excludes.contains( 
descriptor ) )
                     {
                         getLog().info( "        o " + descriptor );
-                        FileUtils.copyFileToDirectory( artifact.getFile(), 
libDirectory );
+
+                        // copy jar skipping maven .xml files which would
+                        // upset the JBoss JARDeployer.
+                        ZipInputStream zis = new ZipInputStream(new 
FileInputStream(artifact.getFile()));
+                        ZipOutputStream zos = new ZipOutputStream(new 
FileOutputStream(new File(libDirectory, artifact.getFile().getName())));
+                        
+                        try {
+                            ZipEntry ze = null;
+                            while(null != (ze = zis.getNextEntry())) {
+                                String name = ze.getName();
+                                getLog().debug( "           - " + name );
+                                if(name.startsWith("META-INF/maven") && 
+                                    name.endsWith(".xml")) {
+                                    getLog().info( "           ! skipping " + 
name );
+                                    continue;
+                                }
+                                zos.putNextEntry(ze);
+                                IOUtil.copy(zis, zos);
+                            }
+                        } finally {
+                            zis.close();
+                            zos.close();
+                        }
                     }
                     else
                     {

Reply via email to