日期:2014-05-16  浏览次数:20314 次

关于Maven中下载导入Json的jar包的问题
mvn clean install 编译时报错为:
[INFO] Failed to resolve artifact.
Missing:
----------
1) net.sf.json-lib:json-lib:jar:2.2.3

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=net.sf.json-lib -DartifactId=json-lib -Dversion=2.2.3 -Dpackaging=jar -Dfile=/p
ath/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=net.sf.json-lib -DartifactId=json-lib -Dversion=2.2.3 -Dpackaging=jar -Dfile=/pat
h/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) org.apache.struts:ServiceSystem:war:0.0.1-SNAPSHOT
        2) net.sf.json-lib:json-lib:jar:2.2.3

----------
1 required artifact is missing.
for artifact:
  org.apache.struts:ServiceSystem:war:0.0.1-SNAPSHOT
from the specified remote repositories:
  central (http://repo1.maven.org/maven2)

pom.xml中的配置为
                  <dependency>
		    <groupId>net.sf.json-lib</groupId>
		    <artifactId>json-lib</artifactId>
		    <version>2.2.3</version>
		</dependency>

注意:上面的配置方式是错误的!
json-lib是需要区分jdk版本的,pom.xml中的配置应加上<classifier>标签,如用jdk15:
<dependency>
		    <groupId>net.sf.json-lib</groupId>
		    <artifactId>json-lib</artifactId>
		    <version>2.2.3</version>
                    <classifier>jdk15</classifier>
</dependency> 

总之,以上<classifier>标签是必须的,如果还是Missing,可能是因为网络原因导致下载失败。
请查看本地仓库net\sf\json-lib\json-lib\2.2.3目录下是否存在json-lib-2.2.3-jdk15.jar,
如果没有,则把这个目录删除,重新运行mvn clean install