sshj 0.9.0 throwing NoClassDefFoundError: net/schmizz/sshj/SSHClient - java

My code below is throwing following Error and only information i can find on Google involved logging errors but nothing that looks like mine. I have tried installing dependences it says are needed on the central maven repo but still the problem persists. Does anyone know why im getting class no found exceptions?
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
public class ConnectSSH {
public void connecting() throws IOException {
#SuppressWarnings("resource")
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("*******");
try {
ssh.authPassword("*****", "*****");
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("*****");
System.out.print(IOUtils.readFully(cmd.getInputStream()));
cmd.join(5, TimeUnit.SECONDS);
System.out.print("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
}
}
Error below is thrown when running:
Exception in thread "main" java.lang.NoClassDefFoundError: net/schmizz/sshj/SSHClient
at ssh.liq_con.stats.ConnectSSH.connecting(ConnectSSH.java:16)
at ssh.liq_con.stats.App.main(App.java:8)
Caused by: java.lang.ClassNotFoundException: net.schmizz.sshj.SSHClient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Note i have:
<dependency>
<groupId>net.schmizz</groupId>
<artifactId>sshj</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.49</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
<version>1.1.3</version>
</dependency>

You actually don't need to install dependencies - they are auto-fetched by Maven. This might be a problem with your classpath, you may try adding as the first line of your public static void main(String[]):
System.out.println(System.getProperty("java.class.path"));
to make sure you have sshj-0.9.0.jar in your classpath.

Related

An error occurs when using spark to retrieve elasticsearch data

I want to use spark to retrieve some data from elastic-search data catalogy and I use the offical document's method then wrong here...
This is my code (using Java and JDK 1.8_221):
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.elasticsearch.spark.rdd.api.java.JavaEsSpark;
import scala.Tuple2;
import java.util.Map;
public class Main {
public static void main(String[] args) {
SparkConf conf = new SparkConf();
conf.setMaster("local");
conf.setAppName("Spark ElasticSearch");
conf.set("es.index.auto.create", "true");
conf.set("es.nodes", "10.245.142.213");
conf.set("es.port", "9200");
JavaSparkContext sc = new JavaSparkContext(conf);
sc.setLogLevel("ERROR");
JavaPairRDD<String, Map<String, Object>> esRDD =
JavaEsSpark.esRDD(sc, "au_pkt_ams/au_pkt_ams");
for(Tuple2 tuple: esRDD.collect()){
System.out.print(tuple._1()+"-------------");
System.out.println(tuple._2());
}
}
}
And here is the error report(All logs):
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/Partition$class
at org.elasticsearch.spark.rdd.EsPartition.<init>(AbstractEsRDD.scala:84)
at org.elasticsearch.spark.rdd.AbstractEsRDD$$anonfun$getPartitions$1.apply(AbstractEsRDD.scala:49)
at org.elasticsearch.spark.rdd.AbstractEsRDD$$anonfun$getPartitions$1.apply(AbstractEsRDD.scala:48)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.collection.TraversableLike.map(TraversableLike.scala:237)
at scala.collection.TraversableLike.map$(TraversableLike.scala:230)
at scala.collection.immutable.List.map(List.scala:298)
at org.elasticsearch.spark.rdd.AbstractEsRDD.getPartitions(AbstractEsRDD.scala:48)
at org.apache.spark.rdd.RDD.$anonfun$partitions$2(RDD.scala:253)
at scala.Option.getOrElse(Option.scala:138)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:251)
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2126)
at org.apache.spark.rdd.RDD.$anonfun$collect$1(RDD.scala:945)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:363)
at org.apache.spark.rdd.RDD.collect(RDD.scala:944)
at org.apache.spark.api.java.JavaRDDLike.collect(JavaRDDLike.scala:361)
at org.apache.spark.api.java.JavaRDDLike.collect$(JavaRDDLike.scala:360)
at org.apache.spark.api.java.AbstractJavaRDDLike.collect(JavaRDDLike.scala:45)
at Main.main(Main.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.Partition$class
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)
... 22 more
Process finished with exit code 1
Log says esRDD.collect() is wrong, that they cannot get the file 'Partition.class' but the file is actully exists.
I had the same issue. I found that this was a scala version incompatibility between Spark and Elastic libraries. In my case Spark libraries are included with scala 2.12 but then I realised that elasticsearch-spark connector includes only scala 2.11.
I updated Spark libraries to scala 2.11 and also changed elasticsearch-hadoop to elasticsearch-spark-20_2.11. Here is the new pom.xml entries which works fine for me.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.11</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-spark-20_2.11</artifactId>
<version>7.4.2</version>
</dependency>

after packaging and running app I get java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver

When I try to run the code in IDEA I don't get this error, but after I package it and try to run the jar with
java -cp app.jar com.hive.connect.controller.RecordController
I get this exception.
java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
My maven
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
My code
public class RecordController {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName(driverName);
Connection con = DriverManager
.getConnection("jdbc:hive2://host:port/db;" +
"principal=principal");
Statement stmt = con.createStatement();
String tableName = "evkuzmin_testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
}
}
Why does this happen?
EDIT
Full error
Exception in thread "main" java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.hive.connect.controller.RecordController.main(RecordController.java:18)
Try like this:
"%JAVA_HOME%\bin\java.exe" -cp "%~dp0\hive-jdbc.jar;%~dp0\app.jar" com.hive.connect.controller.RecordController
instead of this:
java -cp app.jar com.hive.connect.controller.RecordController
The error is due to the non-availability of the Hive JDBC jar while trying to run your Java code (which inturn tries to load the Hive JDBC jar)
Hope this helps!
1-if you are using maven , you have to add this in pom.xml file
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>0.8.1</version>
</dependency>
2.Alternatively you can download above mentioned jar.
Place the jar in to hive/install location/of/lib directory...
This properly working always.

NoClassDefFoundError: org/apache/commons/lang3/StringUtils

I'm trying to run the sample project with this library and I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/lang3/StringUtils
at com.github.devnied.emvnfccard.enums.EmvCardScheme.<init>(EmvCardScheme.java:97)
at com.github.devnied.emvnfccard.enums.EmvCardScheme.<clinit>(EmvCardScheme.java:32)
at com.github.devnied.emvnfccard.parser.EmvParser.readWithAID(EmvParser.java:277)
at com.github.devnied.emvnfccard.parser.EmvParser.readEmvCard(EmvParser.java:120)
at com.github.devnied.emvpcsccard.Main.main(Main.java:64)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
I've added commons-lang-2.6.jar & commons-lang3-3.1-sources.jar in libs and classpath
Main class:
public static void main(final String[] args) throws CardException {
Main pcsc = new Main();
CardTerminal ct = pcsc.selectCardTerminal();
Card c = null;
if (ct != null) {
c = pcsc.establishConnection(ct);
CardChannel channel = c.getBasicChannel();
PcscProvider provider = new PcscProvider(channel);
EmvParser parser = new EmvParser(provider, false);
parser.readEmvCard();
c.disconnect(false);
}
}
I have referred to the following links:
java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils from BaseClassLoader
Struts 2 framework demo
http://apache-commons.680414.n4.nabble.com/lang-java-lang-NoClassDefFoundError-org-apache-commons-lang-StringUtils-Exception-td3735881.html
I have added commons-lang-2.6.jar & commons-lang3-3.1-sources.jar...
Here's your problem: commons-lang-2.6.jar doesn't contain the org.apache.commons.lang3 package, since that's part of version 3, and commons-lang3-3.1-sources.jar contains the source code, not the byte code.
You need to include commons-lang3-3.1.jar instead.
If you're using Maven, put this inside your pom.xml file:
Maven Central Repository for Commons Lang:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Maven Central Repository for Apache Commons Lang:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12</version>
</dependency>
Don't forget: Update Maven Project
Apache Commons Lang ™ Dependency Information
Last Published: 2 March 2021 | Version: 3.12
Apache Maven
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12</version>
</dependency>
Apache Buildr
'org.apache.commons:commons-lang3:jar:3.12'
Apache Ivy
<dependency org="org.apache.commons" name="commons-lang3" rev="3.12">
<artifact name="commons-lang3" type="jar" />
</dependency>
Groovy Grape
#Grapes(
#Grab(group='org.apache.commons', module='commons-lang3', version='3.12')
)
Gradle/Grails
compile 'org.apache.commons:commons-lang3:3.12'
Scala SBT
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.12"
Leiningen
[org.apache.commons/commons-lang3 "3.12"]
Reference:
https://commons.apache.org/proper/commons-lang/dependency-info.html
Yo adding the below and update maven project worked like a charm:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
Adding below worked for me:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
When everything else is correct, rarely jar file gets corrupted. Ensure you don't see error something like below while compiling
[ERROR] error reading
C:\Users\Mohan\.m2\repository\org\apache\commons\commons-lang3\3.7\commons-lang3-3.7.jar;
ZipFile invalid LOC header (bad signature)
I was having this issue in IJ version 2016 after updating it to 2018.3.4 and clicking "Generate sources and update folders for all projects" at Maven options tab the issue went away

connection to Magento SOAP API java

i am trying to connect to the magento soap api in java, i have added almost all the jar files as per the error logs, but i am stuck at this run time exception, please have a look a look at the code and the output.
import com.google.code.magja.soap.MagentoSoapClient;
import com.google.code.magja.soap.SoapConfig;
import org.apache.axis2.AxisFault;
public class testConnection {
public static void main(String[] args) throws AxisFault {
String user = "XXXXXX";
String pass = "XXXXX";
String host = "http://XXX.co.in/magento/index.php/api/soap?wsdl";
SoapConfig soapConfig = new SoapConfig(user, pass, host);
MagentoSoapClient magentoSoapClient = MagentoSoapClient.getInstance(soapConfig);
// configure connection
magentoSoapClient.setConfig(soapConfig);
}
}
OUTPUT
Exception in thread "main" java.lang.RuntimeException: org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.http.CommonsHTTPTransportSender
at com.google.code.magja.soap.MagentoSoapClient.<init>(MagentoSoapClient.java:56)
at com.google.code.magja.soap.MagentoSoapClient.getInstance(MagentoSoapClient.java:79)
at magentomanager.testConnection.main(testConnection.java:14)
Caused by: org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.http.CommonsHTTPTransportSender
at org.apache.axis2.deployment.AxisConfigBuilder.processTransportSenders(AxisConfigBuilder.java:708)
at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:122)
at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:857)
at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)
at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:151)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:144)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:251)
at com.google.code.magja.soap.MagentoSoapClient.login(MagentoSoapClient.java:138)
at com.google.code.magja.soap.MagentoSoapClient.<init>(MagentoSoapClient.java:53)
... 2 more
Caused by: java.lang.ClassNotFoundException: org.apache.axis2.transport.http.CommonsHTTPTransportSender
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.apache.axis2.util.Loader.loadClass(Loader.java:261)
at org.apache.axis2.deployment.AxisConfigBuilder.processTransportSenders(AxisConfigBuilder.java:683)
Added JAR Files
I just ran into the same issue and added these dependencies to my maven pom
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
Hope this helps.

How to add attachment to an existing JIRA Issue using rest-client API

I could create a jira issue using the rest client API, but i wasn't able to attach the screeshot/attachment to the exsiting JIRA issue. Would be really helpful if anyone could provide a solution which would be really appreciated.
I just wrote the below code snippet for attaching a jpeg file to the existing JIRA Issue. But then i experienced "Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager"
Code Snippet :-
private static String addAttachment(String attachmentfilepath) throws URISyntaxException, FileNotFoundException{
final java.net.URI jiraServerUri = new java.net.URI("https://oliveits.atlassian.net");
FileInputStream fileStreamPath = new FileInputStream(attachmentfilenamepath);
JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
NullProgressMonitor pm = new NullProgressMonitor();
System.out.println("Server Url :"+jiraServerUri);
JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri,"mobileqa","MobileQA1234");
Issue issue1 = restClient.getIssueClient().getIssue(newKey, pm);
final java.net.URI AttachmentUri = new java.net.URI(jiraServerUri+"/rest/api/2/issue/"+newKey+"/attachments");
System.out.println("URI :"+issue1.getAttachmentsUri());
//restClient.getIssueClient().addAttachment(pm,issue1.getAttachmentsUri(), fileStreamPath , imageName);
restClient.getIssueClient().addAttachment(pm, AttachmentUri, fileStreamPath, imageName);
return attachmentfilepath;
}
Exception:-
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager
at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.create(JerseyJiraRestClientFactory.java:34)
at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.createWithBasicHttpAuthentication(JerseyJiraRestClientFactory.java:39)
at com.jtricks.JTricksRESTClient.addAttachment(JTricksRESTClient.java:157)
at com.jtricks.JTricksRESTClient.main(JTricksRESTClient.java:101)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpConnectionManager
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
Just added the missing jar files to the classpath. But I'm getting an exception as mentioned below.
Exception Msg-1: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class com.sun.jersey.multipart.MultiPart, and Java type class com.sun.jersey.multipart.MultiPart, and MIME media type multipart/form-data; boundary=Boundary_1_18541827_1358346116249 was not found
Exception Msg-2: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class com.sun.jersey.multipart.MultiPart, and Java type class com.sun.jersey.multipart.MultiPart, and MIME media type multipart/form-data; boundary=Boundary_1_18541827_1358346116249 was not found
You issue comes from inability to find org.apache.commons.httpclient.HttpConnectionManager class. Look for commons-httpclient JAR in your classpath.
You can try this :
String issueKey = "your-issue";
JiraRestClient restClient
= AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(
getJiraUri(),
username,
password);
Issue issue = restClient.getIssueClient().getIssue(issueKey).claim();
restClient.getIssueClient().addAttachments(issue.getAttachmentsUri(), file).claim();
restClient.close();
in the pom.xml
<properties>
<jira-rest-java-client-core.version>5.2.4</jira-rest-java-client-core.version>
<atlassian.fugue.version>5.0.0</atlassian.fugue.version>
</properties>
...
<dependencies>
...
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>${jira-rest-java-client-core.version}</version>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
<version>${jira-rest-java-client-core.version}</version>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>${atlassian.fugue.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

Categories

Resources