103

I found net.sf.json-lib in the central repository. Copy-pasted the dependency (with version 2.3), and then when I build I get this error:

[INFO] Unable to find resource 'net.sf.json-lib:json-lib:jar:2.2.3' in repository central (http://repo1.maven.org/maven2)

[ERROR] BUILD ERROR
[INFO] ---------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) net.sf.json-lib:json-lib:jar:2.3

  Try downloading the file manually from the project website.

I tried using version 2.2.3, but I'm getting the same error. Why am I getting this error? I can override it by installing it locally, but I want to understand what the problem is.

Edit - I deleted the package from my local repository, and tried again, this time getting a checksum error. I guess I should file a bug report with json-lib.

[WARNING] *** CHECKSUM FAILED - Error retrieving checksum file for net/sf/json-lib/json-lib/2.3/json
-lib-2.3.pom - IGNORING
ripper234
  • 222,824
  • 274
  • 634
  • 905
  • It looks like the file in maven central has a incorrect checksum...you must decide if you trust it anyway or don't. – khmarbaise Nov 13 '10 at 15:45

4 Answers4

278

Looking at the maven-central repo, you need to specify a classifier for this dependency.

Either jdk13 or jdk15, like this:

<dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>2.4</version>
    <classifier>jdk15</classifier>
</dependency>
Gary
  • 13,303
  • 18
  • 49
  • 71
Petar Tahchiev
  • 4,336
  • 4
  • 35
  • 48
  • 2
    I am having the same problem. In `BuildConfig.groovy`, I do: `dependencies { runtime group:'net.sf.json-lib', name:'json-lib', version:'2.4', classifier:'jdk15' }` but to no avail. I get `Failed to resolve dependency.`. Any idea why ? – Alexandre Bourlier May 30 '12 at 16:48
  • 2
    Right. It doesn't help that http://search.maven.org/#artifactdetails%7Cnet.sf.json-lib%7Cjson-lib%7C2.4%7Cjar is lying to us, and omitting the classifier. – djsadinoff Nov 27 '12 at 16:31
  • FYI, for those using Play Framework 1.x, you can't use this jar from maven central - https://play.lighthouseapp.com/projects/57987-play-framework/tickets/986-support-for-classifier-in-dependenciesyml#ticket-986-3 – ripper234 Dec 26 '12 at 16:07
  • Nice! Wonder why the classifier wasn't set when I initially added the dependency that had jdk15. – heyomi Jan 26 '13 at 14:52
  • 2
    What's the equivalent for ivy? – Ron Romero Jul 19 '13 at 17:24
  • Thank you Peter, it really helped –  Feb 04 '16 at 14:51
  • I got following error, Could not find artifact net.sf.json-lib:json-lib:jar:2.4 in wso2-nexus (http://maven.wso2.org/nexus/content/groups/wso2-public/). Onces add "jdk15" this line additionally, this build working without any issue. Thanks lot – Thusitha Indunil Apr 25 '19 at 03:23
  • hello, thx for the answer. question: how did you know about the classfier ? – Arthur Silva Dec 28 '22 at 15:04
27

For gradle as sample

compile 'net.sf.json-lib:json-lib:2.4:jdk15'

OR

compile group: 'net.sf.json-lib', name: 'json-lib', version: '2.4', classifier: 'jdk15'

I searched for more classifier's could not find anything other than jdk15 (don't go looking or jdk16 or jdk17)

Siddharth
  • 9,349
  • 16
  • 86
  • 148
Rinat Mukhamedgaliev
  • 5,401
  • 8
  • 41
  • 59
  • This didn't work for me. I had to install the file locally similar to @icyrock.com's suggestion, then put `mavenLocal()` before `mavenCentral()` in the `repositories` sections. – ben3000 Dec 15 '15 at 06:14
  • Just for documentation: there is at least one [bug in Gradle](https://issues.gradle.org/browse/GRADLE-3188) associated with transitive dependencies, also as far as I can tell, json-lib doesn't supply any classifier data in its POM (see [this](http://stackoverflow.com/questions/3092085/building-same-project-in-maven-with-different-artifactid-based-on-jdk-used) and [this](http://search.maven.org/#artifactdetails|net.sf.json-lib|json-lib|2.2.3|jar)). I also couldn't find a way to determine whether Gradle checks for checksum errors as mentioned above. – ben3000 Dec 15 '15 at 06:43
2

Barring khimarbaise's comment about trustworthiness, you can install it locally using maven install:

mvn install:install-file  -Dfile=path-to-your-artifact-jar
                          -DgroupId=your.groupId
                          -DartifactId=your-artifactId
                          -Dversion=version
                          -Dpackaging=jar
                          -DlocalRepositoryPath=path-to-specific-local-repo
icyrock.com
  • 27,952
  • 4
  • 66
  • 85
1

For ivy users, after trying many different iterations to configure my ivy.xml to properly find this dependency, this finally worked for me:

  <dependency org="net.sf.json-lib" name="json-lib" rev="2.4">
        <artifact name="json-lib" url="http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar"/>     
    </dependency>
danbsd
  • 123
  • 2
  • 6
  • I think the hardwired URL is not an optimal solution, this works in Ivy too: – stumbav Apr 26 '15 at 07:00
  • @stumbav, this doesn't work for me. It gives error: parsed: [[Fatal Error] ivy.xml:19:137: The prefix "maven" for attribute "maven:classifier" associated with an element type "artifact" is not bound – Jitesh Sojitra Sep 11 '16 at 16:56