kullanarak package-info.java adresinin açıklaması değiştirilemedi. Bir paket bilgisini değiştirmem gereken bir sorunla karşılaşıyorum.Java 8
package-info.java
@javax.xml.bind.annotation.XmlSchema(namespace = "http://some.url/soap/style/document_literal")
package org.example.wsdl.wsdl;
Aşağıdaki kod 1.7.0_45 ile çalışıyor.
java.lang.NoSuchFieldException: annotations
at java.lang.Class.getDeclaredField(Class.java:2057)
Ben onun Hack en azından öyle görünüyor, biliyorum: derlenmesi ve 1.8.0_05 ile aynı kod yürütürken
// do not load any classes before, this could break the following code.
Class<?> pkgInfo = Class.forName("org.example.wsdl.package-info", true, NameSpaceModifier.class.getClassLoader());
Field field = Class.class.getDeclaredField("annotations");
field.setAccessible(true);
final XmlSchema oldAnnotation = (XmlSchema) pkgInfo.getAnnotations()[0];
logger.debug("Old Annotation namespace value was: " + oldAnnotation.namespace());
XmlSchema newAnnotation = new XmlSchema() {
@Override
public XmlNs[] xmlns() {
return oldAnnotation.xmlns();
}
@Override
public String namespace() {
return "newNs";
}
@Override
public XmlNsForm elementFormDefault() {
return oldAnnotation.elementFormDefault();
}
@Override
public XmlNsForm attributeFormDefault() {
return oldAnnotation.attributeFormDefault();
}
@Override
public String location() {
return oldAnnotation.location();
}
@Override
public Class<? extends Annotation> annotationType() {
return oldAnnotation.annotationType();
}
};
@SuppressWarnings("unchecked")
Map<Class<? extends Annotation>, Annotation> annotations = (Map<Class<? extends Annotation>, Annotation>) field.get(pkgInfo);
annotations.put(XmlSchema.class, newAnnotation);
XmlSchema modifiedAnnotation = (XmlSchema) pkgInfo.getAnnotations()[0];
Bu hata mesajı alıyorum. Ama Java 8 beklendiği gibi burada çalışıyor mu? O kodun Java 8 ile çalıştığını nasıl değiştirmeliyim?
Herhangi bir java güncelleştirmesinin kodumu kesebileceğini biliyorum. Farklı bir yol için herhangi bir öneriniz var mı? – Zarathustra
@Zarathustra Neden ek açıklamaları değiştiremiyorsunuz? Üretilen kodu – Jeffrey
. Farklı Sunucularda bir SOAP Hizmeti ile iletişim kuruyorum, hepsi aynı wsdl'yi paylaşıyor, hostname içerdiğinden targetNamespace olmasını bekliyorum. – Zarathustra