how to add local jar to maven project - java

I trying a small maven project, and I try to connect to db2 database, so I need the com.ibm.db2.jcc.DB2Driver jar for the connection.
I tried many method from internet but still fail, here is some of the method I tried:
edit in pom.xml
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.5.0.7</version>
<scope>system</scope>
<systemPath>
/home/Workspace/book/springData/lib/db2jcc4-10.5.0.7.jar
</systemPath>
</dependency>
use maven command to install:
mvn install:install-file -Dfile=/home/Workspace/book/springData/lib/db2jcc4-10.5.0.7.jar -DpomFile=/home/Workspace/book/springData/pom.xml
or
mvn install:install-file -Dfile=/home/meow/Workspace/mbsb-cib/springData/lib/db2jcc4-10.5.0.7.jar -DgroupId=com.ibm.db2 -DartifactId=db2jcc4 -Dversion=10.5.0.7 -Dpackaging=jar -DgeneratePom=true
But, I am still hitting could not load JDBC driver.
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.ibm.db2.jcc.DB2Driver]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 70 more
Caused by: java.lang.IllegalStateException: Could not load JDBC driver class [com.ibm.db2.jcc.DB2Driver]
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:150)
at com.journaldev.spring.config.DataConfig.dataSource(DataConfig.java:52)
at com.journaldev.spring.config.DataConfig$$EnhancerBySpringCGLIB$$46013fb.CGLIB$dataSource$0(<generated>)
at com.journaldev.spring.config.DataConfig$$EnhancerBySpringCGLIB$$46013fb$$FastClassBySpringCGLIB$$8fec3ead.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at com.journaldev.spring.config.DataConfig$$EnhancerBySpringCGLIB$$46013fb.dataSource(<generated>)
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.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 71 more
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver from [Module "deployment.springData.war" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:147)
... 82 more

Try to add the reference from central repository in pom.xml?
<!-- https://mvnrepository.com/artifact/com.ibm.db2.jcc/db2jcc4 -->
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
</dependency>
Once you add this please rebuild your project with maven.
Or if you want to proceed from local disk : click here to view the answer in stackoverflow itself

Related

java.lang.ClassNotFoundException: org.springframework.cache.guava.GuavaCache

Context -
I have a spring boot app and
I updated the spring-boot-starter-parent version from 1.5.12.RELEASE to 2.4.0
I had this dependency in my pom -
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1-android</version>
</dependency>
Now when I am running my app, I am getting this error -
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'guavaCacheManager' defined in class path resource...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'guavaCacheManager' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/cache/guava/GuavaCache ...
Caused by: java.lang.NoClassDefFoundError: org/springframework/cache/guava/GuavaCache
at biz.kaar.common.services.cache.TempGuavaCacheConfig.guavaCacheManager(TempGuavaCacheConfig.java:32)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 43 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.cache.guava.GuavaCache
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 49 common frames omitted
I resolved this by completely removing guava dependency and its references from my project.
If you still need to use caching then try using Caffeine.
With some more research over the web, I was able to fix the same exception which was occurring in my project by adding spring-context-support to the project.
I did it by adding following dependency to my build.gradle:
compile("org.springframework:spring-context-support:4.1.7.RELEASE")
spring-context-support is a library that contains helper methods and classes for configuring the cache.
Here is the blog that I followed:
https://codedevstuff.blogspot.com/2015/07/add-guava-cache-to-spring-boot-to-cache.html

Unable to load the voltage class java.lang.NoClassDefFoundError: com/voltage/securedata/enterprise/VeException

I am trying to encrypt / decrypt messages using libvibesimplejava.so of 6.21 version where I have added the dependencies to load the jar from system path when I deployed to dev instance it's throwing this error:
Caused by: java.lang.NoClassDefFoundError: com/voltage/securedata/enterprise/VeException
Caused by: java.lang.ClassNotFoundException: com.voltage.securedata.enterprise.VeException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181]
Below is the code for library instantiation
Loading Library -
static {
System.load("src/main/resources/****/libvibesimplejava.so");
}
Library context instanitiation -
LibraryContext library = new LibraryContext.Builder()
.setPolicyURL(policyURL)
.setFileCachePath(cachePath)
.setTrustStorePath(trustStorePath)
.setClientIdProduct("****",
"***")
.build();
Pom file -
<dependency>
<groupId>vibesimplejava</groupId>
<artifactId>vibesimplejava</artifactId>
<version>6.21.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/****/lib/vibesimplejava.jar</systemPath>
</dependency>
Why it is failing to load the class in dev? Could any one suggest me the way to resolve this issue?

Spring boot : Unable to load cache item: javax/servlet/Filter

I have a spring boot project and getting some error related to javax servlet filter.
Is it some kind of version compatibility or I am missing something in pom file.
Following is the log from the console and the pom file.
I have been searching all over, couldn't find anything.
Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:249)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:281)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:125)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.abc.application.Application.main(Application.java:15)
Caused by: java.lang.IllegalStateException: Unable to load cache item
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:79)
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337)
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:138)
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:393)
... 11 more
Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getDeclaredConstructors(Class.java:2020)
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:566)
at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanFactoryAwareGeneratorStrategy.generate(ConfigurationClassEnhancer.java:252)
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
... 19 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
For me problem were in pom file (in spring boot 2 project),
when I used a parent spring boot in version 2.1.9 which under the hood uses spring-core in version 5.1.10.RELEASE
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I had dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
removing it resolved problem
I was getting the similar error in my Gradle project(might be a problem with Maven too) when I was trying to upgrade my Spring Boot version to latest one.
A quick gradle clean solved that problem for me.
Usually, this Filter class can be found in embedded tomcat jar.
So please make sure that your application (jar) contains this file:
Open up the Jar file of the compiled spring boot application and check whether the jar named like tomcat-embed-core resides in the BOOT-INF\lib folder.
This answer is valid as long as you're running tomcat of course + use JAR artifact for spring boot application (for WAR the folder is different, probably WEB-INF/lib although I've never worked with WARs of Spring Boot application so I might be wrong here)

karaf with orient db gives "java.lang.NoClassDefFoundError: com/sun/jna/Platform"

Iam trying to build up an application with
karaf 4.0.5
orientdb 2.1.16
But the orientdb service isnt loading and in the log is following error:
The callback method validate has thrown an exception : com/sun/jna/Platform
java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.orientechnologies.nio.OCLibraryFactory.<clinit>(OCLibraryFactory.java:35)
at com.orientechnologies.nio.OJNADirectMemory.<clinit>(OJNADirectMemory.java:35)
at com.orientechnologies.common.directmemory.ODirectMemoryFactory.<clinit>(ODirectMemoryFactory.java:59)
at com.orientechnologies.common.directmemory.ODirectMemoryPointerFactory.<init>(ODirectMemoryPointerFactory.java:28)
at com.orientechnologies.common.directmemory.ODirectMemoryPointerFactory.<clinit>(ODirectMemoryPointerFactory.java:24)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog$LogSegment.initPageCache(ODiskWriteAheadLog.java:558)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog$LogSegment.init(ODiskWriteAheadLog.java:279)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.<init>(ODiskWriteAheadLog.java:692)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.<init>(ODiskWriteAheadLog.java:616)
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.initWalAndDiskCache(OLocalPaginatedStorage.java:292)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:169)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:248)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getDatabase(OrientGraphFactory.java:125)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getDatabase(OrientGraphFactory.java:106)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getTx(OrientGraphFactory.java:66)
at xx.yy.zz.orientdb.OrientDatabase.__M_validate(OrientDatabase.java:30)
at xx.yy.zz.orientdb.OrientDatabase.validate(OrientDatabase.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_91]
at org.apache.felix.ipojo.util.Callback.call(Callback.java:233)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.util.Callback.call(Callback.java:193)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114)[28:org.apache.felix.ipojo:1.12.1]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_91]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_91]
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform not found by com.orientechnologies.orientdb-core [13]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_91]
... 38 more
2016-05-06 19:54:58,171 | ERROR | pool-1-thread-1 | orientdb | 21 - xx.yy.zz.orientdb - 1.0.0.SNAPSHOT | [ERROR] : java.lang.NoClassDefFoundError: com/sun/jna/Platform
java.lang.IllegalStateException: java.lang.NoClassDefFoundError: com/sun/jna/Platform
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:171)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114)[28:org.apache.felix.ipojo:1.12.1]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_91]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_91]
Caused by: java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.orientechnologies.nio.OCLibraryFactory.<clinit>(OCLibraryFactory.java:35)
at com.orientechnologies.nio.OJNADirectMemory.<clinit>(OJNADirectMemory.java:35)
at com.orientechnologies.common.directmemory.ODirectMemoryFactory.<clinit>(ODirectMemoryFactory.java:59)
at com.orientechnologies.common.directmemory.ODirectMemoryPointerFactory.<init>(ODirectMemoryPointerFactory.java:28)
at com.orientechnologies.common.directmemory.ODirectMemoryPointerFactory.<clinit>(ODirectMemoryPointerFactory.java:24)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog$LogSegment.initPageCache(ODiskWriteAheadLog.java:558)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog$LogSegment.init(ODiskWriteAheadLog.java:279)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.<init>(ODiskWriteAheadLog.java:692)
at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.<init>(ODiskWriteAheadLog.java:616)
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.initWalAndDiskCache(OLocalPaginatedStorage.java:292)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:169)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:248)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getDatabase(OrientGraphFactory.java:125)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getDatabase(OrientGraphFactory.java:106)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getTx(OrientGraphFactory.java:66)
at xx.yy.zz.orientdb.OrientDatabase.__M_validate(OrientDatabase.java:30)
at xx.yy.zz.orientdb.OrientDatabase.validate(OrientDatabase.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_91]
at org.apache.felix.ipojo.util.Callback.call(Callback.java:233)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.util.Callback.call(Callback.java:193)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)[28:org.apache.felix.ipojo:1.12.1]
at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162)[28:org.apache.felix.ipojo:1.12.1]
... 13 more
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform not found by com.orientechnologies.orientdb-core [13]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_91]
... 38 more
the maven module looks like
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-graphdb</artifactId>
<version>2.1.16</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.2.2</version>
</dependency>
adding "com.sun.jna" and "com.sun.jna.platform" to the property "org.osgi.framework.system.packages.extra" in the custom.properties file doesnt helps either
As karaf felix base Iam using:
https://github.com/thometal/ipojokaraf
Why does the orientdb module not recognize that the "jna" bundles are there?
Thank you in advance

Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext

I am trying to set up the JUnit test with the MockMVC.
From this link - "either must not use the Servlet API or you need to provide it on the classpath".
I added the following to file pom.xml, but it didn't work. What should I do?
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Here is the trace:
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.test.context.web.WebDelegatingSmartContextLoader]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:130)
at org.springframework.test.context.ContextLoaderUtils.resolveContextLoader(ContextLoaderUtils.java:118)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:594)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:560)
at org.springframework.test.context.TestContext.<init>(TestContext.java:99)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:117)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:119)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:108)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at org.springframework.test.context.web.WebDelegatingSmartContextLoader.<init>(WebDelegatingSmartContextLoader.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 22 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 28 more`enter code here`
Based on the comments, I changed the scope to compile, and then it seems past the issue of class not found!
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
It is a common issue. As Aniket Thakur said, the container will provide all Java Servlet classes at runtime. But during the tests you need a JAR file to provide them.
The dependency you added to your POM is only the API: it declares everything but contains no implementation. So it will not help. Anyway, you declare it as "provided" which says to Maven "don't worry, I know it will be on classpath".
You have to add a dependency that bring the implementation of all Java EE classes in test scope. In my projects I use GlassFish even if I later use Tomcat as a Servlet container, but I once found the dependency googling for the same problem:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
It should solve your NoClassDefFoundError problem.
Class is not found at runtime, but it is available at compile time. You need to add the corresponding JAR file so that it can be found at runtime. I generally use Ivy and in Eclipse I do:
Menu Project → Properties → Deployment Assembly → Add → Java Build Path Entries → Ivy → Finish
There must be something similar for Maven as well.
Also you need javax.servlet-api only during compile time as the container you are using to run the server will provide the actual APIs at runtime.

Categories

Resources