2011-12-14 5 views
2

私のアプリケーションでスタンドアロンの突堤を走っていると、奇妙な動作が見られます。アプリケーションを起動するjetty guice illegalaccessError

でエラーが発生します:

ライン

if (f.getAnnotation(Persist.class) != null) //f is a Field instance (a public one, no less), Persist is an annotation

コードは、Tomcatの中で正常に動作この

  • についていくつかの面白い事実によってトリガーされる

    2011-12-14 16:46:20.634:WARN::Error starting handlers java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor2 cannot access its superclass sun.reflect.ConstructorAccessorImpl at sun.misc.Unsafe.defineClass(Native Method)

  • コードは、私は桟橋のAntタスクを実行している同じ桟橋瓶でそれを実行した場合でも、アリ桟橋タスク

  • コードがスタンドアロン桟橋(しようとしたV6 & V8)でこのエラーをスローで細かい動作します。

最小限のjetty.xml(基本的にはディレクトリを指す)で実行します。

答えて

6

私はちょうどこれを見つけたので、それはちょっと見えないので、他の貧しい魂が一見無作為な行動のこの同じピットに走っているところは投稿価値があると思う。

はメッセージhere

The problem is the AOP proxy classes are being generated in a separate classloader and this is the cause of the visibility issues, as package-private types are not visible from other classloaders. Guice tries to detect this to avoid introducing the separate classloader, but this seems not to be happening in your example.

だから私のアプリケーションは、私はすべてのアプリのjarファイルを取る場合は動作し、直接、明らかにAOP原因JETTY_HOME/libに、にそれらをダンプするとなっている関連の引用に出くわしましたguiceが承認する方法でクラスを生成する。

修正 - これは、guiceとはまったく関係がありませんでしたが、Jettyがクラスをロードする方法とは全く関係ありませんでした。このため、実際の修正は道桟橋負荷クラスを変更することで、jetty.xmlのwebappcontextの定義にこれを追加する:

<Set name="handler"> 
     <New class="org.mortbay.jetty.webapp.WebAppContext"> 
    <Set name="parentLoaderPriority">true</Set> 
+0

+1根本原因を釘付け用:ここ

context.setClassLoader(Thread.currentThread().getContextClassLoader()); 

は完全なコードです:私は自分のアプリケーションのクラスローダと同じになるように桟橋のクラスローダを強制することによってそれを解決しました。 – edwardw

2

を私は、組み込みのJettyと@Async注釈と同様の問題がありました。

public class Jetty { 
    public static Server createServer(int port) { 
     Server server = new Server(port); 
     WebAppContext context = new WebAppContext(); 
     context.setResourceBase("src/main/webapp"); 
     context.setClassLoader(Thread.currentThread().getContextClassLoader()); 
     HandlerList handlers = new HandlerList(); 
     handlers.setHandlers(new Handler[]{context}); 
     server.setHandler(handlers); 
     return server; 
    } 
}