Jars needed for JasperReports? - java

I have downloaded JasperReports jars (jasperreports-5.6.0-project.zip from here) and toke all the jars in the dist folder. These are the files I added to my project:
jasperreports-5.6.0.jar
jasperreports-applet-5.6.0.jar
jasperreports-fonts-5.6.0.jar
jasperreports-javaflow-5.6.0.jar
But when I try my code I always get this error:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
UPDATE 1
I solved that error and I have a lot of more missing jars. Please tell me all the additional jars needed to use JasperReports.

Ok, as I said I added the jars in the dist folder of the downloaded zip (as showed in the question) to my project and to resolve all the problems I had, I added the next jars from the lib folder to my project:
JasperReports 5.6.0 - ...
...poi-3.7-20101029.jar
...commons-beanutils-1.8.0.jar
...commons-collections-3.2.1.jar
...commons-digester-2.1.jar
...commons-javaflow-20060411.jar
...commons-logging-1.1.1.jar
...groovy-all-2.0.1.jar
...iText-2.1.7.js2.jar
...jcommon-1.0.15.jar
...jfreechart-1.0.12.jar
Hope this helps someone!

these are gradle dependencies i needed to make Jasper Report work in Spring Boot:
// https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports
compile group: 'net.sf.jasperreports', name: 'jasperreports', version: '5.0.1'
// https://mvnrepository.com/artifact/commons-logging/commons-logging
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.2'
// https://mvnrepository.com/artifact/com.lowagie/itext
compile group: 'com.lowagie', name: 'itext', version: '2.1.7'
Hope it helps someone.

Related

gradle executable jar can't include local jar dependencies

SOLVED
WaitingDatabase.connect(WaitingDatabase.java:17)
// added this line
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(
DatabaseProperties.properties.getProperty("waiting_url_oracle"),
DatabaseProperties.properties.getProperty("waiting_user_oracle"),
DatabaseProperties.properties.getProperty("waiting_password_oracle")
);
(Sorry for bad english.)
I have to connect my oracle database, so I downloaded oracle jdbc driver and added in my dependencies. It connected well when I run at intellij, so I built executable jar file with gradle.
However, it couldn't connect to my oracle database. I think it was built without oracle jdbc driver file, because it is a local jar file.
How can I build with all of my dependencies?
If you need more information about my project to solve this problem, please let me know.
Thank you :D
build.gradle
jar {
manifest {
attributes 'Main-Class': 'App'
}
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
// https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.6.0'
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
// oracle 11g jdbc driver
compile files('lib/ojdbc6.jar')
}
cmd
{directory}> java -jar ./{jarFileName}.jar
error message
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:#{address}:{port}:{sid}
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at WaitingDatabase.connect(WaitingDatabase.java:17)
at App.connectDatabase(App.java:22)
at App.main(App.java:5)
WaitingDatabase.connect(WaitingDatabase.java:17)
connection = DriverManager.getConnection(
DatabaseProperties.properties.getProperty("waiting_url_oracle"),
DatabaseProperties.properties.getProperty("waiting_user_oracle"),
DatabaseProperties.properties.getProperty("waiting_password_oracle")
);
file tree
- {root directory}
- lib
- ojdbc6.jar
- src
- main
- java
- App.java
- WaitingDatabase.java
- build.gradle
ADDED
db.properties
sleep-millisecond=1000
waiting_db=oracle
waiting_url_oracle=jdbc:oracle:thin:#{address}:{port}:{sid}
waiting_user_oracle={username}
waiting_password_oracle={password}
waiting_url_mariadb=jdbc:mariadb://{address}:{port}
waiting_user_mariadb={username}
waiting_password_mariadb={password}
What you did is correct:
compile files('lib/ojdbc6.jar')
This will also work:
dependencies {
implementation fileTree(dir: 'lib', include: '*.jar')
The advantage of this is that it will include all the jars in the lib directory without you having to do it manually.
ojdbc6.jar is meant for JDK 6, as stated here.
If you are using > JDK 6, you might want to consider upgrading your ojdbc6.jar and most importantly you might want to check this.
Cheers

IntelliJ no Main Manifest Attribute after creating jar artifact

I am trying to build an jar artefact from this repository. I imported apache commons io and org.json as libraries. When extracting the artifact I find a Manifest file which only contains the information of org.json. You can find the jar here. The manifest file in my Project is not reflected at all. Any help is appreciated. When I run the jar in console with java -jar I get the
Error: No Main Manifest Attribute in XXX.jar.
From the project you provided on github i made the following changes to make it run with java -jar. But first and foremost the project you linked on github does not build with gradle build on a fresh pull.
to make this run you need to add commons io and org.json to you build.gradle file. this makes the build.gradle file look like:
plugins {
id 'java'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.json', name: 'json', version: '20190722'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar {
manifest {
attributes(
'Main-Class': 'de.bergwacht.esslingen.Main'
)
}
}
your project also has alot of unused dependencies that should be removed that were creating gradle warnings.
in AnweseneheitsTableModel remove the imports:
import com.sun.org.apache.xpath.internal.operations.Bool;
in DienstprotokollInvalidArgumentException remove the imports:
import com.sun.javaws.exceptions.InvalidArgumentException;
in MainForm remove the imports:
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.sun.xml.internal.fastinfoset.algorithm.BooleanEncodingAlgorithm;
at this point you can run ./gradlew jar and this will create a jar for you under build/libs
you can run that jar with java -jar build/libs/BWOrgaTool-1.0-SNAPSHOT.jar
that command will run it, it will encounter a NPE:
Exception in thread "main" java.lang.NullPointerException
at de.bergwacht.esslingen.forms.MainForm.<init>(MainForm.java:138)
at de.bergwacht.esslingen.Main.main(Main.java:42)
but thats another problem all together, you can start debugging your program at that point.

Vaadin 12 + Gradle 5 Create executable Fat jar

I need to use Jetty and Vaadin and build a fat jar.
My workspace is based around Gradle 5, Its a gradle multi module project
Parent
Common-Lib
Core-Lib
Jetty+Vaadin
I followed the documentation which i found here:
https://vaadin.com/tutorials/embedded-jetty-server-in-vaadin-flow
The documentation explains how to create Jetty's WebAppContext and start Jetty Server instance all based around maven.
Expect as i said my workspace is based around gradle, so instead of copying the pom.xml i rewrote it to the gradle build script which looks as follows:
plugins {
id 'idea'
}
group = 'some.example.jetty.and.vaadin.fatjar'
version = '1.0.0'
dependencies {
implementation project(':Core-Lib')
implementation project(':Common-Lib')
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
compile group: 'org.eclipse.jetty', name: 'jetty-continuation', version: '9.4.14.v20181114'
compile group: 'org.eclipse.jetty.websocket', name: 'websocket-server', version: '9.4.14.v20181114'
compile group: 'org.eclipse.jetty.websocket', name: 'javax-websocket-server-impl', version: '9.4.14.v20181114'
compile group: 'com.vaadin', name: 'vaadin-core', version: '12.0.7'
}
My problem is that during the build gradle outputs a .war file. I cannot use a .war file.
This project is supposed to be a plug-in module for another application, which i do not have sources for. The application just loads a jar files from specific folder, only jar extension is supported.
My question is: How can i create standard "unshaded" uber jar/fat jar instead of .war
With the word "unshaded" i want to unpack all JAR dependencies, and repack them into the final JAR.

Using JavaCV and Realm together causes "java.lang.UnsatisfiedLinkError"

I have recently been getting the following error by attempting to start an instance of JavaCV's FFmpegFrameGrabber:
java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at org.bytedeco.javacpp.Loader.load(Loader.java:413)
at org.bytedeco.javacpp.Loader.load(Loader.java:381)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2597)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:386)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:380)...
While solutions to this problem exist, none worked for me.
Through many trials i have discovered that weirdly enough, if i do not include Realm in my project, i no longer receive this error.
Here is the part of my build.gradle file in which I include all of these libraries:
compile group: 'org.bytedeco', name: 'javacv', version: '1.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-x86'
// ORM
compile 'io.realm:realm-android:0.87.2' // Tested NOT OK - Causes JavaCV to crash
//
I am thinking that there may be a solution to this problem that i am not aware of. I found no mention anywhere on the internet about library incompatibility or why this behaviour may occur.
I will edit this post with any additional details that anyone might need.
Any help would be greatly appreciated.
EDIT
I attempted to apply the fix described here.
Now my packaging options look like this:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
exclude "lib/arm64-v8a/librealm-jni.so"
}
Unfortunately, this change has no effect. I'm still stuck.
With the help of one of my coleagues i have been able to solve this issue.
In adition to the steps described in the question, we:
Copyed all of the .so files in the app/src/main/jniLibs/armeabi and app/src/main/jniLibs/armeabi-v7a folders
Added
ndk {
abiFilters "armeabi-v7a"
}
to the defaultConfig part of the module's build.gradle file
Added
lintOptions {
abortOnError false
}
to the android part of the module's build.gradle file
I will try to provide further clarifications to anyone that needs them if i am able.
Firstly this issue occurs because of Gradle doesn't resolve dependencies properly from maven profile ..In my case only x86 depdendecies shipped to APK. that means code above works only on x86 cpu architecture. solution should be done on Android Studio. but as workaround I did this:
Download binary javacv-platform-1.3.1-bin.zip. It's from: https://github.com/bytedeco/javacv
Inside directory javacv-bin copy these jars to new directory
ffmpeg-android-arm.jar
opencv-android-arm.jar
ffmpeg-android-x86.jar
opencv-android-x86.jar
For 2.1 2.2 files, Extract these jars and go to lib then or armeabi. Then copy all *.so files into your project under:
app/src/main/jniLibs/armeabi/
app/src/main/jniLibs/armeabi-v7a/
you might do the same with 2.3 * 2.4 jars by copying dependencies into app/src/main/jniLibs/x86/ . just check your apk if it really doesn't have them.
That's it.

How do I get IntelliJ to resolve Gradle dependencies for custom source sets?

When IntelliJ opens a build.gradle file it will generate an IntelliJ project with the Gradle dependencies resolved and added to the project scope. This works great for the "compile" source set and the "test" source set, however I can not get this to work for custom source sets.
I want to have IntelliJ resolve the dependencies for my componentTest source set. How do I tell IntelliJ to resolve these dependencies and add them to scope?
dependencies {
// main source set, "compile" scope in IntelliJ
compile(group: 'com.google.guava', name: 'guava', version: '18.0')
// test source set, "test" scope in IntelliJ
testCompile(group: 'junit', name: 'junit', version: '4.11')
// my custom source set, not added to any scope in IntelliJ
componentTestCompile(group: 'org.springframework', name: 'spring', version: '3.0.7')
}
Details: IntelliJ 13.1.2, Gradle 1.11
This is described in Gradle user guide - http://www.gradle.org/docs/current/userguide/idea_plugin.html and http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
You will need to add something like:
idea {
module {
scopes.TEST.plus += [ configurations.componentTestCompile ]
}
}
to your build.gradle file.

Categories