JavaFX不允许WebView透明,因此我发现this patch使用Javassist来修改Java的com.sun.webkit.WebPage
。
这在Java 8之前都可以正常工作,但是停止使用Java 9:
> Patching com/sun/webkit/WebPage ...
javassist.CannotCompileException: [source error] no such class: com.sun.webkit.graphics.WCRectangle
at javassist.CtBehavior.setBody(CtBehavior.java:446)
at javassist.CtBehavior.setBody(CtBehavior.java:412)
at com.github.micheljung.transparentwebview.TransparentWebViewPatch.transform(TransparentWebViewPatch.java:64)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:550)
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1099)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at javafx.web/javafx.scene.web.WebEngine.<clinit>(WebEngine.java:338)
at javafx.web/javafx.scene.web.WebView.<init>(WebView.java:260)
at com.github.micheljung.transparentwebview.Demo.start(Demo.java:21)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: compile error: no such class: com.sun.webkit.graphics.WCRectangle
at javassist.compiler.MemberResolver.searchImports(MemberResolver.java:468)
at javassist.compiler.MemberResolver.lookupClass(MemberResolver.java:412)
at javassist.compiler.MemberResolver.lookupClassByName(MemberResolver.java:315)
at javassist.compiler.TypeChecker.atNewExpr(TypeChecker.java:146)
at javassist.compiler.ast.NewExpr.accept(NewExpr.java:73)
at javassist.compiler.JvstTypeChecker.atMethodArgs(JvstTypeChecker.java:221)
at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:735)
at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:695)
at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:330)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:292)
at javassist.compiler.Javac.compileBody(Javac.java:223)
at javassist.CtBehavior.setBody(CtBehavior.java:438)
... 25 more
/!\ com/sun/webkit/WebPage patching failed :(
javassist.NotFoundException: com.sun.webkit.graphics.WCRectangle
at javassist.ClassPool.get(ClassPool.java:452)
at com.github.micheljung.transparentwebview.TransparentWebViewPatch.transform(TransparentWebViewPatch.java:84)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:550)
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1099)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at javafx.web/javafx.scene.web.WebEngine.<clinit>(WebEngine.java:342)
at javafx.web/javafx.scene.web.WebView.<init>(WebView.java:260)
at com.github.micheljung.transparentwebview.Demo.start(Demo.java:21)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
at java.base/java.lang.Thread.run(Thread.java:844)
> Patching com/sun/javafx/webkit/prism/WCGraphicsPrismContext ...
/!\ com/sun/javafx/webkit/prism/WCGraphicsPrismContext patching failed :(
由于我不了解javassist如何查找类,所以我在这里迷路了。我认为这与Java 9模块有关。有人知道吗? 该类仍然具有相同的包名称。
答案 0 :(得分:2)
在两个演示版本3.20.0-GA中,您都使用了 javassist 的过时版本。
dependencies {
compile 'org.javassist:javassist:3.20.0-GA'
}
这将适用于Java 8,但不适用于Java9。如果您在GitHub上的releases页面上浏览,直到版本3.22.0-GA,该库才与Java 9兼容。但是,由于其最新版本(在撰写此答案时)为3.23.1-GA,因此也已过时。
将依赖项声明更改为使用最新版本,您的问题应得到解决。
dependencies {
compile 'org.javassist:javassist:3.23.1-GA'
}
与您的问题无关:我不知道您使用的是哪个版本的Gradle,但在更高版本中,compile
配置已过时;它已被implementation
取代。有关更多信息,请参见here。