9

We're using iText in one of our projects to generate PDF reports, precisely the version 4.2.1 because it is the last free version.

<dependency>
   <groupId>com.lowagie</groupId>
   <artifactId>itext</artifactId>
   <version>4.2.1</version>
</dependency>

When I cloned the repository on an new machine this morning, I faced a lot of compiler errors, because maven redirects to version 5.5.6 and the imports are failing. On our research, we found out, that the pom-file in maven central was changed last week. From now on, it seems to be impossible to add the jar dependency like we did before.

Can anyone tell me, if there is still a way to integrate iText in version 4.2.1 via maven?

justus
  • 584
  • 1
  • 7
  • 19

4 Answers4

9

As documented here, the people who published the iText forks versions 4.x.y didn't follow the rules as explained by Apache:

I have a patched version of the foo project developed at foo.com, what groupId should I use?

When you patch / modify a third party project, that patched version becomes your project and therefore should be distributed under a groupId you control as any project you would have developed, never under com.foo. See above considerations about groupId.

They published an unofficial version of iText using a groupId that led people to believe that they were using an original version of iText, which was not the case. This error has caused much confusion and frustration.

To stop the confusion, iText Group has reclaimed the groupId so that no third party can introduce software that infringes third part rights or even malware into your code base (this is a risk you take when you allow Maven to automatically upgrade).

Your allegation that iText 4.2.1 is the last free version is incorrect. There are some serious issues with iText versions prior to iText 5, but that's another discussion and the subject of a conference talk at JavaOne 2015 entitled IANAL: What Developers Should Know About IP and Legal.

In any case, the easiest solution is for you to change the dependecy to:

<dependency>
  <groupId>com.lowagie</groupId>
  <artifactId>itext</artifactId>
  <version>[1.02b,2.1.7]</version>
  <scope>compile</scope>
</dependency>

See this answer in answer to Dependency error in jasper-reports from itext for even more background information.

Polostor
  • 187
  • 6
  • 25
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
3

First solution

You can download the jar locally and then install it locally with the following command.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> 
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

Use groupId, artifactId, version and packaging you like.

In this case:

mvn install:install-file -Dfile=itext.jar -DgroupId=com.lowagie
-DartifactId=itext -Dversion=4.2.1 -Dpackaging=jar

Second solution:

You can also download the jar locally and reference it with the following dependency group

<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>4.2.1</version>
    <scope>system</scope>
    <systemPath>/PATHTOJAR/itext.jar</systemPath>
</dependency>
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
  • Thank you for your comment. I know about that possibility, but I hoped to find an easier solution... – justus Jul 13 '15 at 14:45
  • I added another solution. Check it – Davide Lorenzo MARINO Jul 13 '15 at 14:49
  • AFAIK this path has to be absolute, isn't it? In this case I would prefer the first solution. – justus Jul 13 '15 at 14:50
  • It is also possible to use `${basedir}` to reference the directory of the project like this: `${basedir}/systemLib//itext.jar` if you created a directory `systemLib` inside your project – Davide Lorenzo MARINO Jul 13 '15 at 14:53
  • That's new for me, thank you! I think we'll give it a try! – justus Jul 13 '15 at 14:55
  • If you find this solution useful you can upvote it and flag it as the correct answer with the green check. Thanks – Davide Lorenzo MARINO Jul 13 '15 at 14:55
  • 2
    @DavideLorenzoMARINO The second solution isn't future-proof as iText 4.2.1 was published on Maven in a way that violates the rules for publishing software on Maven (see my answer). There is a chance that iText 4.2.1 will be moved to another groupId and that the dependency you show in your answer will no longer be valid. – Bruno Lowagie Jul 13 '15 at 15:22
  • Thanks Bruno I didn't know that the version posted on central maven repository wasn't the official one. I checked it now and as you said it points to a different repository. I hope that you will soon take the rights on the com.lowagie group! – Davide Lorenzo MARINO Jul 13 '15 at 15:29
  • @DavideLorenzoMARINO iText Group took the rights (and I am the CEO of the iText Group). That is OK. We are now evaluating whether or not we have the right to remove iText 4.2.0 and 4.2.1. This is more pervasive than introducing 4.2.2 as a *"here is where it stops"* sign. It is not a decision that can be taken lightly. – Bruno Lowagie Jul 13 '15 at 15:35
  • @Bruno From a developer point of view I can say that looking at the maven central repository quickly (as often programmers do) isn't clear that iText 4.2.0 and 4.2.1 are not part of the same group of the other versions. So if possible I hope you can ask to renaming of this two versions to another more appropriate group. – Davide Lorenzo MARINO Jul 13 '15 at 15:48
  • @DavideLorenzoMARINO I understand, but we (iText / Lowagie) didn't cause this problem. We are now facing the question: how do we solve the mess created by third parties? – Bruno Lowagie Jul 13 '15 at 15:58
1

I know this is an old thread, but I'd just cleared out my .m2 folder due to some random issues, and unfortunately then got "The artifact com.lowagie:itext:jar:4.2.1 has been relocated to com.itextpdf:itextpdf:jar:5.5.6".

Just came across this here while trying to remember how we fixed, so thought I'd post solution we had to stop it trying to upgrade.

Goto %UserProfiles%\.m2\repository\com\lowagie\itext\4.2.1\

Edit the itext-4.2.1.pom and remove the following section from the bottom and it won't bother you again and you can happily use 4.2.1 :-

  <distributionManagement>
      <relocation>
          <groupId>com.itextpdf</groupId>
          <artifactId>itextpdf</artifactId>
          <version>5.5.6</version>
          <message>After release 2.1.7, iText moved from the MPLicense to the AGPLicense.
          The groupId changed from com.lowagie to com.itextpdf and the artifactId from itext to itextpdf.
          See http://itextpdf.com/functionalitycomparison for more information.</message>
      </relocation>
  </distributionManagement>
0

I had the same problem using Gradle.

In my build.gradle file, under dependencies,

compile 'com.lowagie:itext:4.2.1'

would fetch itextpdf-5.5.6.jar

Running the command

gradle myapp:dependencies

would show a transitive dependency like this:

\--- com.lowagie:itext:4.2.1
     \--- com.itextpdf:itextpdf:5.5.6

My solution was to upload a copy I had of the original itext-4.2.1.jar to our Nexus repository and give it a different version number.

John Berg
  • 105
  • 6