在我的项目中,以下代码示例在不使用ice4j软件包的情况下有效:
import javax.sdp.*;
public class Hello
{
public static void main(String[] args) throws Throwable
{
SdpFactory factory = SdpFactory.getInstance();
}
}
但是如果我包含如下的ice4j软件包:
apply plugin: 'java-library'
repositories {
google()
jcenter()
}
jar {
manifest {
attributes 'Main-Class': 'Hello'
}
from {
configurations.compile.collect{it.isDirectory()?it:zipTree(it)}
}
}
dependencies {
compile group: 'javax.sdp', name: 'nist-sdp', version: '1.0'
compile group: 'org.jitsi', name: 'ice4j', version: '1.0'
}
sourceCompatibility = "7"
targetCompatibility = "7"
在gradle中添加ice4j软件包,然后构建没有问题,但如果使用以下命令运行:
java -jar build/libs/Hello.jar
报告错误消息:
Exception in thread "main" java.lang.NoSuchMethodError: javax.sdp.SdpFactory.getInstance()Ljavax/sdp/SdpFactory;
at Hello.main(Hello.java:7)
为什么运行时传递的编译找不到方法?
答案 0 :(得分:0)
请改用以下代码:
SdpFactory factory = new NistSdpFactory();//SdpFactory.getInstance();
将更改渐变为:
compile group: 'org.opentelecoms.sdp', name: 'java-sdp-nist-bridge', version: '1.1'