javax/validation/Path GWT Java Maven converstion - gwt

I am using GWT in my project., recently I tried converting a manual compilation of GWT + Java + tomcat to a maven project., almost I am able successfully package it to a war., BUt when I deployed on tomcat I got followin error:
EVERE: Exception while dispatching incoming RPC call
java.lang.NoClassDefFoundError: javax/validation/Path
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.google.gwt.user.server.rpc.SerializationPolicyLoader.loadFromStream(SerializationPolicyLoader.java:196)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.loadSerializationPolicy(RemoteServiceServlet.java:90)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doGetSerializationPolicy(RemoteServiceServlet.java:293)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.getSerializationPolicy(RemoteServiceServlet.java:157)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.prepareToRead(ServerSerializationStreamReader.java:455)
Here is what i added for my added in my pom.xml:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
as dependencies.
Kindly help me.
What I need to add more to resolve the issue?

It is the dependency scope that is causing the problem. compile is actually the default scope so this could be omitted from the first dependency if you want.
The problem is in the second artifact which is declared as provided. This means that the application is expecting the web container to provide that library/classes. It looks like it is not providing the required classes, which results in the NoClassDefFoundError.
Removing the <scope>provided</scope>, will instruct Maven to package that library with the application and Tomcat should be able to get past that error.
There are no compile-time errors since the gwt-user is available at compile time. It is simply not available at run-time for Tomcat.

Related

Maven jar dependency not found at runtime by OSGi environment

I'm building an Eclipse product that requires some external dependencies, which are not bundled as Eclipse plugins.
For example javax.json-1.1.4.jar.
I'm usign a target platform file, with Maven dependency added. This is the relevant part of the .target file:
<location includeDependencyScope="compile" includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
......
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.4</version>
<type>jar</type>
</dependency>
</dependencies>
</location>
The resulting bundle is included from the plugin that uses this Json implementation: this is the MANIFEST of the plugin
Require-Bundle: org.glassfish.javax.json;bundle-version="1.1.4"
The plugin compiles and run normally. The problem happens at runtime, when the Json implementation is loaded:
2022-03-11 09:44:18,166 ERROR [main]: Provider org.glassfish.json.JsonProviderImpl not found
2022-03-11 09:44:18,168 ERROR [main]:
javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
at javax.json.spi.JsonProvider.provider(JsonProvider.java:99)
at javax.json.Json.createReader(Json.java:225)
at com.test.mas.rcp.hwconfigurator.sirius.core.utils.MotorDataHandler.parseMotorJsonFile(MotorDataHandler.java:64)
at com.test.mas.rcp.hwconfigurator.sirius.core.utils.DBHandler.initMotorsDB(DBHandler.java:209)
at com.test.mas.rcp.hwconfigurator.sirius.core.utils.DBHandler.getMotors(DBHandler.java:116)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.FieldBusDevice.getMotors(FieldBusDevice.java:1323)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.FieldBusDevice.createFromSiriusString(FieldBusDevice.java:1257)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.HwConfiguratorFactoryImpl.createFieldBusDeviceFromString(HwConfiguratorFactoryImpl.java:252)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.HwConfiguratorFactoryImpl.createFromString(HwConfiguratorFactoryImpl.java:93)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createFromString(XMLHelperImpl.java:1615)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1156)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2710)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2769)
at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:79)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2247)
Caused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl cannot be found by javax.json-api_1.1.4
at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:516)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:511)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:403)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at javax.json.spi.JsonProvider.provider(JsonProvider.java:96)
at javax.json.Json.createReader(Json.java:225)
at com.test.mas.rcp.hwconfigurator.sirius.core.utils.MotorDataHandler.parseMotorJsonFile(MotorDataHandler.java:64)
at com.test.mas.rcp.hwconfigurator.sirius.core.utils.DBHandler.initMotorsDB(DBHandler.java:209)
at com.test.mas.rcp.hwconfigurator.sirius.core.utils.DBHandler.getMotors(DBHandler.java:116)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.FieldBusDevice.getMotors(FieldBusDevice.java:1323)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.FieldBusDevice.createFromSiriusString(FieldBusDevice.java:1257)
at com.test.mas.rcp.hwconfigurator.sirius.core.impl.HwConfiguratorFactoryImpl.createFieldBusDeviceFromString(HwConfiguratorFactoryImpl.java:252)
The javax.json-1.1.4.jar is not found at runtime by the api jar javax.json-api_1.1.4.
The only way I found to make it work is to add the implementation jar to the runtime classpath settings of the plugin, in the Bundle-Classpath:
Bundle-ClassPath: .,
lib/javax.json-1.1.4.jar,
This requires the jar in the lib folder of the plugin, while it is already included from the tartget platform. It should be enough..
Is there a configuration or something to be done to make the OSGi environment recognise the jar as a Maven dependency at runtime?
I have read about Eclipse-BuddyPolicy and DynamicImport-Package but I don't know how to used them in my case, and if they are usefull.
This https://github.com/eclipse-ee4j/jsonp/issues/96 says that it "Should be fixed with javax.json:1.1.4 and jakarta.json:1.1.5" but I don't
get how...
I managed to fix this problem, thanks to the comments in this thread:
https://github.com/eclipse-ee4j/jax-ws-api/issues/90
in particular the last one:
https://github.com/eclipse-ee4j/jax-ws-api/issues/90#issuecomment-952793454
This is related to a veri similar problem I had with the implementation of the
com.sun.xml.ws.spi.ProviderImpl web service provider.
Including the OSGi Resource Locator in the bundle manifest, and the plugin with the actual implementations, make them discoverable at runtime.
This is the dependency in the target platform file:
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>osgi-resource-locator</artifactId>
<version>2.5.0-b42</version>
<type>jar</type>
</dependency>
In the end, for the Json problem, I switched to the Eclipse Parsson implementation which works at runtime without problems.
These are the needed dependencies in the target platform:
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>jakarta.json</artifactId>
<version>1.0.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<version>1.0.0</version>
<type>jar</type>
</dependency>

Junit 5 tests don't launch in Eclipse due to NoClassDefFoundError: TestEngine

(There was no question for this problem in stackoverflow, so I decided to share question & solution here.)
I wanted to migrate my Spring Boot project from JUnit 4 to JUnit 5, so I added the new API as dependency and removed the old the ones:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
I wanted to do a full migration of my project, so I explicitly excluded everything from JUnit 4, and also did not include the junit-vintage-engine (as recommended in the official migration guide).
Then, I did the various changes to make the tests compile, like replacing #Before with #BeforeEach and organizing imports. All in all, this was pretty straightforward.
But running the tests in Eclipse caused some trouble:
First I got the message "Cannot find 'junit.framework.TestCase' on project build path. JUnit 3 tests can only be run if JUnit is on the build path." In the launch configuration dialog that popped up automatically, I was able to spot my mistake: I needed to select the 'Test runner' JUnit 5.
Still no success. Now I got the message "No tests found with test runner 'JUnit 5'. This was confusing, because I had used the correct JUnit 5 annotations on the test methods. Eclipse even confirmed this because the launch configuration 'Test method' search listed the test methods just fine.
After I while, I figured out that the test execution had printed a stack trace in the console:
java.lang.NoClassDefFoundError: org/junit/platform/engine/TestEngine
at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:35)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:87)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:67)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:456)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:370)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:365)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:309)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:224)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:208)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.TestEngine
at java.net.URLClassLoader.findClass(URLClassLoader.java:444)
at java.lang.ClassLoader.loadClass(ClassLoader.java:486)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:378)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
... 14 more
This pointed me to the root cause of the problem (see answer below)...
The problem was that I was missing the dependency to the engine library:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
Then, the tests run like a charm in Eclipse.
Migration blogs like https://dev.to/martinbelev/how-to-enable-junit-5-in-new-spring-boot-project-29a8 do mention this dependency, but I primarily worked with the JUnit 5 documentation, and somehow I must have overlooked this important piece of information there...

Got RuntimeException:Unknown resource type: ResourceType = 'jBPM BPMN2 Language' when initiating a kie session

I have created a business process and build it as a jar in Kie Workbench (version 7.16.0.Final).
When trying to execute the process I got the Runtime exception.
2019-01-20 21:35:57.092 [http-nio-9043-exec-8] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Unknown resource type: ResourceType = 'jBPM BPMN2 Language'] with root cause
java.lang.RuntimeException: Unknown resource type: ResourceType = 'jBPM BPMN2 Language'
at org.kie.internal.services.KieAssemblersImpl.addResource(KieAssemblersImpl.java:51)
at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addPackageForExternalType(KnowledgeBuilderImpl.java:778)
at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addKnowledgeResource(KnowledgeBuilderImpl.java:763)
at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl$ResourceBuilder.lambda$static$6(CompositeKnowledgeBuilderImpl.java:307)
at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildResourceType(CompositeKnowledgeBuilderImpl.java:141)
at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildProcesses(CompositeKnowledgeBuilderImpl.java:121)
at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:112)
at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:100)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:251)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.buildKnowledgePackages(AbstractKieModule.java:201)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.createKieBase(AbstractKieModule.java:214)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:406)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:374)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBaseFromKieSessionModel(KieContainerImpl.java:575)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:551)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:521)
I faced this same issue (although in KIE/Drools 7.17.0.Final) and the problem was a missing dependency. In my case I had Drools/KIE/JBPM as a JBoss module and didn't have all required JARs declared in module.xml.
What I did to fix it was to add the following two JARs to module.xml (and of course, put the JARs into the module's main folder):
jbpm-bpmn2-7.17.0.Final.jar
jbpm-flow-builder-7.17.0.Final.jar
You can find these JARs under Drools and jBPM tools distribution.
When using as runtime version one of the latest:
<runtime.version>7.42.0.Final</runtime.version>
Then, it's enough to have the following set of libraries (which are automatically added if you create a Drools project with Eclipse+Drools plugin):
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-test</artifactId>
</dependency>
There's a sample demo project here: Using Drools Rules with jBPM

No Jar found in /WEB-INF/lib after deploying maven project from eclipse to wildlfy9

I am seeing a very strange behavior of wildfly9.x. Build process goes successful. after clicking on RUN AS -> Run on Server(WildFly9.x). It shows exception like NO class def found.
I have already added dependency in POM.xml and its scope is compile.
POM.xml file:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
Exception:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64 from [Module "deployment.worldportfolio.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
Thanks in advance.
I solved it by myself. If you want to run wildfly server from eclipse IDE so you should follow this a very simple method create lib folder in WEB-INF and place all the required Jars in the lib folder. You are done.

org.hibernate.cfg.beanvalidation.TypeSafeActivator;141) HHH000274: Unable to apply constraints on DDL

I am using JDK 1.7 with Maven 3.0 for my project.
When I have the following in pom.xml
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>compile</scope>
</dependency>
I am getting the following while deploying to Weblogic 10.3.6 integrated with Eclipse
WARN (org.hibernate.cfg.beanvalidation.TypeSafeActivator;141) HHH000274:
Unable to apply constraints on DDL for test.entity.Employee
java.lang.NullPointerException at
org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:172)
If I remove javaee-api dependency, then I do have issues when I compile project using mvn compile with errors like
[ERROR] /domain/view/EmployeeNameConverter.java:[29,76] cannot access
javax.el.ELContext
class file for javax.el.ELContext not found
[ERROR] /EmployeeNameConverter.java:[28,55] cannot access javax.el.ELResolver
class file for javax.el.ELResolver not found
More details here
How can I resolve this issue?
Like we've worked out in the comments Weblogic 11g doesn't support Java EE6. So one solution can be using Java EE5 instead.