2013-03-20 16 views
11

Ci sono una manciata di domande apparentemente molto simili su StackOverflow, ma ho difficoltà a trovare qualcosa che funzioni.Come escludere determinate dipendenze Jar quando si utilizza Maven per Jar Assembly

Per ora, sto cercando di rimuovere log4j dal Jar costruito.

Anche se sono nuovo di Maven, e sono sicuro di aver sbagliato tutto, ecco quello che sto provando.

pom.xml:

<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>com.icf.onecpd</groupId> 
    <artifactId>pdfgen</artifactId> 
    <version>1.1</version> 
    <packaging>jar</packaging> 

    <name>PDF Generator</name> 
    <url></url> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.itextpdf</groupId> 
      <artifactId>itextpdf</artifactId> 
      <version>5.2.0</version> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
      <scope>runtime</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <executions> 
        <execution> 
         <id>default-compile</id> 
         <configuration> 
          <source>1.6</source> 
          <target>1.6</target> 
         </configuration> 
         <phase>compile</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <configuration> 
        <descriptors> 
         <descriptor>assembly.xml</descriptor> 
        </descriptors> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <scm> 
     <url>https://svn.tms.icfi.com/svn/HUD/onecpd/income_calculator_pdf_generator</url> 
    </scm> 
</project> 

assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <dependencySets> 
     <dependencySet> 
      <excludes> 
       <exclude>log4j:log4j:*</exclude> 
      </excludes> 
     </dependencySet> 
    </dependencySets> 
</assembly> 

montaggio: singolo log:

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building PDF Generator 1.1 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default-cli) @ pdfgen --- 
[INFO] Reading assembly descriptor: assembly.xml 
[INFO] META-INF/MANIFEST.MF already added, skipping 
[INFO] META-INF/ already added, skipping 
[INFO] META-INF/maven/ already added, skipping 
[INFO] Building jar: /home/jamie/workspace_ruby2/onecpd_pdfgen/target/pdfgen-1.1-jar-with-dependencies.jar 
[INFO] META-INF/MANIFEST.MF already added, skipping 
[INFO] META-INF/ already added, skipping 
[INFO] META-INF/maven/ already added, skipping 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 5.368s 
[INFO] Finished at: Wed Mar 20 13:45:33 EDT 2013 
[INFO] Final Memory: 8M/158M 
[INFO] ------------------------------------------------------------------------ 

Tuttavia, il vaso risultante finisce con l'/ org/apache/log4j/classi inclusi.

Come sbarazzarsi di loro?

Grazie!

risposta

13

Puoi provare a dichiarare la dipendenza come un ambito fornito, ad es.

<dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
     <scope>provided</scope> 
    </dependency> 
+0

nodo rimosso: 'project> costruire> plugin: Maven-assemblaggio-plugin> Configurazione> descrittori> descriptor', poi cercato la vostra portata, al di sopra, e sono felice! –

+0

Dopo aver dichiarato la dipendenza come fornita, si utilizza ancora il descrittore jar-with-depend del plug-in di assembly maven o si utilizza l'assembly obiettivo: basta? –

Problemi correlati