I am attempting to run this code:
public class ExcelSimpleTest {
public static void main(String[] args) throws Exception {
File f = new File("C:\\Users\\yaron\\Desktop\\Test.xlsx");
FileInputStream fis = new FileInputStream(f);
XSSFWorkbook wb=new XSSFWorkbook(fis);
Sheet sheet=wb.getSheetAt(0);
System.out.println(sheet.getRow(0).getCell(0).getStringCellValue());
}
}
And am getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
at src.ExcelSimpleTest.main(ExcelSimpleTest.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
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)
... 1 more
I checked on the internet and copied over the Apache POI files and don't understand what my problem is.
It Looks like you miss the commons-collection4.jar in your classpath. Download it and add it to your classpath. If you use maven you can add
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
to your pom.
If not you can download it here
Related
I am using JXLS Java library to generate excel reports. I am trying to run the sample getting started tutorial (Object collection output demo). As suggested in the tutorial I am using maven to specify the required libraries in my project build configuration file. Below is the java code used
List<Employee> employees = generateSampleEmployeeData();
try(InputStream is = ObjectCollectionDemo.class.getResourceAsStream("object_collection_template1.xls")) {
try(OutputStream os = new FileOutputStream("target/" + fileName)) {
Context context = new Context();
context.putVar("employees", employees);
JxlsHelper.getInstance().processTemplate(is, os, context);
}
}
When i run the program in my eclipse i get the below exception:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/openxml4j/exceptions/InvalidFormatException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at org.jxls.util.TransformerFactory.createTransformer(TransformerFactory.java:34)
at org.jxls.util.JxlsHelper.createTransformer(JxlsHelper.java:217)
at org.jxls.util.JxlsHelper.processTemplate(JxlsHelper.java:104)
at com.ucas.ObjectCollectionDemo.main(ObjectCollectionDemo.java:42)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.openxml4j.exceptions.InvalidFormatException
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)
... 9 more
Below is a snapshot of the maven dependencies
Java Version: 1.8
Environment: Windows 7
IDE: Eclipse Neon
It looks like you have an issue with some XML dependencies required for Apache POI processing.
I can see them in your dependencies screenshot however for some reason they are not in effect when you are running your program. May be there is some conflict between the dependencies.
Try to create a minimal jxls project by just adding only the following two dependencies and see if it works
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
<version>1.0.12</version>
</dependency>
Then you can add your own dependencies one by one and see at which point it breaks.
Not seeing very much in the way of code in your question, so I'll be shooting blanks here. It almost looks like you have a version mismatch with the file object_collection_template1.xls being created with a different version of Excel than JXLS is compatible with, at least as its written.
I´m trying to crawl a dynamic Webpage with Serritor but there is a Problem:
This is my Code:
public class MyCrawler extends BaseCrawler {
public MyCrawler() {
String pathToDriver = ".//ChromeDriver//chromedriver.exe";
System.setProperty("webdriver.chrome.driver", pathToDriver);
config.setWebDriver(new ChromeDriver());
config.setFilterOffsiteRequests(true);
config.addSeedAsString("http://yourspecificsite.com");
config.setCrawlingStrategy(CrawlingStrategy.DEPTH_FIRST);
config.setDelayBetweenRequests(Duration.ofSeconds(1));
}
}
And this the return:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver
at com.github.peterbencze.serritor.internal.CrawlerConfiguration.<init>(CrawlerConfiguration.java:47)
at com.github.peterbencze.serritor.api.BaseCrawler.<init>(BaseCrawler.java:68)
at serritor_versuch2.MyCrawler.<init>(MyCrawler.java:21)
at serritor_versuch2.run.main(run.java:5)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.htmlunit.HtmlUnitDriver
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
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver
Above exception clearly states that HtmlUnitDriver class is not found. If you are using maven, you should probably add maven dependency in your pom.xml file.
Not sure, which version are you using but here is the latest version.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
If you are using gradle or any other dependency management tool, look accordingly from: Maven Repository
If you are not using any dependency management tool, you should download the jar file and put it in your classpath.
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.
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.
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>