问题
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?
回答1:
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.
回答2:
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>
回答3:
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.
回答4:
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>
来源:https://stackoverflow.com/questions/31386309/itext-version-4-2-1-redirected-in-maven-central-repository