Failed to load jxbrowser in plain OSGi enviroment - jxbrowser

I've been using jxbrpowser 6.2 with a trial license. Trying to load it in OSGi enviroment generates the following error:
Exception in thread "JavaFX Application Thread" java.lang.ExceptionInInitializerError
at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.getDefault(Unknown Source)
at com.teamdev.jxbrowser.chromium.BrowserContext.<init>(Unknown Source)
(...)
at com.sun.glass.ui.win.WinApplication$$Lambda$39/30523883.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.teamdev.jxbrowser.chromium.internal.ChromiumExtractorException: Failed to extract chromium binaries into C:\Users\Vladimir\AppData\Local\Temp\jxbrowser-chromium-43.0.2357.52.6.2
at com.teamdev.jxbrowser.chromium.internal.ChromiumExtractor.extract(Unknown Source)
at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.<init>(Unknown Source)
at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.create(Unknown Source)
at com.teamdev.jxbrowser.chromium.internal.ipc.IPC$a.<clinit>(Unknown Source)
... 15 more
Caused by: java.lang.IllegalArgumentException: The /chromium-windows.zip resource cannot be found in JAR files.
at com.teamdev.jxbrowser.chromium.internal.ZIPExtractor.extract(Unknown Source)
at com.teamdev.jxbrowser.chromium.internal.e.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 19 more
I can successfully load jxbrowser in the non-OSGi environment, as well as in OSGi environment when resources are already extracted.
Is there any way to make jxbrowser successfully extracts the resources from the jar?

It is looking like you don't have a correct OSGI bundle for JxBrowser. As far as I know jxbrowser supports OSGI bundle distribution, you can simply install it into your OSGI container.
Alternatively you can create your own bundle with which is only exports JxBrowser public API, but contains JxBrowser libraries you need. You can automate it with Felix bundle plugin for example http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html
In order to make such a bundle working you will need to initialize an temporary browser instance (just create a browser component) inside bundle activator. So that chromium binaries will be extracted when bundle is installed in your OSGi container.

Related

Jar file created with JavaFX will not load because of error java.util.MissingResourceException: Can't find bundle for base name lng, locale en_US?

I have a resource bundle with language properties. If the local language is French, it loads french texts or else default English. My program works okay when using Intellij but when I create the jar file and try to run it by doing java -jar myapp.jar then it crashes and shows error.
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javafx.fxml.LoadException:file:/C:/Users/rsoph/OneDrive/Desktop/C195new/out/artifacts/C195_Project_jar/C195_Project.jar!/view/login_welcome_screen.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at main.Main.start(Main.java:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
at com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2591)
... 17 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name lng, locale en_US
at java.base/java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:2055)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1689)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1593)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1556)
at java.base/java.util.ResourceBundle.getBundle(ResourceBundle.java:932)
at controller.LoginWelcomeScreenController.initialize(LoginWelcomeScreenController.java:61)
... 29 more
This is how I use the resource bundle
ResourceBundle resBundle = ResourceBundle.getBundle("lng", Locale.getDefault());
if (Locale.getDefault().getLanguage().equals("fr")) {
usernameLabel.setText(resBundle.getString("username"));
passwordLabel.setText(resBundle.getString("password"));
loginButton.setText(resBundle.getString("login"));
exitButton.setText(resBundle.getString("exit"));
}
My program structure looks like this.
EDIT: This is how I created the jar executable file.
File -> Project Structure -> Artifacts -> click on the plus sign (+) -> Jar -> From modules with dependencies.
Select the main class and OK. Followed by Clicking on the + sign and adding all files from the javafx bin folder to the File ( all the dll files).
Go to Build -> Build artifacts -> Build.
The bundle name you are looking up is "lng", but your the files in your bundle have prefixes of "Lng".
The case of the resource file name and the bundle lookup string should match.
If you are using a Windows system, the lookup on the file name is case-insensitive when using the file protocol to access the unpackaged resources.
But, when packaged in a jar, the lookup of the resources using the jar protocol is case sensitive.
Which explains why you can find the resources when not packaged in a jar, and why the lookup fails after jar packaging.
In addition to the issue with the jar packaging, relying on case insensitive file names also means that the project would fail if used on an OS with a case sensitive file system, like a Mac or Linux system.

Exception while running AWS dynamoDb in Local Machine

I have downloaded AWS dynamodb zip file and extracted to D:/dynamoDB folder
When tried to run via command prompt using
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar
Exception as below occurs
Exception in thread "main" java.lang.NoSuchFieldError: completionKey
at sun.nio.fs.WindowsNativeDispatcher.initIDs(Native Method)
at sun.nio.fs.WindowsNativeDispatcher.<clinit>(Unknown Source)
at sun.nio.fs.WindowsLinkSupport.getRealPath(Unknown Source)
at sun.nio.fs.WindowsPath.toRealPath(Unknown Source)
at sun.nio.fs.WindowsPath.toRealPath(Unknown Source)
at sun.util.calendar.ZoneInfoFile$1.run(Unknown Source)
at sun.util.calendar.ZoneInfoFile$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.util.calendar.ZoneInfoFile.<clinit>(Unknown Source)
at sun.util.calendar.ZoneInfo.getTimeZone(Unknown Source)
at java.util.TimeZone.getTimeZone(Unknown Source)
at java.util.TimeZone.setDefaultZone(Unknown Source)
at java.util.TimeZone.getDefaultRef(Unknown Source)
at java.util.TimeZone.getDefault(Unknown Source)
at org.eclipse.jetty.util.DateCache.<init>(DateCache.java:88)
at org.eclipse.jetty.util.log.StdErrLog.<clinit>(StdErrLog.java:68)
at org.eclipse.jetty.util.log.Log.initStandardLogging(Log.java:185)
at org.eclipse.jetty.util.log.Log.initialized(Log.java:168)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:435)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:425)
at org.eclipse.jetty.util.IO.<clinit>(IO.java:44)
at org.eclipse.jetty.util.log.Log$1.run(Log.java:110)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.util.log.Log.<clinit>(Log.java:85)
at org.eclipse.jetty.util.component.AbstractLifeCycle.<clinit>(AbstractL
ifeCycle.java:33)
at com.amazonaws.services.dynamodbv2.local.main.ServerRunner.createServe
r(ServerRunner.java:123)
at com.amazonaws.services.dynamodbv2.local.main.ServerRunner.createServe
rFromCommandLineArgs(ServerRunner.java:119)
at com.amazonaws.services.dynamodbv2.local.main.ServerRunner.main(Server
Runner.java:70)
I am having Java7 sdk in my windows 32 system.
NoSuchFieldError exceptions are thrown "if an application tries to access or modify a specified field of an object, and that object no longer has that field". In this case, it's likely the jar was compiled against one version of java (or other dependency) and you're using a different version that is not compatible.
I'd suggest updating to Java8 since support for Java7 ended as of April 2015. Also, check your version of jetty (since the last call outside the JVM was caused by org.eclipse.jetty.util.DateCache.<init>(DateCache.java:88)) to make sure it's compatible.

JAX-WS context listener initializing failed in JBOSS

I'm getting below error when trying to deploy a JAX-WS web service in JBOSS 4.0.3. I'm using JAX-WS RI runtime libraries. I'm not using JBOSS-WS the JBOSS specific JAX-WS.
18:31:21,125 INFO [STDOUT] Feb 20, 2015 6:31:21 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFO: WSSERVLET12: JAX-WS context listener initializing
18:31:21,203 INFO [STDOUT] Feb 20, 2015 6:31:21 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor:
java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V
java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V
at com.sun.xml.ws.util.xml.XmlUtil.newTransformerFactory(XmlUtil.java:392)
at com.sun.xml.ws.util.xml.XmlUtil.newTransformerFactory(XmlUtil.java:400)
at com.sun.xml.ws.util.xml.XmlUtil.<clinit>(XmlUtil.java:233)
at com.sun.xml.ws.api.streaming.XMLStreamReaderFactory.getXMLInputFactory(XMLStreamReaderFactory.java:127)
at com.sun.xml.ws.api.streaming.XMLStreamReaderFactory.<clinit>(XMLStreamReaderFactory.java:89)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:176)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:152)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3669)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4104)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)...
In the web.xml I've put the listener for the class: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
The class javax.xml.transform.TransformerFactory is abstract, and you need an Implementation of that class somewhere in your classpath. The exception java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z) often indicates a version conflict in your dependencies, because the implementation you use was build against a different version of the interface.
To solve it you must use a matching implementation. TransformerFactory-implementations are contained withing XML parsers like Xalan or Xerces. You can tell Java to use a certain parser implementation by setting the appropriate system properties:
Properties p = System.getProperties();
p.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
p.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
p.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
System.setProperties(p);
Executing this during initialization of your application will set the default parser implementation to the internal Xalan parser of the JRE. To use other parsers, include their dependencies and put the Implementations classes' names in the setProperties methods.

running mahout RecommenderJob on EMR

I'm trying to run a RecommenderJob on amazon EMR. I have a jar called SmartJukebox.jar (not runnable) and it contains a class main.TrackRecommander (and that's it).
I created a job flow with the jar:
s3n://smartjukebox/SmartJukebox.jar
and args:
main.TrackRecommander --input s3n://smartjukebox/ratings.csv --output s3n://smartjukebox/output --usersFile s3n://smartjukebox/user.txt.
The class TrackRecommander uses the class RecommenderJob.
I run the job flow and i get this in the error log -
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/mahout/cf/taste/hadoop/item/RecommenderJob
at main.TrackRecommander.main(TrackRecommander.java:136)
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 org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.ClassNotFoundException: org.apache.mahout.cf.taste.hadoop.item.RecommenderJob
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
now i see that the JVM can't find RecommenderJob and i didn't put RecommenderJob in my jar. I thought EMR would have mahout jars built in, but i can't find anything about that.
what is the solution here?
Thanks.
You're problem is exactly what you say: "I didn't put RecommenderJob in my jar." Unless you put those classes in your JAR, of course it can't be found. Why would EMR have this built in? Add the Mahout ".job" file classes to your JAR first.
You will need to create a job jar which contains all the classes required by the code to run which includes the mahout classes too.
Take a look at
https://github.com/tdunning/MiA
Check how to create a job jar using maven assembly plugin in pom.xml and the job.xml in the src/main/resources directory.
IF you exclude the hadoop classes then you can run it on any hadoop instance.

Starting Java applet directly from jar file

The goal is to have an applet run from a jar file.
The problem is that the applet only seems to want to run from an exploded jar file.
Samples on the Internet suggest this applet tag:
<applet code="com.blabla.MainApplet"
archive="applet.jar"
width="600" height="600">
This will not even try to look in the jar file and fails with:
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/helloWord/com/blabbla/MainApplet.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Setting the codebase instead of the archive attribute to the jar file. Looks a bit better. However, the JVM does not realize that it has to open the jar file:
<applet code="com.blabla.MainApplet"
codebase="applet.jar"
width="600" height="600">
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/helloWord/applet.jar/com/blabbla/MainApplet.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
How does the applet tag have to be formulated to start an applet class from inside of a jar file?
The problem was that the Java console was caching previous bad jars. Once the cache was cleared in the Java console, the first version of the code worked fine.
<applet code="com.blabla.MainApplet"
archive="applet.jar"
width="600" height="600">

Resources