2017-07-05 5 views
0

私はWindowsでイベントを書きたいと思いますし、Groovyだけが私のアプリケーションでサポートされています。GroovyスクリプトがJNAクラスを見つけることができません

私がテストするために短いコードを書いたが、私は常に次の例外が発生しました:

Java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.platform.win32.Advapi32 
    at ProcessStateHandler.registerEventSource(test.groovy:32) 
    at ProcessStateHandler.main(test.groovy:23) 

テストコードは、このようなものです:私の推測で

import com.sun.jna.platform.win32.Advapi32 
import com.sun.jna.platform.win32.Advapi32Util 
import com.sun.jna.platform.win32.Kernel32 
import com.sun.jna.platform.win32.Win32Exception 
import com.sun.jna.platform.win32.WinNT 
import com.sun.jna.platform.win32.WinNT.HANDLE 
import com.sun.jna.platform.win32.WinReg 

import com.sun.jna.Native 
import com.sun.jna.Library 
import com.sun.jna.Platform 
import com.sun.jna.Pointer 



public class ProcessStateHandler { 
    def APPLICATION_EVENT_LOG_REGISTRY = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application" 
    public static void main(String[] args) { 
     println "First groovy test" 
     CLibrary.INSTANCE.printf("Hello, World\n") 

     ProcessStateHandler processStateHandler = new ProcessStateHandler() 
     processStateHandler.registerEventSource("", "SourceForTest") 
    } 

    private void registerEventSource(String server, String source) { 

     source = source.trim() 

     assert Advapi32 
//  assert Advapi32.INSTANCE   
     HANDLE eventHandle = Advapi32.INSTANCE.RegisterEventSource(server, source) 
    } 
} 


public interface CLibrary extends Library { 
    CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? 'msvcrt' : 'c'), CLibrary.class) 

    void printf(String format, Object... args) 
} 

、Groovyはインタフェース内の変数をサポートしていません。 。 Advapi32インターフェイスはこのように宣言されています。

Advapi32インターフェイスでINSTANCEまたは呼び出しメソッドにアクセスするにはどうすればよいですか?

答えて

0

多分、私のテストは間違っていました。

Eclipseでコードをテストするときに問題はありません。 GroovyConsoleにクラスローダーの問題がある可能性があります。

関連する問題