[解決済み] JaxbRepresentationが "doesnt contain ObjectFactory.class or jaxb.index "というエラーを出す
2022-01-29 18:44:47
質問事項
オブジェクトをJaxbRepresentationに変換するサンプルテストアプリケーションを作成しようとしています。しかし、これを実行しようとすると、エラーが発生します。
Main.javaファイル
package test_jaxb;
import org.restlet.Server;
import org.restlet.data.Protocol;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
Server helloServer = new Server(Protocol.HTTP, 8111,
TestResource.class);
helloServer.start();
}
}
TestResource.javaファイル
package test_jaxb;
import org.restlet.ext.jaxb.JaxbRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
public class TestResource extends ServerResource{
@Override
protected Representation get() throws ResourceException {
SampleResponse res = new SampleResponse();
res.setMsg("Success");
res.setStatusCode(0);
JaxbRepresentation<SampleResponse> representation = new JaxbRepresentation<SampleResponse>(res);
return representation;
}
}
SampleResponse.javaファイル
package test_jaxb;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="Response")
public class SampleResponse {
private int statusCode;
private String msg;
@XmlElement(name="Msg")
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
@XmlElement(name="StatusCode")
public int getStatusCode() {
return statusCode;
}
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
}
これをサーバーで実行すると、次のようなエラーが発生します。
WARNING: Problem creating Marshaller
javax.xml.bind.JAXBException: "test_jaxb" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:299)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at org.restlet.ext.jaxb.JaxbRepresentation.getContext(JaxbRepresentation.java:83)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:68)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:64)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141)
at java.lang.ThreadLocal.get(ThreadLocal.java:131)
at org.restlet.ext.jaxb.internal.Marshaller.getMarshaller(Marshaller.java:163)
at org.restlet.ext.jaxb.internal.Marshaller.marshal(Marshaller.java:216)
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:527)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.internal.Marshaller getMarshaller
WARNING: Unable to locate marshaller.
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.JaxbRepresentation write
WARNING: JAXB marshalling error caught.
javax.xml.bind.JAXBException: Unable to locate marshaller.
at org.restlet.ext.jaxb.internal.Marshaller.getMarshaller(Marshaller.java:166)
at org.restlet.ext.jaxb.internal.Marshaller.marshal(Marshaller.java:216)
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:527)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.internal.Marshaller$1 initialValue
WARNING: Problem creating Marshaller
javax.xml.bind.JAXBException: "failure" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:299)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at org.restlet.ext.jaxb.JaxbRepresentation.getContext(JaxbRepresentation.java:83)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:68)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:64)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141)
at java.lang.ThreadLocal.get(ThreadLocal.java:131)
at org.restlet.ext.jaxb.internal.Marshaller.getMarshaller(Marshaller.java:163)
at org.restlet.ext.jaxb.internal.Marshaller.marshal(Marshaller.java:216)
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:535)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.internal.Marshaller getMarshaller
WARNING: Unable to locate marshaller.
May 16, 2011 7:05:12 AM org.restlet.engine.http.connector.Connection writeMessage
WARNING: Exception while writing the message body.
java.io.IOException: Unable to locate marshaller.
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:539)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.engine.http.connector.ServerConnection writeMessage
INFO: An exception occured while writing the response
java.io.IOException: Unable to locate marshaller.
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:539)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
誰か助けてください!!!
どのように解決するのですか?
jaxb.indexの追加ファイルを削除するには、Javaクラスを使ってコンテキストをインスタンス化することができます。
なぜなら、他のクラスはこれらのクラスから静的に到達可能であり、JAXBはこれらのクラスを識別することができるからです。
関連
-
[解決済み] java.sql.SQLException: ユーザー 'root'@'localhost' (using password: YES) のためのアクセスが拒否されました。
-
[解決済み】このコンパイルユニットは名前付きモジュールに関連しているため、名前付きパッケージeclipseを宣言する必要があります。
-
[解決済み】エラー。Selection does not contain a main type
-
[解決済み】スレッド「main」での例外 java.lang.StringIndexOutOfBoundsException: 文字列のインデックスが範囲外です。0 [閉店]
-
[解決済み】指定された子にはすでに親がいます。先に子の親に対してremoveView()を呼び出す必要がある(Android)
-
[解決済み】 JAVA 変数宣言はここではできない
-
[解決済み】メソッド本体がない、またはJavaで抽象的な宣言をする
-
[解決済み】Javaを包含するクラスではないのか?
-
[解決済み】Ubuntu: OpenJDK 8 - パッケージを見つけることができません。
-
[解決済み】CreateProcess error=2, The system cannot find file specified.
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
[解決済み】Javaパッケージが存在しないエラー
-
[解決済み】代入の左手は必ず変数 CharAt
-
[解決済み】Javaの".class期待値"
-
[解決済み】不正なエスケープ文字"㊧"について
-
[解決済み】HTTPステータス500 サーブレットクラスのインスタンス化エラー [重複]。
-
[解決済み】Javaで無限大を実装する方法とは?
-
[解決済み] java.sql.SQLException を取得しました。ResultSet が終了した後の操作は許可されません。
-
[解決済み】javaで無効な文字定数
-
[解決済み】 executeQuery()でデータ操作文が発行できない。)
-
[解決済み】 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener