When I launch ScyllaDB for the first time:
Cluster cluster = Cluster.builder().addContactPoints("xx.xxx.xx.xxx").build();
Session session = cluster.connect("my_scylladb_cluster");
System.out.println(session.isClosed());
I get the following error:
===== Using optimized driver!!! =====
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
at com.datastax.driver.core.Metrics.<init>(Metrics.java:156)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1773)
at com.datastax.driver.core.Cluster.init(Cluster.java:228)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:401)
at com.datastax.driver.core.Cluster.connect(Cluster.java:352)
at scylladbX.ScyllaDBXMain.main(ScyllaDBMain.java:12)
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
In my Maven POM file I'm using the latest version of Metrics:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.2.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-graphite -->
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>4.2.9</version>
</dependency>
I noticed that if I downgrade to a much earlier version of Metrics, the problem goes away:
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-core -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-graphite -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>3.0.0</version>
</dependency>
Does ScyllaDB not support the latest version of Metrics? What is the latest version supported?
Thanks
The DataStax Java Driver documentation here has a section about the problem you saw:
While the driver depends on Metrics 3.2.x, it also works with Metrics 4, with some caveats.
In Metrics 4, JMX reporting was moved to a separate module, metrics-jmx. Because of this you are likely to encounter the following exception at runtime when initializing a Cluster:
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
at com.datastax.driver.core.Metrics.<init>(Metrics.java:103)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1402)
at com.datastax.driver.core.Cluster.init(Cluster.java:159)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305)
at com.datastax.durationtest.core.DurationTest.createSessions(DurationTest.java:360)
....
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 8 more
That document also has suggestions what to do in this case.
In any case, this problem has nothing to do with Scylla (the backend server you want to connect to) - and is just a problem with the Java client ("driver") you are using.
I'm trying to deploy a bundle in karaf. I want to create a process engine inside of it which connects to h2 database. I have the dependency in pom.xml:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
</dependency>
In ini() method I try to create engine process using:
ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
.setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
.setJobExecutorActivate(true)
.buildProcessEngine();
Nevertheless, in karaf console when I deploy the bundle I got the error:
Caused by: org.apache.ibatis.datasource.DataSourceException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:179)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:57)
at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:349)
at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:55)
.......
Caused by: java.lang.ClassNotFoundException: org.h2.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:173)
Could you print the built MANIFEST ?
And the result of bundle:headers
I guess your bundle try to import h2 Driver because you did not set it to private.
Quick fix, in karaf, run
bundle:install mvn:com.h2database/h2/1.4.199
I am using jsp as front end in spring boot app. I deployed application on localhost through tomcat8 manager and application runs perfectly. But when I follow same steps of deployment on hosting server I am getting below error
Caused by: java.lang.NoClassDefFoundError: javax/servlet/GenericFilter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
Hence I included dependency in pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
and after updating project I have javax.servlet in my classpath and in war file also. Please guide me to resolve this issue.
i'm definitely not an expert in mvn, but after 2 days hacking around, i'm just giving up.
my workflow:
1.
mvn archetype:generate
-DarchetypeGroupId=org.apache.flink
-DarchetypeArtifactId=flink-quickstart-scala
-DarchetypeVersion=0.10.1
-DgroupId=org.apache.flink.quickstart
-DartifactId=flink-scala-project
-Dversion=0.1
-Dpackage=org.apache.flink.quickstart
-DinteractiveMode=false
2.
cd flink-scala-project
3.
mvn clean package
here is a build log: https://gist.github.com/zavalit/1e78478ebdda827f3454 and when I run
`java -jar target/flink-scala-project-0.1.jar`
I get
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/scala/ExecutionEnvironment$
at org.apache.flink.quickstart.Job$.main(Job.scala:41)
at org.apache.flink.quickstart.Job.main(Job.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.scala.ExecutionEnvironment$
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)
... 2 more
The fat jar which you're building is not supposed to be run outside of a cluster environment. Therefore, all Flink related dependencies which run in the cluster environment are excluded from the fat jar.
What you usually do with the generated fat jar is to submit it to a local or remote cluster via bin/flink run -c org.example.MyJob myFatJar.jar. In order to start quickly a local cluster you can run bin/start-local.sh. This will start a local cluster to which you can submit your job jar.
By default, the flink libraries are not included in the fat jar since it would be provided by flink cluster at runtime. To fix that, change the scope of dependencies in pom.xml, from provided to compile:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>compile</scope>
</dependency>
link: Maven Doc
I Started a new project with Spring Boot 1.2.3. I'm getting error
java.lang.NoClassDefFoundError: javax/servlet/Filter
Gradle Dependencies:
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.codehaus.groovy:groovy")
compile("com.h2database:h2")
compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity3")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile 'org.webjars:jquery:2.1.4'
compile 'org.webjars:bootstrap:3.3.4'
}
Here is the full stack trace
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getMethod0(Class.java:2813)
at java.lang.Class.getMethod(Class.java:1663)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:125)
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
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)
... 29 more
Process finished with exit code 1
for the maven users,
comment the scope provided in the following dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
UPDATE
As feed.me mentioned you have to uncomment the provided part depending on what kind of app you are deploying.
Here is a useful link with the details:
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-maven-packaging
It's not good to change the scope of your application dependencies. Putting the dependency as compile, will provide the dependency also in your artifact that will be installed somewere.
The best think to do is configure the RUN configuration of your sping boot application by specifying as stated in documentation :
"Include dependencies with 'Provided' scope" "Enable this option to
add dependencies with the Provided scope to the runtime classpath."
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
This should be
compile("org.springframework.boot:spring-boot-starter-tomcat")
It's interesting things with IDE (IntelliJ in this case):
if you leave default, i.e. don't declare spring-boot-starter-tomcat as provided, a spring-boot-maven-plugin (SBMP) put tomcat's jars to your war -> and you'll probably get errors deploying this war to container (there could be a versions conflict)
else you'll get classpath with no compile dependency on tomcat-embed (SBMP will build executable war/jar with provided deps included anyway)
intelliJ honestly doesn't see provided deps at runtime (they are not in classpath) when you run its Spring Boot run configuration.
and with no tomcat-embed you can't run Spring-Boot with embedded servlet container.
There is some tricky workaround: put Tomcat's jars to classpath of your idea-module via UI: File->Project Structure->(Libraries or Modules/Dependencies tab) .
tomcat-embed-core
tomcat-embed-el
tomcat-embed-websocket
tomcat-embed-logging-juli
Better solution for maven case
Instead of adding module dependencies in Idea, it is better to declare maven profile with compile scope of spring-boot-starter-tomcat library.
<profiles>
<profile>
<id>embed-tomcat</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</profile>
</profiles>
while spring-boot-starter-tomcat was declared provided in <dependencies/>, making this profile active in IDE or CLI (mvn -Pembed-tomcat ...) allow you to launch build with embedded tomcat.
Add the following dependency. The scope should be compile then it will work.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope>
</dependency>
In my case scope of that dependency was provided.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
So, I was getting the same issue.
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
I had to enable the below option in Intellij
Add dependencies with "provided" scope to classpath
You will see below option enabled,
OR
You can add the below property to .intellij/workspace.xml file under your application configuration section.
<option name="INCLUDE_PROVIDED_SCOPE" value="true" />
e.g.,
<component name="RunManager" selected="Application.DemoApp">
<configuration name="DemoApp" type="Application" factoryName="Application">
<option name="INCLUDE_PROVIDED_SCOPE" value="true" /> ```
For Jar
Add pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
That looks like you tried to add the libraries servlet.jar or servlet-api.jar into your project /lib/ folder, but Tomcat already should provide you with those libraries. Remove them from your project and classpath. Search for that anywhere in your project or classpath and remove it.
The configuration here is working for me:
configurations {
customProvidedRuntime
}
dependencies {
compile(
// Spring Boot dependencies
)
customProvidedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
}
war {
classpath = files(configurations.runtime.minus(configurations.customProvidedRuntime))
}
springBoot {
providedConfiguration = "customProvidedRuntime"
}
2023 Solution
Remove provided from maven of tomcat artifactId
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- Here <scope>provided</scope >-->
</dependency>