首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >实现最新版本的JCIFS

实现最新版本的JCIFS
EN

Stack Overflow用户
提问于 2022-04-30 11:58:15
回答 1查看 383关注 0票数 0

尝试将我的应用程序从jcifs-1.3.19更新到最新的jcifs-2.1.29,我更改了适当的代码,将“必要的”jars添加到build.gradle中。

代码语言:javascript
运行
复制
<see answer below>

但继续得到相同的错误,由: java.lang.NoClassDefFoundError:失败的决议:罗格/赏金城堡/asn1 1/asn1 1对象标识符;

找到了一些参考资料,实施了他们提出的解决方案,但没有效果。少了什么??

Java -version java版本"18.0.1“2022-04-19 Java(TM) SE运行时环境(build 18.0.1+10-24) java HotSpot(TM) 64位服务器VM (build 18.0.1+10-24,混合模式,共享)

JAVA_HOME=C:\Program文件\公共文件\Oracle\Java\javapath

Android Studio Gradle:

代码语言:javascript
运行
复制
  //  implementation files('libs/jcifs-1.3.19.jar') moving from V1 to V2
    implementation files('libs/jcifs-2.1.29.jar')  
    implementation files('libs/bcprov-jdk18on-171')
    implementation files('libs/bcutil-jdk18on-171')
    implementation files('libs/slf4j-api-1.7.30.jar')




public CIFSContext getcredentials(String user, String password){
    NtlmPasswordAuthenticator sourceAuth = new NtlmPasswordAuthenticator("",
            user, password);
    Properties properties = new Properties();
    properties.setProperty("jcifs.smb.client.responseTimeout", "5000");
    PropertyConfiguration configuration = null;
    try {
        configuration = new PropertyConfiguration(properties);
    } catch (CIFSException e) {
        e.printStackTrace();
    }
    CIFSContext cifsContext = new BaseContext(configuration).withCredentials(sourceAuth);
    return cifsContext;
}

连接到pc的代码:

代码语言:javascript
运行
复制
String username = getusername();
        String password= getpassword();

        CIFSContext cifsContext = general.getcredentials(username,password );
        String[] shares;
        sharelist.clear();
        try {
            SmbFile server = new SmbFile("smb://" + ip, cifsContext);  // value for server: "smb://192.168.0.38"
           if( server.exists()) {           // yes as it continues
               try {
                   shares = server.list();  // this is where it crashes      Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bouncycastle/asn1/ASN1ObjectIdentifier;
                   for (String s : shares) {
                       if (!s.contains("$")) {
                           sharelist.add(s);
                           op.success = true;
                       }
                       //  System.out.println(s);
                   }
               } catch (SmbException e) {
                   e.printStackTrace();
               }
           }
        } catch (MalformedURLException e) {
            e.printStackTrace();
            op.an_error=e.getMessage().toString();

        } catch (SmbException e) {
            e.printStackTrace();
            op.an_error=e.getMessage().toString();
        }

附加:https://www.baeldung.com/java-bouncy-castle

EN

回答 1

Stack Overflow用户

发布于 2022-05-11 14:33:36

现在使用添加到build.gradle中的以下内容:

代码语言:javascript
运行
复制
implementation files('libs/jcifs-2.1.29.jar')
implementation files('libs/slf4j-api-1.7.30.jar') 
implementation 'org.bouncycastle:bcprov-jdk15on:1.68'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72068321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档