2010-04-06 15 views
15

Questo è il mio file pom:Maven-assemblaggio-plugin non aggiunge le dipendenze con portata di un sistema

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.sia.g7</groupId> 
    <artifactId>sia</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>sia</name> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.12</version> 
    </dependency> 
<dependency> 
    <groupId>commons-math</groupId> 
    <artifactId>commons-math</artifactId> 
    <version>1.2</version> 
</dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.1</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>jmathplot</groupId> 
     <artifactId>jmathplot</artifactId> 
     <version>1.0</version> 
     <scope>system</scope> 
     <systemPath>${project.basedir}/lib/jmathplot.jar</systemPath> 
    </dependency> 

    <dependency> 
     <groupId>jgraphx</groupId> 
     <artifactId>jgraphx</artifactId> 
     <version>1.0</version> 
     <scope>system</scope> 
     <systemPath>${project.basedir}/lib/jgraphx.jar</systemPath> 
    </dependency> 

    </dependencies> 
<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.0.2</version> 
     <configuration> 
     <source>1.6</source> 
     <target>1.6</target> 
     </configuration> 
    </plugin> 
    <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <configuration> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     <appendAssemblyId>false</appendAssemblyId> 
     <archive> 
      <manifest> 
      <mainClass>com.sia.g7.AbstractSimulation</mainClass> 
      </manifest> 
     </archive> 
     </configuration> 

    </plugin> 
    </plugins> 

</build> 
</project> 

E quando corro il barattolo ottengo:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mxgraph/swing/mxGraphComponent 

che fa parte del Dipendenza jgraphx. Cosa mi manca?

risposta

11

Sì, e questo è uno dei motivi per cui non si dovrebbe abusare system dipendenze portata (che è a livello mondiale una cattiva pratica) e questo problema è già stato detto più volte qui su SO (here, here). Sto proponendo una soluzione per gestire le dipendenze relative ai progetti in modo "pulito" in this answer.

1

In primo luogo, non deve essere l'ambito di sistema. Questa è la fonte del tuo problema. Installa/distribuisci la tua dipendenza nel repository e rendila una normale dipendenza da compilazione (o runtime).

2

È necessario rimuovere le clausole <scope>system</scope> da tali dipendenze. Quando l'ambito è impostato su sistema, ciò significa che l'artefatto è SEMPRE disponibile, quindi le dipendenze jar-with non lo includono.

7

potete farlo aggiungendo questo dependencySet al descrittore di file assembly

<dependencySet> 
    <outputDirectory>/</outputDirectory> 
    <unpack>true</unpack> 
    <scope>system</scope> 
</dependencySet> 

questo descrittore di assemblaggio aggiungere tutte le dipendenze, compreso il sistema con scope

<assembly 
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 
<id>jar-with-all-dependencies</id> 
<formats> 
    <format>jar</format> 
</formats> 
<includeBaseDirectory>false</includeBaseDirectory> 
<dependencySets> 
    <dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <useProjectArtifact>true</useProjectArtifact> 
     <unpack>true</unpack> 
     <scope>runtime</scope> 
    </dependencySet> 
    <dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <unpack>true</unpack> 
     <scope>system</scope> 
    </dependencySet> 
</dependencySets> 

</assembly> 
-2

Disimballare vostro vaso e aggiungerlo al src/main/risorse.

Problemi correlati