0

我正在使用 Maven 来构建我的项目。我想创建包含一些依赖项的程序集 jar,所以我编写了自定义程序集描述符。

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.guavus</groupId>
  <artifactId>Exporter</artifactId>
  <version>atlas2.1</version>
  <packaging>jar</packaging>

  <name>Exporter</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <aspectj.version>1.6.10</aspectj.version>
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.guavus.exporter.Exporter</mainClass>
            </manifest>
          </archive>
          <descriptors>
            <descriptor>/Users/archit.thakur/Documents/Code_dev_cdn_mapreduce/exporter/src/main/configurator.xml</descriptor>
          </descriptors>
          <!--
          <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>     
              -->
          <finalName>Exporter-${project.version}</finalName>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>


  <dependencies>
    <!-- local snapshots  -->
    <dependency>
      <groupId>com.guavus</groupId>
      <artifactId>CubeCreator</artifactId>
      <version>atlas2.1</version>
    </dependency>
    <dependency>
      <groupId>com.guavus</groupId>
      <artifactId>ConcurrentFlows</artifactId>
      <version>atlas2.1</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.6.11</version>
    </dependency>
    <dependency>
      <groupId>ps</groupId>
      <artifactId>thriftGenerated</artifactId>
      <version>atlas2.1</version>
    </dependency>
    <!-- local snapshots  --><!-- local 3rd Party -->
    <dependency>
      <groupId>apache</groupId>
      <artifactId>libthrift</artifactId>
      <version>0.5.0</version>
    </dependency>
    <!-- local 3rd Party --><!-- remote 3rd Party -->
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-core</artifactId>
      <version>0.20.203.0</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>1.7.1</version>
    </dependency>

    <!-- remote 3rd Party --><!-- test libs --><!-- test libs -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.6.11</version>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.16</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.2</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-access</artifactId>
      <version>1.0.1</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.1</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>1.0.1</version>
    </dependency>
  </dependencies>

</project>

描述符:

<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">
  <id>dep</id>
  <formats>
    <format>jar</format>
  </formats>

  <dependencySets>

    <dependencySet>
      <scope>runtime</scope>
      <unpack>true</unpack>
      <useProjectArtifact>true</useProjectArtifact>
      <includes>
        <include>log4j:log4j</include>
        <include>org.slf4j:slf4j-api</include>
        <include>ch.qos.logback:logback-access</include>
        <include>ch.qos.logback:logback-classic</include>
        <include>ch.qos.logback:logback-core</include>
        <include>com.guavus:Exporter</include>
      </includes>
    </dependencySet>

  </dependencySets>

</assembly>

问题是,它在像“Exporter-atlas2.1//”这样的目录结构中创建了具有类的 jar。例如,“Exporter-atlas2.1/ch/qos/logback/classic/util/EnvUtil.class”。这就是它在运行时抛出 ClassNotFoundException 的原因。我期待课程出现在“/”,例如。“ch/qos/logback/classic/util/EnvUtil.class”。

4

3 回答 3

0

Exporter-atlas2.1 不只是您的 jar 的名称(因为它被设置为 finalName),并且当您解压缩时,您会将此目录作为解压缩依赖项的父目录?

于 2013-01-22T12:50:02.653 回答
0
<includeBaseDirectory>false</includeBaseDirectory> 

在组装配置器中解决了这个问题。

于 2013-01-28T07:48:49.037 回答
0

很难知道这是否会解决您的问题,但您可以指定一个

<outputDirectory>

对于一个<dependencySet>。但是,当您解压缩依赖项时,这可能不是正确的解决方案。

顺便说一句,你为什么打开包装?

于 2013-01-22T13:52:36.817 回答