OSGi got FrameworkFactory could not be instantiated Error - eclipse

I am trying to use OSGi and maven to develop an standard alone application.
I have the following osgi dependency in pom.xml
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
I tried the following code
import org.osgi.framework.launch.FrameworkFactory;
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
and got this error message
Exception in thread "main" java.util.ServiceConfigurationError: org.osgi.framework.launch.FrameworkFactory: Provider org.osgi.framework.launch.FrameworkFactory could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at com.scottfu.ci.test.OSGiTest.main(OSGiTest.java:19)
Caused by: java.lang.InstantiationException: org.osgi.framework.launch.FrameworkFactory
at java.lang.Class.newInstance(Class.java:427)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 3 more
Caused by: java.lang.NoSuchMethodException: org.osgi.framework.launch.FrameworkFactory.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 4 more
what is wrong?

The dependency you added is the OSGi Core API.
You need an implementation like equinox, felix or knopflerfish.
E.g.:
Instead of adding the dependency you mentioned, add
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>5.6.2</version>
</dependency>

Related

Flink 1.15.2 Upgrade: java.lang.NoClassDefFoundError: org/apache/flink/table/api/bridge/scala/StreamTableEnvironment$

When upgrading to Flink 1.15.2 I have the following dependencies. My project is built by Maven.
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.compat.version}</artifactId>
<version>1.15.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-scala-bridge_${scala.compat.version}</artifactId>
<version>1.15.2</version>
<scope>provided</scope>
</dependency>
I am trying to run a Flink app that converts a Table API to a DataStream. At the top of my App's main method I'm trying to create a StreamTableEnvironment, which will be used to do the conversions.
val env = StreamExecutionEnvironment.getExecutionEnvironment
val sTableEnv = StreamTableEnvironment.create(env)
However the app throws an error, claiming it can not find the StreamTableEnvironment class, despite it being included.
import org.apache.flink.table.api.bridge.scala.StreamTableEnvironment
Tried:
val env = StreamExecutionEnvironment.getExecutionEnvironment
val sTableEnv = StreamTableEnvironment.create(env)
Expected: it to work
What happened:
flink run -d transformer-payments-3.1-new.jar
Using the result of 'hadoop classpath' to augment the Hadoop classpath: /etc/hadoop/conf:/usr/lib/hadoop/lib/*:/usr/lib/hadoop/.//*:/usr/lib/hadoop-hdfs/./:/usr/lib/hadoop-hdfs/lib/*:/usr/lib/hadoop-hdfs/.//*:/usr/lib/hadoop-mapreduce/.//*:/usr/lib/hadoop-yarn/lib/*:/usr/lib/hadoop-yarn/.//*:/usr/lib/hadoop-lzo/lib/hadoop-lzo-0.4.19.jar:/usr/lib/hadoop-lzo/lib/hadoop-lzo.jar:/usr/lib/hadoop-lzo/lib/native:/usr/share/aws/aws-java-sdk/aws-java-sdk-bundle-1.12.331.jar:/usr/share/aws/aws-java-sdk/LICENSE.txt:/usr/share/aws/aws-java-sdk/NOTICE.txt:/usr/share/aws/aws-java-sdk/README.md:/usr/share/aws/emr/emrfs/conf:/usr/share/aws/emr/emrfs/lib/animal-sniffer-annotations-1.14.jar:/usr/share/aws/emr/emrfs/lib/annotations-16.0.2.jar:/usr/share/aws/emr/emrfs/lib/aopalliance-1.0.jar:/usr/share/aws/emr/emrfs/lib/bcprov-ext-jdk15on-1.66.jar:/usr/share/aws/emr/emrfs/lib/checker-qual-2.5.2.jar:/usr/share/aws/emr/emrfs/lib/emrfs-hadoop-assembly-2.54.0.jar:/usr/share/aws/emr/emrfs/lib/error_prone_annotations-2.1.3.jar:/usr/share/aws/emr/emrfs/lib/findbugs-annotations-3.0.1.jar:/usr/share/aws/emr/emrfs/lib/ion-java-1.0.2.jar:/usr/share/aws/emr/emrfs/lib/j2objc-annotations-1.1.jar:/usr/share/aws/emr/emrfs/lib/javax.inject-1.jar:/usr/share/aws/emr/emrfs/lib/jmespath-java-1.12.331.jar:/usr/share/aws/emr/emrfs/lib/jsr305-3.0.2.jar:/usr/share/aws/emr/emrfs/auxlib/*:/usr/share/aws/emr/cloudwatch-sink/lib/cloudwatch-sink-2.3.0.jar:/usr/share/aws/emr/cloudwatch-sink/lib/cloudwatch-sink.jar:/usr/share/aws/emr/security/conf
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/lib/flink/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/hadoop/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
2023-01-08 22:47:13,213 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /var/lib/flink/yarn/.yarn-properties-hadoop.
2023-01-08 22:47:13,213 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /var/lib/flink/yarn/.yarn-properties-hadoop.
java.lang.NoClassDefFoundError: org/apache/flink/table/api/bridge/scala/StreamTableEnvironment$
at io.benevity.data.PaymentsDataService$.main(PaymentsDataService.scala:32)
at io.benevity.data.PaymentsDataService.main(PaymentsDataService.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:355)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:222)
at org.apache.flink.client.ClientUtils.executeProgram(ClientUtils.java:114)
at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:836)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:247)
at org.apache.flink.client.cli.CliFrontend.parseAndRun(CliFrontend.java:1078)
at org.apache.flink.client.cli.CliFrontend.lambda$main$10(CliFrontend.java:1156)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1878)
at org.apache.flink.runtime.security.contexts.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1156)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.table.api.bridge.scala.StreamTableEnvironment$
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.apache.flink.util.FlinkUserCodeClassLoader.loadClassWithoutExceptionHandling(FlinkUserCodeClassLoader.java:68)
at org.apache.flink.util.ChildFirstClassLoader.loadClassWithoutExceptionHandling(ChildFirstClassLoader.java:65)
at org.apache.flink.util.FlinkUserCodeClassLoader.loadClass(FlinkUserCodeClassLoader.java:52)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 18 more
Add this dependency to the pom.xml
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>

Drools program throwing java.lang.NoClassDefFoundError:org/drools/core/impl/KnowledgeBaseFactoryServiceImpl

Need some help in running a simple POC from eclipse.
I have written a java class and a rule (.drl) in eclipse (using drools distribution 7.6.0).Code snippet where i'm creating a knowledgebase to run the rules:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("rules/Sample Rule.drl"), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
The code does not have any error. But on run time, i see the below exception
Caused by: java.lang.ClassNotFoundException: org.drools.core.impl.KnowledgeBaseFactoryServiceImpl
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
I have imported Knowledge-api-6.5.0.Final.jar. But do not see
org.drools.core.impl.KnowledgeBaseFactoryServiceImpl
instead i see
org.drools.impl.KnowledgeBaseFactoryServiceImpl
inside the jar. Am i missing something?
If you are using Drools 7.6.0, why did you import Knowledge-api-6.5.0.Final.jar?
Even if you import the right version of that jar, it will only contain the API interfaces, but no implementation at all. You still need to provide the classes implementing those interfaces while executing your code.
If you are using Maven, these are the dependencies you will need:
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.version}</version>
</dependency>
For version 7.7.0-SNAPSHOT, these dependencies translate to the following jar files:
kie-api-7.7.0-SNAPSHOT.jar
drools-compiler-7.7.0-SNAPSHOT.jar
drools-core-7.7.0-SNAPSHOT.jar
The problem of not using a dependency management system (like Maven) is that you may still need to add some extra jars to your classpath.
Hope it helps,

Java XMPP clint with smack 4.1 NoClassDefFoundError:

I am trying to write XMPP Clint using smack 4.1.1. I have added smack jar files into build path. I am using eclipse IDE to write the code.
However, when I am trying to run application I get NoClassDefFoundErrors. I fixed some of these errors adding xpp3, jxmpp and minidns jar files into the build path. Yet, I am getting the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jxmpp/util/cache/ExpirationCache
at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.<clinit>(MiniDnsResolver.java:46)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
at JabberSmackAPI.login(JabberSmackAPI.java:29)
at JabberSmackAPI.main(JabberSmackAPI.java:76)
Caused by: java.lang.ClassNotFoundException: org.jxmpp.util.cache.ExpirationCache
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 12 more
How to fix this issue?
In the internet, it is advised to use gradle or maven for building the same. If so, can you help me how to use the same? I have never used them before.
As per below stack trace
Caused by: java.lang.ClassNotFoundException: org.jxmpp.util.cache.ExpirationCache
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
It seem You are missing jxmpp-util-cache-0.5.0-alpha2.jar in your class path. Download and add this jar to your lib/ directory of your application .
In the internet, it is advised to use gradle or maven for building the
same. If so, can you help me how to use the same?
Create a meven project in eclipse .If you are new to meven project refer
How to create a Java project with Maven
And add Below dependencies to pom.xml of your meven build project
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-java7</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-tcp</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-im</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-extensions</artifactId>
<version>4.1.0</version>
</dependency>
For more details refer this link

Not able to insert data using MongoTemplate of Spring data MongoDB

``I am getting the following exception while instantiatingthg mongoTemplate
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/FieldNamingStrategy
at org.springframework.data.mongodb.core.MongoTemplate.getDefaultMongoConverter(MongoTemplate.java:1962)
at org.springframework.data.mongodb.core.MongoTemplate.(MongoTemplate.java:210)
at org.springframework.data.mongodb.core.MongoTemplate.(MongoTemplate.java:174)
at com.adobe.ffc.controller.MongoDBTest.createData(MongoDBTest.java:29)
at com.adobe.ffc.controller.MongoDBTest.main(MongoDBTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.model.FieldNamingStrategy
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 10 more
Process finished with exit code 1
the error is coming from line 1 in the following code :
MongoOperations mongoOps = new MongoTemplate(new Mongo(),"database");
User user = new User();
user.setId("200");
user.setFullName("Mongo Template");
user.setStatus("A");
user.setAge("29");
mongoOps.insert(user);
The pom configration are as follows:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.4</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
The problem is mixing Spring Data Release Trains with one another.
spring-data-mongodb 1.4 is part of Release Train Codd that requies to have spring-data-commons 1.7, while spring-data-commons 1.5 which you're currently using was part of the Arora release.
So either downgrade to spring-data-mongodb 1.2 or upgrade to spring-data-commons 1.7. Maybe also have a look at your dependencies and check for potential conflicts.
Sidenote: you can checout the spring data wiki pages to see which versions have been part of a particular release.

javax/validation/Path GWT Java Maven converstion

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.