Replace JasperReport iText 2.1.7 with latest iText 7.0.1 - jasper-reports

We are using JasperReport 6.1.0 which has a dependency to com.lowagie:itext:jar:2.1.7.js2. It looks like iText 2.1.7 has IP issue, and iText is asking all users to use the latest version which requires a commercial license. So we would like to buy iText license. Now iText latest version is 7.0.1. I tried did below steps to replace JasperReport's iText 2.1.7 with latest iText 7.0.1:
1. Exclude default itext 2.1.7 dependency in pom.xml
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.0</version>
<exclusions>
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
...
2. Add new iText jars in pom.xml
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>barcodes</artifactId>
<version>7.0.1</version>
<!-- barcodes depends on kernel -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>font-asian</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.1</version>
<!-- forms depends on kernel and layout -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>hyph</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.0.1</version>
<!-- kernel depends on io -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.0.1</version>
<!-- layout depends on kernel -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>7.0.1</version>
<!-- pdfa depends on kernel -->
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>sign</artifactId>
<version>7.0.1</version>
<!-- sign depends on kernel, layout and forms -->
</dependency>
3. Run mvn and test report function, I got below error:
2016-11-17 14:43:36,520 ERROR [c.i.c.d.DeferredOperationManager] [ Thread-49] Exception on Deferred Operation. Operation UUID: 2a647922-d6d0-450d-9b2d-4d97638ba03f. UI Error key:d9a16093-be20-4278-9f8b-93120c0a2231 - Error: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
It looks like JasperReport is trying to find old iText classes which namespace is "com.lowagie...".
I tried to unzip the new iText 7.0.1 jar, the classes are in package "com.itextpdf...".
How can I make the JasperReport call the new iText jar?

You can not replace iText 2.1.7 with iText 7 because the differences between the two versions are too big. We do know of some people who moved to using iText 5 with JasperReports. That requires a number of changes to JasperReports such as changing the package names from com.lowagie to com.itextpdf (*) and changing references to com.lowagie.text.Color to com.itextpdf.text.BaseColor.
At iText, we noticed that we were hitting the ceiling with iText 5. For instance: we store text using char which means that each character is stored using only 2 bytes. That wasn't sufficient if we wanted to support Hindi. We had to rewrite the complete font layer if we wanted to add support for Indic languages to iText. "Replacing the font layer" in iText 5 would have been really difficult since the font layer is the foundation on which all the rest of the code is built. Hence our decision to rewrite the complete API.
You can watch a video that goes into more detail regarding this decision here: Devoxx 2016: "Oops I broke my API"
However: the biggest problem with replacing iText 2.1.7 with iText 7, is that JasperReports depends on PdfGraphics2D and we haven't ported that part to iText 7 (yet). We might even decide not to port that part ever, because it is impossible to create PDF/UA if you choose to use PdfGraphics2D (and PDF/UA is getting more and more important).
(*) In 2009, I decided to remove my name from the package names. When I first released iText, I only owned the lowagie.com domain, and I used com.lowagie packages for all the Java code I wrote. I didn't expect iText to become such a success. When everyone started to use iText, everyone started to ask me questions personally. I didn't have a life anymore. Hence I created a company, we professionalized iText and replacing com.lowagie with the more neutral com.itextpdf was one of those professionalizations.

Related

How do I update Itext7 to version 7.1.1

This seems like it should be simple but I cannot find anything on how to upgrade to newer versions of itext7. I am using an Eclipse maven project with itext7 version 7.0.4 and would like to update to 7.1.1. However, I can find nothing that tells me how to do that. Neither the Eclipse update menu or the Maven menu has an option to update itext7. Can someone point me to the documentation on how to do an update? TIA.
After answer:
I am not getting the libraries but instead getting conflicts:
I can't seem to post my pom.xml using code tags (I guess the formatter has a problem with XML code because of the <>) but I will include it if someone tells me how. I've uploaded the pom file to DropBox:
pom.xml
(Turning #mkl's and #amedee's comments into an answer)
In your project there is a file pom.xml which contains the Maven project definition. In there is a dependencies section with entries for the iText artifacts (among others). The version is therein. Well, it could also be in a separate dependencies management section or in a parent pom.xml referenced in your file.
As soon as you update the POM file, you can update the Eclipse project configuration in your Eclipse Maven menu. That will, if necessary, automatically download the jar artifacts. If your Eclipse Maven integration is properly configured, that is, and if your computer has proper internet connectivity.
Old versions will remain in your local repository but won't be in the class path anymore.
Also check out our getting started guide. Which contains an example POM snippet.
https://developers.itextpdf.com/itext7/download-and-install-information/Java
If you put your iText version number in POM properties, then you only have to update the value once when you want to upgrade. Like this:
<properties>
<itext.version>7.1.1</itext.version>
</properties>
and then
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>${itext.version}</version>
</dependency>
...
</dependencies>

can't create dependence of msqlconnector in pom.xml in eclipse

I can't create the dependency for mysql in eclipse.
error Missing artifact mysql:mysql-connector-java:jar:5.7.9
I use maven console to create the dependency, but It doesn't work
What can I do??
Most likely this is because the current version in 5.* series is 5.1.40.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
There is no version 5.7.9. You can check current version here or all available here.

Service Component missing in AEM

I am trying to create a project in Eclipse using the AEM Developer Tools plugin. The project is published in AEM server and can be seen in: Websites and CRXDE Lite.
The project was created using Maven Archetype-10 in Eclipse and the default project has two pages in English and French. When I open the page in the Site URL, I get the end page, where the message from the HelloWorldModel class should be displayed, along with the other text. But I don't get the message from the respective class. Instead, I am getting the following error message:
org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.sightly.SightlyException: Cannot find a a file corresponding to class com.pen.mypen.core.models.HelloWorldModel in the repository.
It looks like the Java files in the CORE project are not published or are not visible to the web page. But the 3 packages: Core, Apps, and Content are all published and synchronized in Eclipse. Is there any way to check if the Java package is deployed to AEM server? Please guide me to what I am missing here. Please find the error stack trace below:
Caused by: org.apache.sling.scripting.sightly.SightlyException: Cannot find a a file corresponding to class com.pen.mypen.core.models.HelloWorldModel in the repository.
at org.apache.sling.scripting.sightly.impl.compiler.SightlyJavaCompilerService.compileRepositoryJavaClass(SightlyJavaCompilerService.java:212)
at org.apache.sling.scripting.sightly.impl.compiler.SightlyJavaCompilerService.getInstance(SightlyJavaCompilerService.java:113)
at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.provide(JavaUseProvider.java:127)
at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:84)
at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:66)
at org.apache.sling.scripting.sightly.apps.pen.components.content.helloworld.SightlyJava_helloworld.render(SightlyJava_helloworld.java:53)
at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderUnit.render(RenderUnit.java:54)
at org.apache.sling.scripting.sightly.impl.engine.SightlyScriptEngine.evaluateScript(SightlyScriptEngine.java:92)
at org.apache.sling.scripting.sightly.impl.engine.SightlyScriptEngine.eval(SightlyScriptEngine.java:78)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)
UPDATE
AEM - 6.2
Eclipse - Luna
Java - 1.8
You can check the following things:
http://SERVER:PORT/system/console/bundles shows all the java bundles that are installed on your AEM machine. Check if your bundle is listed there. If not then it could not be installed => check the error log
If your bundle is listed there, check if it is status is active, if not there might be missing dependencies or stuff like that. => click the bundle name to see more details what went wron, also check the error log.
If the status is active, click on the bundle and see if the package that contains your java class is listed in the Exported Packages section.
If the package is listed, you might need to check the error log (again).
UPDATE (because of AEM 6.2):
The problem with your project is, that with AEM versions prior to 6.2, there was a dependency to javax.inject version 0 whereas now they need version 1 and that's not reflected in the pom.xml.
Just add this to your pom.xml of the core project - that's the only change you'll have to do:
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
and everything will work. Sorry for the confusion...
In case you are using SlingModels the javax.inject is exposed by the org.apache.sling.models.api
Can you check your pom for the SlingModel dependencies
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
<version>VERSION_NUMBER</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
<version>VERSION_NUMBER</version>
<scope>provided</scope>
</dependency>
Check the VERSION_NUMBER you are using and then in /system/console/bundles verify that the same version bundle is present and Active.
With AEM 6.x the Sling Model bundles are available by default. The 6.0 will have a lower version 1.0.x. Fixing the version either by updating the pom or installing the SlingModel bundles with version VERSION_NUMBER fix your issue.
Update for 6.2
For 6.2 with models with version 1.2.2 use following in dependencies -
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
geronimo-atinject_1.0_spec is the one that is exposing javax.inject in sling models 1.2.2
Sharing my solution which will be helpful.
Tested on AEM 6.2 working perfect.
In core pom.xml file add Import-Package tag with "javax.inject;version=0.0.0,*" inside "org.apache.felix" plugin tag.
Following is the sample :
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!--
<Embed-Dependency>
artifactId1,artifactId2;inline=true
</Embed-Dependency>
-->
<!-- Import any version of javax.inject, to allow running on multiple versions of AEM -->
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
<Sling-Model-Packages>
com.next.sample_test_impl.core
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>

GWT 2.8 websocket support

Does jetty server in gwt 2.8 support websocket now? As I know it did not support before. If there is a positive answer, then how to make it work? Stripping out jetty-8 and replaceing it with jetty-9 is not a good idea I think.
then how to make it work?
I want to elaborate a bit on this after the GWT 2.8.0 release. The only thing required for using javax.websocket is the knowledge of the Jetty version packaged with GWT and the following set of Maven dependencies (see also the Jetty WebSocket examples on GitHub):
<project>
<properties>
<sdm.jetty.version>9.2.14.v20151106</sdm.jetty.version>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${sdm.jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${sdm.jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</depencies>
</project>
Make doubly sure that the scope is provided - for the former two this will mean they are not packaged into the final app - you will be requiring those only when running the SuperDev-Mode (SDM). Ifjava.websocket-apiwas on your classpath probably the annotation-based configuration will not work at all (at least in embedded Tomcat and Jetty) due to the annotations being picked up by the wrong class loader (see also related question WebSocket 404 error for more info on this topic).
GWT 2.8 has switched to Jetty 9.2, and now supports Servlets 3.1 servlets container initializers, which I think are being used to setup WebSockets.
I haven't tried it but I suppose that you can now have WebSockets in DevMode, provided you add the required dependencies to the classpath.
You can also simply use a separate server rather than the one embedded into DevMode.

Using Drools on Jetty

I am trying to start up a webapp that uses Drools 5.2.0.M1. I get the following stacktrace on startup:
java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/CategorizedProblem;
at org.drools.commons.jci.compilers.EclipseJavaCompiler$3.acceptResult(EclipseJavaCompiler.java:336)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:335)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:366)
at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:51)
at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:366)
at org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:55)
I have the jars in my pom:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>5.2.0.M1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.5.1</version>
</dependency>
Why Can't it find CompilationResult.getProblems()?
JDT isn't backwards compatible.
Check the drools-compiler pom (of exactly the version you're using) on which version of ecj it depends and use that version. Or don't declare ecj at all, it's a transitive dependency for drools-compiler anyway.
PS: upgrade to drools 5.2.0.CR1 (or final once it's out)
I had a similar problem. I was having a web-app using Jetty 6. Jetty 6 which apparently bringing in a non-compatible version of JDT. After switching to Jetty 7 the problem was solved.