在我的项目中,下面的代码示例在不使用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)


为什么编译时通过运行时传递找不到方法?

最佳答案

使用以下代码代替:

SdpFactory factory = new NistSdpFactory();//SdpFactory.getInstance();


gradle更改为:

compile group: 'org.opentelecoms.sdp', name: 'java-sdp-nist-bridge', version: '1.1'

10-04 19:55