2011-08-06 11 views
9

I am using some non-standard extensions EclipseLinkのJAXBの実装から、この実装を有効にするために、jaxb.propertiesを使用して設定する必要があります。うまくいく。jaxb.propertiesをコードに置き換えることはできますか?

ビルドエラーのため、プロパティファイルが適切な場所に含まれていなかったため、デフォルトのJAXBが使用されていましたが、XMLファイルを解析しただけでエラーは発生せず、私には稼働していないbeanが残っています。

これをより堅牢にするには、プロパティファイルを削除して、コードでコンテキスト設定を指定したいと思います。 EclipseLinkの注釈のためにEclipseLinkにはすでにコンパイル時の依存関係があります。この部分をデプロイ時に構成する必要はありません(実際には何がうまくいかないかを見て、構成可能にする必要はありません)。

+0

。 –

答えて

12

あなたはjaxb.propertiesファイルなしでEclipseLink JAXB(MOXY)JAXBContextを取得するには、次のことができます:後半ビルドでjaxb.propertiesの存在のためのテスト:代替手段を考えてみましょう

import java.io.File; 

import javax.xml.bind.JAXBContext; 
import javax.xml.bind.Marshaller; 
import javax.xml.bind.Unmarshaller; 

import org.eclipse.persistence.jaxb.JAXBContextFactory; 

public class Demo { 

    public static void main(String[] args) throws Exception { 
     //JAXBContext jc = JAXBContext.newInstance(Animals.class); 
     JAXBContext jc = JAXBContextFactory.createContext(new Class[] {Animals.class}, null); 

     Unmarshaller unmarshaller = jc.createUnmarshaller(); 
     File xml = new File("src/forum6871469/input.xml"); 
     Animals animals = (Animals) unmarshaller.unmarshal(xml); 

     Marshaller marshaller = jc.createMarshaller(); 
     marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 
     marshaller.marshal(animals, System.out); 
    } 

} 
+0

上記のコードでMarshallerProperties.JSON_INCLUDE_ROOTプロパティを設定するにはどうすればよいですか? – Vivek

関連する問題