English 中文(简体)
Maven——我怎么能够把任意的那类 entry子带入jar?
原标题:Maven - how can I add an arbitrary classpath entry to a jar?
  • 时间:2009-10-02 14:59:45
  •  标签:

我的情况不寻常,我需要在可起诉的杰尔宣言中加上任意的班次入境(这在杰尔档案中注明)。 (用于桌面应用。)

maven-jar-plugin利用maven Dependencies生成了“Class-Path”号标语,似乎没有任何办法增加任意条目。

我也以“等级”参数对开始申请的批量档案进行硬化分类,但我可以说明如何让Maven把班次过滤到批量档案中。

最佳回答

我发现这个问题很容易解决。 您可添加以下内容:<Class-Path>lement;maniEntries> content and set <addClassPath>true</addClassPath> to <maniwel>。 因此,<代码><Class-Path>要素自动添加到类别-path。 例:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
        <addClasspath>true</addClasspath>
        <mainClass>your.main.Class</mainClass>
      </manifest>
      <manifestEntries>
        <Class-Path>../conf/</Class-Path>
      </manifestEntries>
    </archive>
  </configuration>
</plugin>
问题回答

最新信息:在此,如何将一个班子过滤为习俗清单。

缩略语 目标可配置成按特性格式(即:等级=[等级])向档案输出。 之后,你将过滤器内容混为一谈,以使用生成的分类卷宗,并没收将过滤的资源目录。

例如:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.1</version>
      <executions>
        <execution>
          <phase>generate-resources</phase>
          <goals>
            <goal>build-classpath</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <outputFilterFile>true</outputFilterFile>
        <outputFile>${project.build.directory}/classpath.properties</outputFile>
      </configuration>
    </plugin>
    <plugin>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifestFile>
            ${project.build.outputDirectory}/META-INF/MANIFEST.MF
          </manifestFile>
        </archive>
      </configuration>
    </plugin>
  </plugins>
  <filters>
    <filter>${project.build.directory}/classpath.properties</filter>
  </filters>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
    </resource>
  </resources>
</build>

然后在弧/主要/资源/气象局-INF/管理中具体说明如下内容。 MF:

Bundle-Version: 4.0.0
...
Classpath: ${classpath};[specify additional entries here]

< Note:, 采用标准窗口路段分离器()进行这种处理时,产生途径被拆掉分离器(注在欧罗特公司进行罚款)。 可以通过具体说明<代码><fileSeparator>±</fileSeparator> in the build-classpath 目标配置。


http://maven.apache.org/plugins/maven-jar-plugin/examples/mani.4/1999/-customization.html 组合。 为此,请在您的日程上添加这样的内容。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  ...
  <configuration>
    <archive>
      <index>true</index>
      <manifest>
        <addClasspath>true</addClasspath>
      </manifest>
      <manifestEntries>
        <mode>development</mode>
        <url>${pom.url}</url>
        <key>value</key>
      </manifestEntries>
    </archive>
  </configuration>
  ...
</plugin>

rel=“noretinger”>archiver specification提供了一些选择。 见rel=“noretinger”>examples page ,用于配置该类组别的备选办法。

如果你不做这些工作,你可以,建立含有所需条目的特性,并使用filtera/pope 。

我得以略微修改了Rich Seller办法,避免了<代码>。 Error assembling JAR: Unable to berew file (line so long) issue that was referred in the comments.

我想通过<代码>依赖性-maven-plugin复制所有受抚养人,在.jar档案中参考。 我不能使用<条码>和代号;addClasspath>true</addClasspath>Maven Jar Plugin的选项,因为在我的Jar Levelpath(我只复制了一批受扶养人)。

在这方面,我如何工作。

首先,我使用Maven Dependency Plugin做复制,同时形成一个阶级变量。 采用<代码><outputProperty> 我把它放在财产上,而不是档案中:

  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
      <execution>
        <phase>generate-resources</phase>
        <goals>
          <goal>copy-dependencies</goal>
          <goal>build-classpath</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/lib</outputDirectory>              

          <!-- These properties are for build-classpath. It creates a classpath for the copied
               dependencies and puts it in the ${distro.classpath} property. The jar Class-Path
               uses spaces as separators. Unfortunately <pathSeparator> configuration property
               does not work with a space as value, so the pathSeparator is set to a character
               here and this is then replaced later using the regex-property plugin. -->
          <prefix>lib</prefix>
          <outputProperty>distro.classpath</outputProperty>
          <pathSeparator>:</pathSeparator>
        </configuration>
      </execution>
    </executions>
  </plugin>

The syntax of the Jar Manifest Class-Path used a space as separateors. 虽然依赖性金刚金有<条码>和>;pathSeparator> 财产,但如果是一片空间,则这种无情地忽视了价值。 因此,我仅用硬体编码,一面价值,然后使用建筑辅助器-装配机,将其替换为我所需要的空间:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
      <execution>
        <phase>process-resources</phase>
        <goals>
          <goal>regex-property</goal>
        </goals>
        <configuration>
          <!-- Here the value of property for the jar the Class-Path is replaced to have a space
               as separator. Unfortunately <replacement> does not work if a single space if specified
               so this uses the surrounding .jar and lib to provide some content. -->
          <name>distro.classpath.replaced</name>
          <value>${distro.classpath}</value>
          <regex>[.]jar[:]lib</regex>
          <replacement>.jar lib</replacement>
        </configuration>
      </execution>
    </executions>
  </plugin>

这里还有<代码><replacement> Value don t work if it s only aspace, so I m around it with the text that is around.

最后,我可以利用Maven Jar Plugin来收回被替换为分离者的财产。 由于我把这门课堂的价值放在黑白化定义中(而不是从过滤的档案中取而代之),马尼夫案的线上长度限制将自动处理,而且似乎没有太长的问题:

  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
      <archive>
        <manifest>
          <mainClass>org.acme.Main</mainClass>
        </manifest>
        <manifestEntries>
          <!-- Include the computed classpath with all copied dependencies in the jar here -->
          <Class-Path>${distro.classpath.replaced}</Class-Path>
        </manifestEntries>
      </archive>
    </configuration>
  </plugin>




相关问题
热门标签