jasperreports_extension.properties由maven程序集插件覆盖 [英] jasperreports_extension.properties overwritten by maven assembly plugin

查看:936
本文介绍了jasperreports_extension.properties由maven程序集插件覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了拥有一个可执行jar,我包含了maven依赖项。一切正常,但 jasperreports_extension.properties 。 Jasper已经有一个替换我的默认值。

In order to have an executable jar I include the maven dependencies. Everything works fine but the jasperreports_extension.properties. Jasper already has a default one that replaces mine.

我想知道如何将两个文件(默认文件和自定义文件)组合到jar文件中。实际上我已经手动组合了两个设置,现在我想找到替换汇编插件复制的文件的方法,我已经合并了。

I'd like to know how to combine both files (the default and custom one) into the jar file. Actually I have manually combined both settings and now I want to find the way to replace the file that assembly plugin copies with the merged one I already have.

这是我的当前maven程序集插件设置:

This is my current maven assembly plugin settings:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>${maven-assembly-plugin.version}</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>
                            com.test.sample.MainClass
                        </mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

这些是我在报告中添加一些字体的自定义设置:

These are my custom settings to add some fonts to the reports:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory 
net.sf.jasperreports.extension.simple.font.families.ireportfamily1453367638844=fonts/fontsfamily1453367638844.xml

依赖项:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.2.0</version>
</dependency>

编辑:

考虑依赖关系


  • jasperreports_extension.properties 位于(根级别)
    jasperreports-6.2.0.jar

  • jasperreports_extension.properties 在里面(根级别)
    jasperreports-fonts-6.0.0.jar (这只是一个测试依赖项)

  • jasperreports_extension.properties is inside (root level) the jasperreports-6.2.0.jar
  • jasperreports_extension.properties is inside (root level) the jasperreports-fonts-6.0.0.jar (this is only a Test Dependencies)

在我用阴影1替换了程序集插件后,我报告的初始问题是固定的,但我得到了这个新问题:

After I replaced the assembly plugin by shade one, the initial issue I reported is fixed, however I got this new one:

    Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry org/bouncycastle/mail/smime/SMIMEEnvelopedGenerator$EnvelopedGenerator.class
        at sun.security.util.SignatureFileVerifier.verifySection(Unknown Source)
        at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
        at sun.security.util.SignatureFileVerifier.process(Unknown Source)
        at java.util.jar.JarVerifier.processEntry(Unknown Source)
        at java.util.jar.JarVerifier.update(Unknown Source)
        at java.util.jar.JarFile.initializeVerifier(Unknown Source)
        at java.util.jar.JarFile.getInputStream(Unknown Source)
        at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
        at sun.misc.Resource.cachedInputStream(Unknown Source)
        at sun.misc.Resource.getByteBuffer(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

我在此之后解决了这个签名问题:无效的签名文件当试图运行.jar时

I solved this signature problem following this: "Invalid signature file" when attempting to run a .jar

推荐答案

我假设你的问题是你有一个名为<的文件code> jasperreports_extension.properties 作为项目的资源,位于 src / main / resources 内。因为您依赖于 jasperreports ,所以在类路径的根目录上也恰好有一个名为 jasperreports_extension.properties 的资源当你制作 jar-with-dependencies 时,一个人会覆盖另一个。

I'm assuming from your question that you have a file called jasperreports_extension.properties as a resource of your project, located inside src/main/resources. Because you have a dependency on jasperreports that also happens to have a resource called jasperreports_extension.properties at the root of the classpath, one is overwriting the other when you are making the jar-with-dependencies.

要解决这个问题,你应该删除 maven-assembly-plugin 并使用 maven-shade-plugin 。此插件提供现成的变压器能够将两个属性文件合并在一起:通过合并,我的意思是其中一个文件被附加到另一个文件的末尾:

To tackle this problem, you should drop the maven-assembly-plugin and use maven-shade-plugin instead. This plugin provides out of the box a transformer that is able to merge two properties file together: by merging, I mean that one of the file is appended to the end of the other one:


某些jar包含具有相同文件名的其他资源(例如属性文件)。为避免覆盖,您可以选择通过将其内容附加到一个文件来合并它们。

Some jars contain additional resources (such as properties files) that have the same file name. To avoid overwriting, you can opt to merge them by appending their content into one file.

在这种情况下,示例配置将是:

In this case, a sample configuration would be:

<plugin>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.4.3</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>jasperreports_extension.properties</resource>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <mainClass>com.test.sample.MainClass</mainClass>
          </transformer>
        </transformers>
        <createDependencyReducedPom>false</createDependencyReducedPom>
      </configuration>
    </execution>
  </executions>
</plugin>

这将产生最终的胖JAR,其中的内容为jasperreports_extension.properties 将是您的文件的内容和来自依赖项的文件。

This will produce a final fat JAR where the content of jasperreports_extension.properties will be the content of your file and the file coming from the dependency.

此外,它还将具有正确的 MANIFEST 因为我们为插件指定了哪个类是主类。

Also, it will also have a correct MANIFEST since we specified to the plugin which class was the main class.

作为一方请注意,当您制作胖JAR时, maven-assembly-plugin 仅提供基本支持。 从他们的主页

As a side note, when you are making fat JAR, the maven-assembly-plugin only provides basic support. From their homepage:


如果您的项目想要将工件打包在超级jar中,则程序集插件仅提供基本支持。要获得更多控制,请使用Maven Shade插件。

If your project wants to package your artifact in an uber-jar, the assembly plugin provides only basic support. For more control, use the Maven Shade Plugin.

这篇关于jasperreports_extension.properties由maven程序集插件覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆