我想在命令行上运行java注释程序。我无法运行该程序。 这是程序
manager.delegate.sessionDidReceiveChallenge = { session, challenge in
var disposition: NSURLSessionAuthChallengeDisposition = .PerformDefaultHandling
var credential: NSURLCredential?
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
let host = challenge.protectionSpace.host
if let serverTrust = challenge.protectionSpace.serverTrust {
let serverTrustPolicy = ServerTrustPolicy.PerformDefaultEvaluation(validateHost: true)
if serverTrustPolicy.evaluateServerTrust(serverTrust, isValidForHost: host) {
disposition = .UseCredential
credential = NSURLCredential(forTrust: serverTrust)
} else {
disposition = .CancelAuthenticationChallenge
return (disposition, credential)
}
for index in 0..<SecTrustGetCertificateCount(serverTrust) {
if let certificate = SecTrustGetCertificateAtIndex(serverTrust, index) {
if let fingerPrint = certificate.SHA1Fingerprint {
if isValidFingerprint(fingerPrint) {
return (disposition, credential)
}
}
}
}
}
}
disposition = .CancelAuthenticationChallenge
return (disposition, credential)
}
我使用命令编译程序as javac com / lara / annotations / G.java 它编译成功但我在运行程序时遇到问题。我用命令运行程序为 java com.lara.annotation G. 但它不起作用。 请任何人帮我运行这个程序。 谢谢。
答案 0 :(得分:0)
首先,您应该将注释的保留定义为RUNTIME ... 并且您需要使用反射来打印刚刚注释到方法
的元数据G gClass = new G();
Method m = gClass.getClass( ).getMethod("main");
Annotation[] annos = m.getAnnotations();
System.out.println("All annotations for myMeth:");
for(Annotation a : annos)
System.out.println(a);