java.lang.NoClassDefFoundError: org/springframework/web/client/ResponseErrorHandler - java

I got this issue when I tried to open my deployed application in HEROKU. NoClassDefFoundError is being thrown for the Spring Framework class ResponseErrorHandler. I tried changing the xml and properties files, but in vain.
[33m2014-12-15T12:12:46.641119+00:00 heroku[web.1]:←[0m Starting process with command java -Dserver.port=39847 -Ddatabase.url=postgres://genreimfcnjetj:Swt7eGbTANi2-X7tBru0wTX4GT#ec2-54-235-76-206.compute-1.amazonaws.com:5432/d9108hum0pg29o -Xss512k -XX:+UseCompressedOops -Dspring.profiles.active=production -jar target/*.jar
[33m2014-12-15T12:12:47.517755+00:00 app[web.1]:←[0m at java.lang.Class.getDeclaredMethods0(Native Method)
[33m2014-12-15T12:12:47.518480+00:00 app[web.1]:←[0m at java.lang.Class.privateGetMethodRecursive(Class.java:3035)
[33m2014-12-15T12:12:47.517563+00:00 app[web.1]:←[0m Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/web/client/ResponseErrorHandler
[33m2014-12-15T12:12:47.518545+00:00 app[web.1]:←[0m at java.lang.Class.getMethod0(Class.java:3005)
[33m2014-12-15T12:12:47.519084+00:00 app[web.1]:←[0m at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
[33m2014-12-15T12:12:47.319339+00:00 app[web.1]:←[0m Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Djava.rmi.server.useCodebaseOnly=true
[33m2014-12-15T12:12:47.519022+00:00 app[web.1]:←[0m at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
[33m2014-12-15T12:12:47.518428+00:00 app[web.1]:←[0m at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
[33m2014-12-15T12:12:47.518938+00:00 app[web.1]:←[0m at java.lang.Class.getMethod(Class.java:1771)
[33m2014-12-15T12:12:47.519224+00:00 app[web.1]:←[0m Caused by: java.lang.ClassNotFoundException: org.springframework.web.client.ResponseErrorHandler
[33m2014-12-15T12:12:47.520145+00:00 app[web.1]:←[0m at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
[33m2014-12-15T12:12:47.519277+00:00 app[web.1]:←[0m at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
[33m2014-12-15T12:12:47.519388+00:00 app[web.1]:←[0m at java.security.AccessController.doPrivileged(Native Method)
[33m2014-12-15T12:12:47.520395+00:00 app[web.1]:←[0m at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[33m2014-12-15T12:12:47.520237+00:00 app[web.1]:←[0m at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[33m2014-12-15T12:12:47.519339+00:00 app[web.1]:←[0m at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[33m2014-12-15T12:12:47.520312+00:00 app[web.1]:←[0m at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[33m2014-12-15T12:12:47.520441+00:00 app[web.1]:←[0m ... 7 more
[33m2014-12-15T12:12:48.201159+00:00 heroku[web.1]:←[0m Process exited with status 1
[33m2014-12-15T12:12:48.209235+00:00 heroku[web.1]:←[0m State changed from starting to crashed
Can I have some HELP please.
Sharing my classes relating to ResponseErrorHandler.
CustomerErrorResponseHandler.java
package rentitnew;
import java.io.IOException;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
class CustomResponseErrorHandler implements ResponseErrorHandler {
private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler();
#Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return errorHandler.hasError(response);
}
#Override
public void handleError(ClientHttpResponse response) throws IOException {
}
}
Application.java
package rentitnew;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application {
#Autowired
private WebMvcProperties mvcProperties = new WebMvcProperties();
#Autowired
Credentials credentials;
#Autowired
ClientHttpRequestFactory basicSecure;
#Bean
public RestTemplate restTemplate() {
RestTemplate _restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
_restTemplate.setMessageConverters(messageConverters);
_restTemplate.setErrorHandler(new CustomResponseErrorHandler());
_restTemplate.setRequestFactory(basicSecure);
return _restTemplate;
}
#Bean
public ClientHttpRequestFactory requestFactory() {
return new BasicSecureSimpleClientHttpRequestFactory();
}
#Bean
#ConfigurationProperties(locations = "classpath:META-INF/integration/credentials.yml")
public Credentials getCredentials() {
return new Credentials();
}
public static class Credentials {
private Map<String, Map<String, String>> credentials = new HashMap<>();
public Map<String, Map<String, String>> getCredentials() {
return this.credentials;
}
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
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>rentitnew</groupId>
<artifactId>rentitnew</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rentitnew</name>
<description>Rentit Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<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>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.4.8</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.springtestdbunit</groupId>
<artifactId>spring-test-dbunit</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.16.0.RELEASE</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>rentitnew.Application</start-class>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<systemProperty>
<name>spring.profiles.active</name>
<value>production</value>
</systemProperty>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportsDirectory>shippable/testresults</reportsDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Procfile
web: java -Dserver.port=$PORT -Ddatabase.url=$DATABASE_URL $JAVA_OPTS -Dspring.profiles.active=production -jar target/*.jar
Can I have some suggestions how I can change the code/other files so that I can open my application.
Thanks in advance!

Well, I see I haven't answered this question yet. So even though it is late, I will provide the fix I had made to solve this issue.
Apart from the change proposed by Jens, I added the following plugin into the plugins tag in pom.xml.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
I had accidently removed this plugin from pom.xml which caused the issue above.

You miss the org.springframework.web in your classpath. add it to your pom and it should work.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version><!--your spring version--></version>
</dependency>

In my case only this worked (for executable jar file):
Plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Dependency (same as Jens answer):
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.10.RELEASE</version>
</dependency>

Although its late to answer but let me add my 2 cents, for me all the jars and build plugin were there in pom but scope for the jar was "provided" and hence though it was running through jar it wasn't through my IDE (intelliJ), once commented that working all good.

Related

Nullpointer exception for pico container instantion's method running maven clean test

I am getting nullpointerException while running my cucumber tests by mvn clean test.
Scenario: Run atlas # src/test/java/Atlas/Features/Atlas.feature:3
Given Go to atlas and check title # Atlas.PageObjects.AtlasPage.openAtlas()
java.lang.NullPointerException
at Atlas.PageObjects.AtlasPage.openAtlas(AtlasPage.java:12)
at âś˝.Go to atlas and check title(file:///C:/atlas%20qa/src/test/java/Atlas/Features/Atlas.feature:4)
I created WebDriverConfig.java file and I am using pico container to share this class.
Code is working until classes are in the same package but I want to separate them.
Please ask me for more information if it's needed.
package Atlas;
import io.cucumber.java.Before;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.Arrays;
import java.util.List;
public class WebDriverConfig {
public WebDriver driver;
#Before
public void setup(){
ChromeOptions chromeOptions = new ChromeOptions();
WebDriverManager.chromedriver().setup();
List<String> browserArguments = Arrays.asList(
"--window-size=1920,1080",
// "--start-maximized",
"--no-sandbox",
"--ignore-certificate-errors",
"--disable-popup-blocking",
//"--incognito",
"--allow-no-sandbox-job",
"--proxy-bypass-list=*");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments(browserArguments);
this.driver = new ChromeDriver(chromeOptions);
}
public WebDriver getDriver(){
return driver;
}
}
package Atlas.PageObjects;
import Atlas.WebDriverConfig;
import io.cucumber.java.en.Given;
import org.openqa.selenium.WebDriver;
public class AtlasPage {
WebDriver driver;
#Given("Go to atlas and check title")
public void openAtlas() {
driver.get("test env bla bla bla");
}
public AtlasPage(WebDriverConfig webDriverConfig) {
this.driver = webDriverConfig.getDriver();
}
}
pom:
<?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>atlas-automation-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>**/common.RunCucumberTest*.java</includes>
<forkCount>2</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<!-- Jar file entry point -->
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.9.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.9.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Thanks to Alexey R.
Issue is resolved.
To solve this problem I had to add classes with #Before / #After annotations to glue property in CucumberRuner class:
glue = {"Atlas.PageObjects", "Atlas.common"}

Why is a java.lang.NoClassDefFoundError raised when I run my JAR with Apache Storm ? (org/apache/storm/kafka/spout/KafkaSpoutConfig)

I started last week a formation in Kafka and Storm at OpenClassRooms. During practical work, I encounter an error when I try to execute a JAR containing my java code for Storm.
No problem when compiling the project in Java, no problem when packaging with maven, the problem only occurs when running the JAR
theirman#vm-debian:/data/eclipse-workspace/velos$ storm jar target/velos-1.0-SNAPSHOT.jar velos.App remote
Running: /usr/lib/jvm/java/bin/java -client -Ddaemon.name= -Dstorm.options= -Dstorm.home=/apps/storm -Dstorm.log.dir=/apps/storm/logs -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib:/usr/lib64 -Dstorm.conf.file= -cp /apps/storm/*:/apps/storm/lib/*:/apps/storm/extlib/*:target/velos-1.0-SNAPSHOT.jar:/apps/storm/conf:/apps/storm/bin: -Dstorm.jar=target/velos-1.0-SNAPSHOT.jar -Dstorm.dependency.jars= -Dstorm.dependency.artifacts={} velos.App remote
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/storm/kafka/spout/KafkaSpoutConfig
at velos.App.main(App.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.storm.kafka.spout.KafkaSpoutConfig
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)
... 1 more
App.java
package velos;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.generated.AlreadyAliveException;
import org.apache.storm.generated.AuthorizationException;
import org.apache.storm.generated.InvalidTopologyException;
import org.apache.storm.generated.StormTopology;
import org.apache.storm.kafka.spout.KafkaSpout;
import org.apache.storm.kafka.spout.KafkaSpoutConfig;
import org.apache.storm.topology.TopologyBuilder;
import org.apache.storm.topology.base.BaseWindowedBolt;
import org.apache.storm.tuple.Fields;
public class App
{
public static void main( String[] args ) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException
{
TopologyBuilder builder = new TopologyBuilder();
KafkaSpoutConfig.Builder<String, String> spoutConfigBuilder = KafkaSpoutConfig.builder("localhost:9092", "velib-stations");
spoutConfigBuilder.setGroupId("city-stats");
KafkaSpoutConfig<String, String> spoutConfig = spoutConfigBuilder.build();
builder.setSpout("stations", new KafkaSpout<String, String>(spoutConfig));
builder.setBolt("station-parsing", new StationParsingBolt()).shuffleGrouping("stations");
builder.setBolt("city-stats", new CityStatsBolt().withTumblingWindow(BaseWindowedBolt.Duration.of(1000*60*5))).fieldsGrouping("station-parsing", new Fields("city"));
builder.setBolt("save-results", new SaveResultsBolt()).fieldsGrouping("city-stats", new Fields("city"));
StormTopology topology = builder.createTopology();
Config config = new Config();
config.setMessageTimeoutSecs(60*30);
String topologyName = "velos";
if(args.length > 0 && args[0].equals("remote")) {
StormSubmitter.submitTopology(topologyName, config, topology);
}
else
{
LocalCluster cluster = new LocalCluster();
cluster.submitTopology(topologyName, config, topology);
}
}
}
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>velos</groupId>
<artifactId>velos</artifactId>
<version>1.0-SNAPSHOT</version>
<name>velos</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.12</artifactId>
<version>0.10.2.0</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-kafka</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-kafka-client</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
storm-kafka or storm-kafka-client likely are not provided on the storm classpath, so you would need to remove the scope from those
Then you will also want to try shading your JAR so that all dependencies are available at runtime

NoSuchMethodError: akka.actor.LocalActorRefProvider.log()Lakka/event/LoggingAdapter

When I start a simple akka-http-server, I get an exception. I searched all over the internet and found two solutions which are not working for me:
Mixing scala versions.(I had check my pom 2.11 scala without mix)
Change scala actor version.(I tried almost ten versions with 2.11 scala)
I have no idea how to resolve this problem, kindly tell me how to resolve it.
application.conf
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 2552
}
}
}
main class
package com.akkademo;
import akka.actor.ActorSystem;
import akka.actor.Props;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
public class Main {
public static void main(String[] args) {
ActorSystem actorSystem = ActorSystem.create("akkademo", ConfigFactory.load());
Config config = actorSystem.settings().config();
actorSystem.actorOf(Props.create(AkkademoDb.class), "akkademo-db");
}
}
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<scala>2.11</scala>
<scala.version>2.11.8</scala.version>
<akka.version>2.4.14</akka.version>
<akka.remote>2.3.6</akka.remote>
<akka.compat>0.7.0</akka.compat>
<akka.test>2.5.9</akka.test>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_${scala}</artifactId>
<version>${akka.test}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_${scala}</artifactId>
<version>${akka.remote}</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-java8-compat_${scala}</artifactId>
<version>${akka.compat}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_${scala}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-slf4j_${scala}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Exception in thread "main" java.lang.NoSuchMethodError:
akka.actor.LocalActorRefProvider.log()Lakka/event/LoggingAdapter;
at akka.remote.RemoteActorRefProvider.(RemoteActorRefProvider.scala:128)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$2.apply(ReflectiveDynamicAccess.scala:32)
at scala.util.Try$.apply(Try.scala:192)
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:27)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$3.apply(ReflectiveDynamicAccess.scala:38)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$3.apply(ReflectiveDynamicAccess.scala:38)
at scala.util.Success.flatMap(Try.scala:231)
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:38)
at akka.actor.ActorSystemImpl.liftedTree1$1(ActorSystem.scala:620)
at akka.actor.ActorSystemImpl.(ActorSystem.scala:613)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:142)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:119)
at akka.actor.ActorSystem$.create(ActorSystem.scala:67)
at akka.actor.ActorSystem.create(ActorSystem.scala)
at com.akkademo.Main.main(Main.java:15)
You issue is propably caused by using different minor versions of akka-remoting and the core akka-actor package.
Set the akka.version and akka.remote property to the same value. The current release is 2.5.19.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStrea

I'm pretty new on Cloudera Quick-start so sorry if my explanation will be not so clear. Anyway I'm writing a code in Java which read File from Hdfs. I build a Maven-Project and I set up all the dependencies in the pom.xml, but when I try to launch the jar from shell (java -jar jnameofthefile.jar) I'm getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStrea
This is my Java code:
package com.hdfs_java_api;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import java.io.InputStream;
import java.io.IOException;
import java.net.URI;
public class HadoopFileSystemCat {
public static void main(String [] args) throws IOException
{
String uri = "hdfs://quickstart.cloudera:8020/user/hive/warehouse/Orders.csv";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
InputStream in = null;
try {
in = fs.open(new Path(uri));
IOUtils.copyBytes(in, System.out, 4096, false);
}finally{
IOUtils.closeStream(in);
}
}
}
And this is my 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>com</groupId>
<artifactId>cards</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hdfs_java_api</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0-cdh5.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>2.6.0-cdh5.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-common</artifactId>
<version>2.6.0-cdh5.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.6.0-cdh5.13.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>cloudera</id>
<name>cloudera</name>
<url>https://repository.cloudera.com/artifactory/cloudera-
repos/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.hdfs_java_api.HadoopFileSystemCat</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
As i said I'm noob so be patient and try to be as much clear as possible, thank you in advance!
I think you are missing core library
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2</version>
</dependency>
After that make sure, you have included "Maven Dependencies" in build path.
And in Deployment Assembly -

Logging error on WAR Deploy with Tomcat7, Apache Wink, and Mongo DB

I am having problems deploying my application onto my tomcat server. I get the following trace every time I deploy it:
27-Oct-2013 17:02:34 org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/JsonTest.war
Handler error
java.io.IOException: Couldn't get lock for %h/java%u.log
at java.util.logging.FileHandler.openFiles(FileHandler.java:389)
at java.util.logging.FileHandler.<init>(FileHandler.java:225)
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:532)
at java.lang.Class.newInstance0(Class.java:374)
at java.lang.Class.newInstance(Class.java:327)
at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:521)
at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:464)
at org.apache.juli.ClassLoaderLogManager$2.run(ClassLoaderLogManager.java:377)
at org.apache.juli.ClassLoaderLogManager$2.run(ClassLoaderLogManager.java:373)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.juli.ClassLoaderLogManager.getClassLoaderInfo(ClassLoaderLogManager.java:373)
at org.apache.juli.ClassLoaderLogManager.getLogger(ClassLoaderLogManager.java:223)
at java.util.logging.LogManager.demandLogger(LogManager.java:381)
at java.util.logging.Logger.demandLogger(Logger.java:310)
at java.util.logging.Logger.getLogger(Logger.java:341)
at org.apache.juli.logging.DirectJDKLog.<init>(DirectJDKLog.java:71)
at org.apache.juli.logging.DirectJDKLog.getInstance(DirectJDKLog.java:196)
at org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:170)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:311)
at org.apache.catalina.core.ContainerBase.getLogger(ContainerBase.java:446)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5150)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:536)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1467)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Server context:
Ubuntu 12.04.3 LTS 32-bit (I'll make it 64 later..)
Tomcat 7 (only thing modified from stock install is adding users for manager[-gui])
Java
$ java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.2)
OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)
Application context:
I'm trying to convert the simple "books REST application" outlined here to use a Mongo connection. I have a feeling the Mongo part is irrelevant here. I'm also using Maven and Eclipse to deploy/build the project.
Some files:
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/maven-v4_0_0.xsd">
<!-- Project detailes -->
<modelVersion>4.0.0</modelVersion>
<groupId>net.navatwo</groupId>
<artifactId>jsontest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Test JSON Marshalling</name>
<build>
<finalName>JsonTest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/webapp/WEB-INF</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat-server</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
<!-- Dependency on Wink SDK library -->
<dependencies>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-component-test-support</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
<version>1.4</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.0</version>
</dependency>
<dependency>
<groupId>woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0-beta</version>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-jackson-provider</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.mongojack</groupId>
<artifactId>mongojack</artifactId>
<version>2.0.0-RC5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
</dependencies>
<packaging>war</packaging>
</project>
BookWebApp.java
/**
*
*/
package org.navatwo.jsontest;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.mongodb.DB;
import com.mongodb.MongoClient;
public class BookWebApp extends Application {
private Logger log;
private static class AppModule extends AbstractModule {
/* (non-Javadoc)
* #see com.google.inject.AbstractModule#configure()
*/
#Override
protected void configure() {
bind(BookService.class).to(BookServiceImpl.class);
// MONGO
try {
MongoClient mongoClient = new MongoClient("localhost");
bind(MongoClient.class).toInstance(mongoClient);
bind(DB.class).toInstance(mongoClient.getDB("db"));
} catch (UnknownHostException e) {
throw new RuntimeException("AppModule#configure threw UnknownHostException", e);
}
// LOGGING
bind(Logger.class).toInstance(LoggerFactory.getLogger(BookWebApp.class));
}
}
private Injector injector = Guice.createInjector(new AppModule());
private Set<Object> svc_singletons = new HashSet<Object>();
private Set<Class<?>> svc_classes = new HashSet<Class<?>>();
public BookWebApp() {
svc_singletons.add(injector.getInstance(BookService.class));
// svc_singletons.add(injector.getInstance(JacksonJsonProvider.class));
svc_singletons.add(injector.getInstance(Logger.class));
log.info("Started?");
log = injector.getInstance(Logger.class);
}
#Override
public Set<Object> getSingletons() {
return svc_singletons;
}
#Override
public Set<Class<?>> getClasses() {
return svc_classes;
}
}
I don't want to pollute the post with code, so if you think others would be useful, please let me know.
I appreciate any help.
java.io.IOException: Couldn't get lock for %h/java%u.log
It looks like Tomcat does not have filesystem permissions to write to the log file. The %h variable is the value of the user.home system property, which is usually the home directory of the system user running the Tomcat process. Make sure that Tomcat has write permissions to that directory.
The location of that directoy can vary, but you can find it programmatically with:
System.getProperty("user.home")
You can also modify the default value by providing the argument -Duser.home=/your/path to the Tomcat startup script.

Categories

Resources