尝试将我的应用程序从jcifs-1.3.19更新到最新的jcifs-2.1.29时,我更改了相应的代码,添加了“必要的”jar到build.gradle
<see answer below>
但仍出现相同的错误,原因如下:java.lang.NoClassDefFoundError:解析失败:Lorg/bouncycastle/asn1/ASN1ObjectIdentifier;
找到了一些参考资料,实施了他们建议的解决方案,但无济于事。缺少什么??
java -version java version“18.0.1”2022-04-19 Java(TM)SE Runtime Environment(build 18.0.1+10-24)Java HotSpot(TM)64位服务器VM(build 18.0.1+10-24,混合模式,共享)
JAVA_HOME=C:\Program Files\Common Files\Oracle\Java\javapath
Android Studio Gradle:
// 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的代码:
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();
}
2条答案
按热度按时间noj0wjuj1#
现在,我们将以下内容添加到build.gradle中:
3pmvbmvn2#
这就是我如何使用NtlmPasswordAuthenticator解决的问题,例如,将文件复制到桑巴舞共享:
所需的库(依赖项):