java


Maven Build with Dependencies Jasper Reports [duplicate]


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.
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.
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
And the dependency:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.2.0</version>
</dependency>
EDIT:
Considering the dependencies:
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)
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)
I solved this signature problem following this: "Invalid signature file" when attempting to run a .jar
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.
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:
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>
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.
Also, it will also have a correct MANIFEST since we specified to the plugin which class was the main class.
As a side note, when you are making fat JAR, the maven-assembly-plugin only provides basic support. From their homepage:
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.

Related Links

How to set alert cancel on Popup In selenium web driver
How to get all the keys of json in java using Gson or org.json library? [duplicate]
Can someone explain join method in Java Thread class?
Spring Boot PropertySources in test environment
How to get image source and description from html data using Jsoup
How to clear java.lang.IndexOutOfBoundsException in selenium webdriver
Java Reflection: Get type parameter of generic interface from implementation class
Start Spring Boot War in a tomcat instance
HDIV : I'm getting a NullPointerException when accessing a page
Android Material Design Toolbar extension
Spring Maven org.springframework.beans.factory.BeanCreationException
Java Decimal Format parsing issue
Taking value from array in JSON in Android Studio
Running akka app in jenkins
One mystery string in Java
JAXB bindings of complex type to new classname

Categories

HOME
twitter
hive
isabelle
google-play
homebrew
hp-exstream
office365api
react-router
xmpp
malloc
pivotal-cloud-foundry
fancybox
django-imagekit
volttron
midi
nstableview
circular-dependency
alignment
hapi
windows-7-x64
solaris-10
connection-string
normalizr
tibco-mdm
javacv
fish
traffic
fgetcsv
atlassian-crucible
librato
nat
nouislider
tinymce-4
preg-match
ecto
semantic-versioning
pdb
vsts-build-task
automake
multilingual
streamsets
service-discovery
twitch
bootstrapper
lumberjack
cookiecutter-django
dism
email-templates
import-from-excel
s
scrollable
logparser
qtwebview
titanium-android
dwscript
pycaffe
objective-c-swift-bridge
instant
intrusion-detection
gridview-sorting
livequery
revolution-r
google-places
marching-cubes
wyam
splash
streambase
block-device
flask-cors
eol
starcluster
phpthumb
terminal-services
oam
ivyde
google-cloud-save
odata4j
gwt-rpc
django-nonrel
spring-validator
eventlistener
kyotocabinet
automount
jspinclude
enter
dotnethighcharts
jquery-ui-layout
php-parser
qt-jambi
spyware
subgurim-maps
genshi
tomcat-valve
xdomainrequest
telerik-scheduler
remember-me
site.master
gamequery
infrastructure
firefox4
libs
adrotator
aquaticprime

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App