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

$Class.getResource failed from fat jar packed by maven shade plugin
Java ThreadPool that allocates work by thread name
jackson jersey json : serializing date from java to json
findViewById problems for webview in navigation drawer
For loop how to print to console without leaving on first iteration java
Dispatcher servlet throws exception: NumberFormatException
Overriding equals method to accept doubles inside of Object class. Java
Line break between GWT widgets
How to set shift in String.format dynamically? [duplicate]
Java audio doesn't play in jar file
How can I obtain the -D parameters passed in to Java launch
Set multiple listeners to one method
why one class of same package can't access another?
cannot find symbol : class NumberTools
Java apache POI java.lang.IllegalArgumentException: Position 21504 past the end of the file
Selenium Automatically Closes Chrome Console (attached or window)

Categories

HOME
twitter
testng
debugging
dot
mean-stack
gis
razor
elm
amortized-analysis
dxl
fsm
icloud
ezpublish
opengl-es-2.0
datastax-java-driver
autotools
elasticsearch-hadoop
facebook-php-sdk
modelica
ups
uitypeeditor
tostring
normalizr
samoa
google-pagespeed
nodatime
immutable.js
autocad-plugin
autoconf
abi
functional-testing
sox
mmap
intel-pin
fopen
gsmcomm
unboundid
r-raster
lightswitch-2013
bcd
http-status-code-503
xquery-3.0
titanium-mobile
framemaker
avcapturesession
azure-sql-database
language-concepts
bower-install
ios5
android-browser
objectlistview
mapzen
galen
pdf-reactor
isbn
password-encryption
http-redirect
gpx
appcompat
azure-application-gateway
apache-fop
pubmed
jquery-validate
carrot
sqldf
bind9
chord-diagram
jquery-filter
grails-tomcat-plugin
log4c
phishing
disque
flash-cs5
rvest
pagerank
goose
natvis
icu4j
mutation-observers
purge
dukescript
sortedlist
csquery
tween
codeigniter-routing
tld
aapt
cloud-connect
pyhdf
multiprocessor
oam
aqtime
jelly
mhtml
hamiltonian-cycle
runas
parametric-equations
nsdatecomponents
f#-powerpack
ecl
imac
cxxtest
getresponsestream
mirah
zend-tool
audio-capture
ti-dsp
privilege
phonon
anti-piracy
text-coloring
putchar

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