0

我正在编译一个使用 org.json 的 java 插件。在我包含这个之前,插件能够正确编译和运行。我在 stackoverflow 上看到过类似的问题,但没有一个使用 gradle 解决这个问题。

在我的班级中,我有以下内容

import org.json.JSONArray;
import org.json.JSONObject;

我的 gradle 构建脚本包含以下内容:

repositories {
    maven {
        url "http://repo.dotcms.com/artifactory/libs-release"
    }
    mavenCentral()
    flatDir {
        dirs 'src/main/resources/localLibs'
    }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile fileTree(dir: 'src/main/resources/libs', include: '*.jar')
    compile (group: 'com.dotcms', name: 'dotcms', version: '4.2.2'){
        transitive = true
    }
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
    compile group: 'org.json', name: 'json', version: '20170516'
    compile group: 'org.simpleflatmapper', name: 'sfm-csv', version: '3.14.1'
    /* Specifying an alternate configuration (see above 'configurations') keeps servlet-api.jar from being added to our own output Jar. */
    providedCompile "javax.servlet:javax.servlet-api:3.1.0"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

jar {
    manifest {
        name = 'Symplicity SOAP API Web Service'
        symbolicName = 'Symplicity SOAP API Web Service'
        instruction 'Bundle-Vendor', 'JustinKubicek'
        instruction 'Bundle-Name', 'Symplicity SOAP API Web Service'
        instruction 'Bundle-Description', 'This is a plugin to access the Symplicity SOAP API Web Service'
        instruction 'Bundle-DocURL', 'https://bitbucket.org/justinkubicek/symplicity-soap-api-plugin'
        instruction 'Bundle-Activator', 'com.symplicitysoapapi.soapapitool.osgi.Activator'
        instruction 'DynamicImport-Package', '*'
        instruction 'Import-Package', '*;version=0;'
    }
}    

我得到的错误是这里。

javax.servlet.ServletException: Unable to resolve Symplicity SOAP API Web Service
[197](R 197.0): missing requirement [Symplicity SOAP API Web Service [197](R 197.0)]
osgi.wiring.package; (&(osgi.wiring.package=org.json)(version>=0.0.0))
Unresolved requirements: [[Symplicity SOAP API Web Service [197](R 197.0)]
osgi.wiring.package; (&(osgi.wiring.package=org.json)(version>=0.0.0))]
Unable to start bundle
at com.dotmarketing.portlets.osgi.AJAX.OSGIAJAX.start(OSGIAJAX.java:122)
~[dotcms_4.2.2_999999.jar:?]
4

1 回答 1

0

除非您需要 JSON 库的自定义版本,否则我建议您更改导入以使用 dotCMS 库中包含的重新打包的类。重新打包的类允许开发人员在需要时包含该库的自定义版本。以下是 4.2.2 版本中可用的 json 类列表:

./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/XMLTokener.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/XML.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/Test.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONWriter.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONTokener.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONStringer.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONString.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONObject.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONML.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONException.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONArray.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/HTTPTokener.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/HTTP.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/CookieList.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/Cookie.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/CDL.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/

当然要在运行时使用这些类,您需要确保它们列在您的导出包列表中: https ://dotcms.com/docs/latest/osgi-plugins#ExportedPackages

于 2017-12-06T18:04:06.290 回答