what's reason building native quarkus fails - quarkus

Trying to build native quarkus and there's an error if I add json path https://github.com/json-path/JsonPath
Call path from entry point to java.lang.ClassLoader.defineClass(String, byte[], int, int, ProtectionDomain):
at java.lang.ClassLoader.defineClass(ClassLoader.java:1015)
at java.lang.ClassLoader.defineClass(ClassLoader.java:878)
at net.minidev.asm.DynamicClassLoader.defineClass(DynamicClassLoader.java:86)
at net.minidev.asm.BeansAccessBuilder.bulid(BeansAccessBuilder.java:313)
at net.minidev.asm.BeansAccess.get(BeansAccess.java:111)
at net.minidev.json.reader.BeansWriterASM.writeJSONString(BeansWriterASM.java:17)
or with option --report-unsupported-elements-at-runtime
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:480)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:349)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:508)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:114)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:537)
Caused by: java.lang.NoClassDefFoundError: javax/security/jacc/EJBMethodPermission
Is there anything I can do about it or it's a bug?
using docker to compile, it's working in jvm mode

Hard to tell without looking into the library code.
Quarkus does its best to integrate libraries and make them work with native mode, by adding the pieces required by native mode. For native mode limitations, please check this link: https://www.graalvm.org/reference-manual/native-image/Limitations/.
Some libraries may work out of the box without additional configuration. Other require additional configuration to comply with the native image rules.
It seems that the library is trying to dynamically add classes into the ClassLoader, which is unsupported in GraalVM due to the closed world assumption, unless the classes are registered at build time.

Related

ClassNotFoundException: com.sun.net.httpserver.HttpHandler- JAVAFX application with Googledrive data storage

I am developing a JAVAFX application which requires GoogleDrive connectivity inorder to store and retrieve data. Since Java11 doesn't include JAVAFX i have used to mergefx inorder to create a merged JDK with FX library. I am able to run the application in Eclipse latest version without any error and is able to connect with Googledrive via browser. In order to create a standalone version, I have used Jlink to create a JRE. Also to avoid the use of .bat file to execute the application, I have used Launch4j to create a .exe file of application. The .exe file has been created successfully,but while trying to connect with Googledrive, its showing the following error:
Caused by: java.lang.ClassNotFoundException:
com.sun.net.httpserver.HttpHandler at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Please let me know your suggestions,which will be really helpful.

java8_OSGI: NoClassDefFoundError: javafx/collections/MapChangeListener

I just started to develop on OSGI, on Eclipse Kura project and I tried to implement a hashmap Listener:
// Use Java Collections to create the List.
Map<String,String> map = new HashMap<String,String>();
// Now add observability by wrapping it with ObservableList.
ObservableMap<String,String> observableMap = FXCollections.observableMap(map);
observableMap.addListener(new MapChangeListener() {
#Override
public void onChanged(MapChangeListener.Change change) {
System.out.println("Detected a change! ");
logerKuraPI("Detected a change! ");
}
});
// Changes to the observableMap WILL be reported.
observableMap.put("key 1","value 1");
System.out.println("Size: "+observableMap.size());
logerKuraPI("Size: "+observableMap.size());
// Changes to the underlying map will NOT be reported.
map.put("key 2","value 2");
System.out.println("Size: "+observableMap.size());
logerKuraPI("Size: "+observableMap.size());
When I run this code in simple main in Intellij IDEA it works fine,however when I implemented in eclipse, OSGI project (Eclipse Kura), I get this error:
java.lang.NoClassDefFoundError: javafx/collections/MapChangeListener
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.eclipse.equinox.internal.ds.model.ServiceComponent.createInstance(ServiceComponent.java:493)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(ServiceComponentProp.java:270)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:331)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:915)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:464)
at org.eclipse.equinox.internal.ds.InstanceProcess.registerService(InstanceProcess.java:536)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:213)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
Caused by: java.lang.ClassNotFoundException: javafx.collections.MapChangeListener cannot be found by fileloger_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
without forgetting that when I compile I get no error in eclipse and it recognize the packages, but when I run I get those errors.
and I am using Java8.
This part of the stack trace:
Caused by: java.lang.ClassNotFoundException: javafx.collections.MapChangeListener cannot be found by fileloger_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
seems to indicate that Equinox is trying to find the class inside your bundle, rather than by delegation. This means that your "bundle" is probably missing some dependency metadata, specifically a package import.
OSGi bundles share API packages through a system of exported and imported packages. An import is wired to an export by the OSGi framework as part of the resolution process. This is what it means for your OSGi bundle to be in the RESOLVED state rather than the INSTALLED state.
All packages that you use in a bundle (except for ones starting java.*) must be imported by that bundle. In this case the import you would need is for javafx.collections. You will find examples that show you how to write an import statement, but you should definitely not do this by hand. There are a number of tools out there that will automatically generate a bundle manifest for your OSGi bundle, including the correct package import statements.
If you are using Maven then I would recommend the bnd-maven-plugin, or if you are using Gradle then you can use the relevant bnd plugin for bnd workspaces or standalone projects
The resulting manifest should end up with an entry like:
Import-Package: javafx.collections
In addition to doing this you will need to make sure that the javafx.collections package is exported by something in the framework. Normally this would involve adding a bundle which provides the relevant API package, however I suspect (I'm not a JavaFX user) that JavaFX has to be installed outside the OSGi framework. If this is the case then you will need to add the javafx.* API packages as exports from the system bundle (the bundle in the OSGi runtime representing the OSGi framework). This can be achieved using the org.osgi.framework.system.packages.extra launch property to list the packages (a list of package names separated by , characters).
Update
Your response to this post indicates that you're using Eclipse PDE. PDE isn't as flexible as bnd, and won't do this analysis for you automatically in the build. As a result you can end up with bad metadata if you forget to run through these steps, but it does still offer the ability to automatically determine your bundle's package dependencies in the IDE. The documentation for this is available from eclipse, but for reference:
Go to the Automated Management of Dependencies section of your plugin's manifest editor.
Make sure that your compile dependencies are listed in the plug in development classpath list.
Make sure that you select the Import-Package radio button. Require-Bundle promotes tight coupling and high fan out and should be avoided.
Any time that you make a change to the code you will need to click the add dependencies hyperlink. This will recalculate your package imports for you.
For the future, you may wish to consider using the Bndtools plugin for Eclipse to develop OSGi bundles rather than Eclipse PDE. Bndtools usually offers much more sophisticated (and more up-to-date) support for the OSGi specifications than PDE as it builds on top of bnd, and bnd is the reference implementation for several parts of the OSGi specification.

Understanding how to resolve "Inconsistent stackmap frames" exception

I get an exception on startup of the web application as guice is trying to construct the class mentioned.
java.lang.VerifyError: Inconsistent stackmap frames at branch target 2770 in method com.aptusi.apps.magazine.api.servlet.internal.EditorServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljava/lang/String;Lcom/aptusi/persistence/runtime/framework/DboSession;)V at offset 200
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getDeclaredConstructors(Class.java:1891)
at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:243)
at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:96)
at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:629)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:845)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
at com.google.inject.internal.InjectorImpl.getBinding(InjectorImpl.java:146)
at com.google.inject.internal.InjectorImpl.getBinding(InjectorImpl.java:66)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:103)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)`
I know about the -XX:-UseSplitVerifier and -noverify jvm options but I don't want to use as I want to ensure that all the code in this project is at least java version 7.
In order to do this It would be useful to understand where exactly this is occurring in my code, its not clear to me what the offset of 200 mentioned is but can it be related to a line number?
Also does anyone know of a way that I can find out the java versions of all classes on my classpath, I am using maven so there are a lot of dependencies, so I'm looking for an automated way of finding any classes on the classpath that may have been compiled to a lower java version than 1.7?
To find the version of a classfile, just look at the 8th byte of the classfile. It will be 51 for Java 7 classes. A framework like ASM will do this for you.
As far as the error goes, it means your classfile is malformed. How did you create these classes? Did you do any bytecode manipulation? If so, you probably have a bug in your code.

spring jdbc suddenly throws class not found error on SingleColumnRowMapper

I have been developing a Spring project about 6 months. This project is built with maven and spring. Suddenly today i discovered that jdbc sections of the code throwing the error below. I made some changes to my web services in the project lately but I did not change any maven configurations or spring configurations since the last time the application worked stable. Where should I start to look for the error?
Any comment is appreciated.
Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/core/SingleColumnRowMapper
at org.springframework.jdbc.core.JdbcTemplate.getSingleColumnRowMapper(JdbcTemplate.java:1184)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:744)
at com.pozitron.bkmtransfer.core.dao.AcsKeyAliasDaoImpl.findRsaPubKeyByBankId(AcsKeyAliasDaoImpl.java:43)
at com.pozitron.bkmtransfer.services.core.CipherActionImpl.verify(CipherActionImpl.java:97)
at com.pozitron.bkmtransfer.services.TransferActionImpl.transferMoney(TransferActionImpl.java:67)
at com.pozitron.bkmtransfer.ws.endpoints.TransferEndPoint.transferMoney(TransferEndPoint.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
At first make sure that you have this class (jar) on your classpath. If you do then make sure that you have only one version of this class in your classpath. It might be that new jar was included if you changed/added some dependencies.
Also, if you're starting your app from the eclipse then the only thing you might be needing is to do project->clean
P.S. Are you getting this error at compile time or runtime?

How to run MRUnit?

I've written an MRUnit to test my mapper. However, I don't know how to run it in Eclipse as it reads some data from distributedCache. When I run it as a normal class in Eclipse it give me a bunch of errors. These are the error messages I get:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.hadoop.mrunit.TestDriver.<clinit>(TestDriver.java:38)
at MapperCombinerReducerTester.setUp(MapperCombinerReducerTester.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at ....
Your error relates to a dependency library (commons-logging) not being on the classpath. Are you using Maven (combined with m2e) to manage your project dependencies, or are you using a straight Java Project in Eclipse?
Testing mappers / reducers which depend on the distributed cache is also tricky with MRUnit as 0.9.0 doesn't have support for emulating the distributed cache (coming in 1.0.0 if you look at the JIRA tickets). One way i've done this before is to assume the use of symlinking your local cached files, and in the setup of my unit test copying the file to the local directory (messy but it works).

Resources