web-dev-qa-db-ja.com

maven-アセンブリ-プラグインはシステムスコープとの依存関係を追加しません

これは私のpomファイルです:

<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>

そして、私が瓶を走らせるとき、私は得ます:

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

これはjgraphx依存関係の一部です。何が足りないのですか?

22
Macarse

はい。これが、systemスコープの依存関係を悪用してはならない理由の1つです(これは世界的に悪い習慣です)。この問題については、ここで何度か言及されていますSO =( herehere )。 この回答 でプロジェクトの相対的な依存関係を「クリーン」な方法で処理するソリューションを提案しています。

14
Pascal Thivent

このdependencySetをアセンブリファイル記述子に追加することでそれを行うことができます

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

このアセンブリ記述子は、システムスコープを含むすべての依存関係を追加します

<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>
12

これらの依存関係から<scope>system</scope>句を削除する必要があります。スコープがシステムに設定されている場合、これはアーティファクトが常に利用可能であることを意味するため、依存関係のあるjarにはアーティファクトが含まれません。

2
bruceberk

そもそもシステムスコープであってはなりません。これが問題の原因です。依存関係をリポジトリにインストール/デプロイし、通常のコンパイル(またはランタイム)スコープの依存関係にします。

1
lexicore