I can't find SqlServerDriver on java project - java

I'm trying to connect to SQL Server and insert the data into the database. I have a class person, main and DataBaseInfo. I have download maven library for all the errors I had and it didn't work. I don't know why.
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id='data' class='com.microsoft.sqlserver.jdbc.SQLServerDriver'>
<property name='driverClassName' value ='java.sql.DriverManager'></property>
<property name='dataSource' value ='jdbc:sqlserver://10.222.115.11:1433;databaseName=Test;integratedSecurity=true'></property>
<property name='username' value='HmgDbUser'></property>
<property name='password' value='123456'></property>
</bean>
<bean id='template' class='org.springframework.jdbc.core.JdbcTemplate'>
<property name='dataSource' ref ='data'></property>
</bean>
<bean id='dbi' class='test1.DataBaseInfo'>
<property name='template' ref ='template'></property>
</bean>
</beans>
My pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>test1</artifactId>
<name> Spring boots test</name>
<version>0.0.2-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssqljdbc6</artifactId>
<version>6.2.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
</properties>
</project>
My Main
package test1;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
//jdbc:sqlserver:10.200.105.11;databaseName=test;integratedSecurity=true
public static void main(String[] args) {
ApplicationContext conx = new ClassPathXmlApplicationContext("bean.xml");
DataBaseInfo di = (DataBaseInfo)conx.getBean("dbi");
int ins=di.insertPerson(new Person("abdulaziz","riyadh","Saudi","Developer"));
System.out.println(ins);
}
}
When I run it, this error occurs:
Oct 28, 2018 4:35:01 PM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.microsoft.sqlserver.jdbc.SQLServerDriver] for bean with name 'data' defined in class path resource [bean.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.microsoft.sqlserver.jdbc.SQLServerDriver] for bean with name 'data' defined in class path resource [bean.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1385)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:663)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:630)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1491)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1014)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:826)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at test1.Main.main(Main.java:8)
Caused by: java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1015)
at java.lang.ClassLoader.loadClass(ClassLoader.java:413)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:275)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:437)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1430)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1374)
... 10 more
My java version

You have two options.
Use JDK version 10 while compiling your maven module. Version 10 since the exception you have supplied indicates so. Class file format 54 corresponds to Java 10. See here.
Use a version of the JDBC driver compiled for JDK version 8 or matching the JDK version you want to use. But do check the documentation of your database as well, to ensure you pick up the correct driver implementation. Here's one for example:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>

Try to use low version jdbc driver from maven

Related

ERROR StatusLogger Unable to create Lookup for ctx

I have this error when i run my project :
ERROR StatusLogger Unable to create Lookup for ctx
Here is the whole stacktrace :
ERROR StatusLogger Unable to create Lookup for ctx
java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ServiceLoaderUtil
at org.apache.logging.log4j.core.impl.ThreadContextDataInjector.getServiceProviders(ThreadContextDataInjector.java:77)
at org.apache.logging.log4j.core.impl.ThreadContextDataInjector.(ThreadContextDataInjector.java:64)
at org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForCopyOnWriteThreadContextMap.(ThreadContextDataInjector.java:211)
at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:94)
at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:71)
at org.apache.logging.log4j.core.lookup.ContextMapLookup.(ContextMapLookup.java:34)
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 org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:189)
at org.apache.logging.log4j.core.lookup.Interpolator.(Interpolator.java:81)
at org.apache.logging.log4j.core.lookup.Interpolator.(Interpolator.java:100)
at org.apache.logging.log4j.core.config.AbstractConfiguration.(AbstractConfiguration.java:135)
at org.apache.logging.log4j.core.config.NullConfiguration.(NullConfiguration.java:32)
at org.apache.logging.log4j.core.LoggerContext.(LoggerContext.java:74)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
at org.apache.poi.ooxml.POIXMLDocumentPart.(POIXMLDocumentPart.java:56)
at CreateDocumentSimple.main(CreateDocumentSimple.java:88)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.ServiceLoaderUtil
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 27 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.core.impl.ThreadContextDataInjector
at org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForCopyOnWriteThreadContextMap.(ThreadContextDataInjector.java:211)
at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:94)
at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:71)
at org.apache.logging.log4j.core.impl.ReusableLogEventFactory.(ReusableLogEventFactory.java:42)
at org.apache.logging.log4j.core.config.LoggerConfig.(LoggerConfig.java:101)
at org.apache.logging.log4j.core.config.AbstractConfiguration.(AbstractConfiguration.java:138)
at org.apache.logging.log4j.core.config.NullConfiguration.(NullConfiguration.java:32)
at org.apache.logging.log4j.core.LoggerContext.(LoggerContext.java:74)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
at org.apache.poi.ooxml.POIXMLDocumentPart.(POIXMLDocumentPart.java:56)
at CreateDocumentSimple.main(CreateDocumentSimple.java:88)
I don't know where this come from since i don't user any logger in my whole projet. If you need more information please feel free to ask.
Here is my pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>TestPoi</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
</dependencies>
</project>
Add the library log4j-api.jar to the classpath.
To make your project work you have to remove all jars starting with log4j-1.x.
I made the same mistake, because when I downloaded the log4j dependency package, I didn't know which files I needed, so I added all of them. But by doing so, for whatever reason, now log4j 1 is used instead of log4j 2.

How to create local database using JPA?

I am just starting to use JPA. I am trying to create database based on schema using Persistence.generateSchema("DataLayer", null) method, but i get an exception. As JPA implementation i am using OpenJPA.
My solution is divided into two Eclipse projects. Both use Maven and module-info.java.
1st project is clearly just main method where i call the method above.
2nd one is JPA entities and data access objects.
In 1st project i included dependency to 2nd project. In 2nd project i included dependencies to jpa implementor (openjpa) and database driver (derby). See dependencies part from pom.xml's bellow:
1st project dependency (there is just my 2nd project):
<dependency>
<groupId>registry</groupId>
<artifactId>datalayer</artifactId>
<version>0.0.1</version>
</dependency>
1st project module-info:
module justtestingTEMP
{
exports justtestingTEMP;
requires registry.datalayer;
requires javax.persistence;
}
2nd project dependencies:
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.15.2.0</version>
</dependency>
</dependencies>
2nd project module-info:
module registry.datalayer
{
exports datalayer.other;
exports datalayer.dto;
exports datalayer.dao;
requires javax.persistence;
}
This is persistence.xml (it is in 2nd project):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="DataLayer"
transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>myNonJtaDataSource</non-jta-data-source>
<properties>
<property
name="javax.persistence.schema-generation.database.action"
value="create" />
</properties>
</persistence-unit>
This is the exception:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/sql/DataSource
at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newInstance(JDBCBrokerFacto
ry.java:72)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Metho
d)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodA
ccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Delegatin
gMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:131)
at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:66)
at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(Pers
istenceProviderImpl.java:152)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFa
ctory(PersistenceProviderImpl.java:95)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFa
ctory(PersistenceProviderImpl.java:159)
at org.apache.openjpa.persistence.PersistenceProviderImpl.generateSchema(Persis
tenceProviderImpl.java:244)
at javax.persistence#1.1/javax.persistence.Persistence.generateSchema(Persisten
ce.java:188)
at justtestingTEMP/justtestingTEMP.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoade
r.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoa
ders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
Where can i get that javax.sql.DataSource class from? I guess i am missing some dependency or i have configured something wrong.
What i tried: Switch JPA implementation (other exceptions were raised - but about missing classes), add requires java.sql; to module-info.
After adding requires java.sql; to module-info:
Exception in thread "main" java.lang.NoClassDefFoundError: java/lang /instrument/
ClassFileTransformer
at org.apache.openjpa.persistence.PersistenceProviderImpl.loadAgent(Persistence
ProviderImpl.java:365)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFa
ctory(PersistenceProviderImpl.java:102)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFa
ctory(PersistenceProviderImpl.java:159)
at org.apache.openjpa.persistence.PersistenceProviderImpl.generateSchema(Persis
tenceProviderImpl.java:244)
at javax.persistence#1.1/javax.persistence.Persistence.generateSchema(Persisten
ce.java:188)
at justtestingTEMP/justtestingTEMP.Main.main(Main.java:14)
Caused by: java.lang.ClassNotFoundException: java.lang.instrument.ClassFileTrans
former
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoade
r.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoa
ders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 6 more
Found out that required classes were in java.sql and and java.instrument module, so adding these to module-info solve my issue. module-info.java should look like this:
module justtestingTEMP
{
exports justtestingTEMP;
requires java.instrument;
requires java.sql;
requires javax.persistence;
requires registry.datalayer;
}
Also it is possible to remove module-info.java from 1st project. That resulted in a "correct" error saying that i have not defined jdbc driver and connection properties - that is good. No class not found errors. I can create and connect to database now. That is probably because all required modules are available implicitly. With module-info.java i have to define all required modules.

Sending Message to Azure Event Hub

I am trying to connect to Azure event hub as described here. But getting below error:
Exception in thread "main" java.lang.NoSuchMethodError: reactor.core.publisher.Flux.retryWhen(Ljava/util/function/Function;)Lreactor/core/publisher/Flux;
at com.azure.core.amqp.implementation.RetryUtil.withRetry(RetryUtil.java:58)
at com.azure.core.amqp.implementation.ReactorConnection.getClaimsBasedSecurityNode(ReactorConnection.java:142)
at com.azure.messaging.eventhubs.implementation.EventHubReactorAmqpConnection.createSession(EventHubReactorAmqpConnection.java:148)
at com.azure.core.amqp.implementation.ReactorConnection.lambda$createSession$9(ReactorConnection.java:203)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at com.azure.core.amqp.implementation.ReactorConnection.lambda$createSession$10(ReactorConnection.java:197)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:210)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1784)
at reactor.core.publisher.MonoCallable.subscribe(MonoCallable.java:61)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:157)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1784)
at com.azure.core.amqp.implementation.AmqpChannelProcessor$ChannelSubscriber.onNext(AmqpChannelProcessor.java:310)
at com.azure.core.amqp.implementation.AmqpChannelProcessor.lambda$onNext$0(AmqpChannelProcessor.java:87)
at java.lang.Iterable.forEach(Iterable.java:75)
at com.azure.core.amqp.implementation.AmqpChannelProcessor.onNext(AmqpChannelProcessor.java:87)
at reactor.core.publisher.FluxRepeatPredicate$RepeatPredicateSubscriber.onNext(FluxRepeatPredicate.java:85)
at reactor.core.publisher.Operators$MonoSubscriber.request(Operators.java:1871)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.request(Operators.java:2118)
at com.azure.core.amqp.implementation.AmqpChannelProcessor.requestUpstream(AmqpChannelProcessor.java:257)
at com.azure.core.amqp.implementation.AmqpChannelProcessor.subscribe(AmqpChannelProcessor.java:210)
at reactor.core.publisher.Mono.subscribe(Mono.java:4046)
at reactor.core.publisher.Mono.block(Mono.java:1726)
at com.azure.messaging.eventhubs.EventHubProducerClient.createBatch(EventHubProducerClient.java:127)
at com.sample.eventhub.eventhub.EventhubDemoApplication.main(EventhubDemoApplication.java:63)
The line at which the error is thrown(EventhubDemoApplication.java:63) has "EventDataBatch batch = producer.createBatch();"
My Pom.xml is as below:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.sample.eventhub</groupId>
<artifactId>eventhub</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eventhub-demo</name>
<description>Demo project for eevnt hub</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs</artifactId>
<version>5.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Tried changing the Spring Boot version(2.3.7), then getting the below error:
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
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.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: com.azure.core.amqp.exception.AmqpException: The messaging entity '************************' could not be found. To know more visit https://aka.ms/sbResourceMgrExceptions. TrackingId:"*********", SystemTracker:**********************, Timestamp:2021-01-11T09:40:57, errorContext[NAMESPACE: ******************, PATH: $cbs, REFERENCE_ID: cbs:receiver, LINK_CREDIT: 0]
at com.azure.core.amqp.implementation.ExceptionUtil.distinguishNotFound(ExceptionUtil.java:114)
at com.azure.core.amqp.implementation.ExceptionUtil.amqpResponseCodeToException(ExceptionUtil.java:101)
at com.azure.core.amqp.implementation.RequestResponseChannel.settleMessage(RequestResponseChannel.java:274)
at com.azure.core.amqp.implementation.RequestResponseChannel.lambda$new$0(RequestResponseChannel.java:124)
at reactor.core.publisher.LambdaSubscriber.onNext(LambdaSubscriber.java:160)
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:114)
at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:793)
at reactor.core.publisher.FluxCreate$BufferAsyncSink.next(FluxCreate.java:718)
at reactor.core.publisher.FluxCreate$SerializedSink.next(FluxCreate.java:153)
at com.azure.core.amqp.implementation.handler.ReceiveLinkHandler.onDelivery(ReceiveLinkHandler.java:95)
at org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:185)
at org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108)
at org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:324)
at org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:291)
at com.azure.core.amqp.implementation.ReactorExecutor.run(ReactorExecutor.java:82)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:139)
at reactor.core.publisher.Mono.block(Mono.java:1709)
at com.azure.messaging.eventhubs.EventHubProducerClient.createBatch(EventHubProducerClient.java:127)
at com.example.Sender.SenderApplication.main(SenderApplication.java:30)
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.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Tried looking into the answer here, but no luck.
Also, I am trying only send part mentioned in the Microsoft official docs. Is that causing the issue?
Any input in this regard would be great.
The NoSuchMethodError is a result of conflicting dependencies in which it resolved a version of project reactor that does not match the one used in azure-messaging-eventhubs. The problem is that it is resolving "reactor-core" version 3.4.1 where-as azure-messaging-eventhubs uses version 3.3.0.RELEASE. In between these releases, Flux.retryWhen's methods were changed to use Retry class rather than a function and a publisher.
You can see this dependency conflict if you execute:
.\mvnw.cmd org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true -Dincludes=*reactor*
One solution is to upgrade your dependency to 5.3.1.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs</artifactId>
<version>5.3.1</version>
</dependency>
Or, you can downgrade your version of spring-boot to one that works with reactor-core 3.3.0.RELEASE (if you want to keep using azure-messaging-eventhubs 5.0.1). Or explicitly select a version of reactor-core in your pom.xml... Though, you may encounter other NoSuchMethodErrors.
Thank you #Connie for your response.
Found that legacy event hub was used. Following this Microsoft doc helped me in connecting to the event hub.

Gobblin Error:- java.io.IOException: java.lang.ClassNotFoundException:

I'm new to the Gobblin and trying to ingest data from the Kafka to HDFS. I was able to flow the Kafka-HDFS Ingestion example successfully. But now I need to add a time-based writer partition option to my job. I did go through the TimeBasedWriterPartitioner google forum and come up with the bellow solution as suggested by Zongjun.
I create a separate Java project for my time-based writer partition class:
import gobblin.writer.partitioner.TimeBasedWriterPartitioner;
public class LogJsonWriterPartitioner extends TimeBasedWriterPartitioner<byte[]> {
public LogJsonWriterPartitioner(gobblin.configuration.State state, int numBranches, int branchId) {
super(state, numBranches, branchId);
}
#Override
public long getRecordTimestamp(byte[] payload) {
return System.currentTimeMillis();
}
}
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pm.data.gobblin.kafka</groupId>
<artifactId>LogJsonWriterPartitioner </artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.linkedin.gobblin</groupId>
<artifactId>gobblin-api</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.linkedin.gobblin</groupId>
<artifactId>gobblin-core</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Create a Jar from the above project and copy it to gobblin-dist/lib directory
I update gobblin-mapreduce.sh in gobblin-dist/bin directory and add the new jar name under LIBJARS.
Create a Job file as bellow:
job.name=GobblinKafkaQuickStart
job.group=GobblinKafka
job.description=Gobblin quick start job for Kafka
job.lock.enabled=false
fs.uri=file:///
kafka.brokers=localhost:9092
source.class=org.apache.gobblin.source.extractor.extract.kafka.KafkaSimpleSource
extract.namespace=org.apache.gobblin.extract.kafka
writer.builder.class=org.apache.gobblin.writer.SimpleDataWriterBuilder
writer.partitioner.class=com.pm.data.gobblin.kafka.LogJsonWriterPartitioner
writer.partition.granularity=day
writer.partition.pattern=YYYY-MM-dd
writer.partition.timezone=UTC
writer.file.path.type=tablename
writer.destination.type=HDFS
writer.output.format=txt
data.publisher.type=org.apache.gobblin.publisher.BaseDataPublisher
data.publisher.replace.final.dir=false
data.publisher.final.dir=/home/myuser/Desktop/Gobblin
mr.job.max.mappers=1
metrics.reporting.file.enabled=true
metrics.log.dir=${gobblin.cluster.work.dir}/metrics
metrics.reporting.file.suffix=txt
bootstrap.with.offset=earliest
Then I start gobblin as standalone using the gobblin-standalone.sh file in the bin directory.
I got below error on logs/gobblin-current.log
org.apache.gobblin.runtime.fork.Fork 250 - Fork 0 of task task_GobblinKafkaQuickStart_1590391135660_0 failed to process data records. Set throwable in holder org.apache.gobblin.runtime.ForkThrowableHolder#433cf3c0
java.io.IOException: java.lang.ClassNotFoundException: com.pm.data.logging.gobblin.LogJsonWriterPartitioner
at org.apache.gobblin.writer.PartitionedDataWriter.<init>(PartitionedDataWriter.java:135)
at org.apache.gobblin.runtime.fork.Fork.buildWriter(Fork.java:534)
at org.apache.gobblin.runtime.fork.Fork.buildWriterIfNotPresent(Fork.java:542)
at org.apache.gobblin.runtime.fork.Fork.processRecord(Fork.java:502)
at org.apache.gobblin.runtime.fork.AsynchronousFork.processRecord(AsynchronousFork.java:103)
at org.apache.gobblin.runtime.fork.AsynchronousFork.processRecords(AsynchronousFork.java:86)
at org.apache.gobblin.runtime.fork.Fork.run(Fork.java:243)
at org.apache.gobblin.util.executors.MDCPropagatingRunnable.run(MDCPropagatingRunnable.java:39)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.pm.data.logging.gobblin.LogJsonWriterPartitioner
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.gobblin.writer.PartitionedDataWriter.<init>(PartitionedDataWriter.java:128)
... 12 more
Whoever when I modify my job file as writer.partitioner.class=LogJsonWriterPartitioner, error is changed as java.lang.NoClassDefFoundError: gobblin/writer/partitioner/TimeBasedWriterPartitioner.
Could some help me to overcome this problem?
For the first problem, make sure that you have correct package statement for LogJsonWriterPartitioner, i would expect it to be package com.pm.data.logging.gobblin
For the second, looks like dependencies in pom.xml are not correct, and that is why TimeBasedWriterPartitioner cannot be loaded. com.linkedin.gobblin was renamed to org.apache.gobblin long time ago, and the version numbers are higher. Recent release was '0.14.0'

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: linux, architecture: x86_64

I am trying setup TensorFlow Java application in Eclipse Oxygen (OS: Ubuntu Linux 16.x). I installed Tensorflow and followed the process mentioned in official documentation for Java (Maven Project) installation. I downloaded libtensorflow-1.3.0.jar, jni files and included in the build path. When I execute the program I get this following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: linux, architecture: x86_64. See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/java/README.md for possible solutions (such as building the library from source). Additional information on attempts to find the native library can be obtained by adding org.tensorflow.NativeLibrary.DEBUG=1 to the system properties of the JVM.
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.TensorFlow.init(TensorFlow.java:36)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:40)
at com.tensorflow.malwaredetection.App.main(App.java:13)
App.java
package com.tensorflow.malwaredetection;
import org.tensorflow.TensorFlow;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!"+ TensorFlow.version() );
}
}
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TensorFlow</groupId>
<artifactId>MalwareDetection</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MalwareDetection</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<exec.mainClass>App</exec.mainClass>
<!-- The sample code requires at least JDK 1.7. -->
<!-- The maven compiler plugin defaults to a lower version -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</project>
I got tired of this error and tried to do this in an old-fashioned way. Created App.java in a separate folder and included jar, jni files in the same directory. When I execute this from command line, I get different error
dev#ubuntu:~/Downloads$ javac -cp libtensorflow-1.3.0.jar Test1.java
dev#ubuntu:~/Downloads$ java -cp libtensorflow-1.3.0.jar:. -Djava.library.path=./jni Test1
Error: Could not find or load main class Test1
dev#ubuntu:~/Downloads$
I think you need to include jni library dependency in your pom.
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow_jni</artifactId>
<version>1.1.0</version>
</dependency>
When you have tensor flow dependency in your pom.xml file as below
<dependencies>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow</artifactId>
<version>1.14.0</version>
</dependency>
It will download required 3 libraries
tensorflow-1.14.0.jar
libtensorflow-1.14.0.jar
libtensorflow_jni-1.14.0.jar
So you have to manually extract the 3rd jar(libtensorflow_jni) and get your OS compatible file like for windows you have to copy the tensorflow_jni.dll file and paste in your project root directory
that will solve your problem.
For Linking error the JNI library which you have downloaded is
not compatible with OS you are running,
is not in PATH () or
with lesser probability TensorFlow bu which you should be able to confirm from TF triage.
For second could not find class
your PATH must be appended with "." so that it can find class in current folder from where it is running
Less probability is if class name/package is not same.
If you can post code for class will check

Categories