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.
Related
i am new to maven, after running Maven with mvn clean package command.
it compiles the project into an executable jar.
i run the jar in the terminal and got this error:
$ java -jar create_pass_criteria-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/mprv/automation/core/exceptions/AutomationException
at Create_pass_criteria.Main.main(Main.java:23)
Caused by: java.lang.ClassNotFoundException: com.mprv.automation.core.exceptions.AutomationException
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 have a lot of jars that i use in my code by importing them.
how can i make the jar also include those jars?
is this what this error means?
appreciate any help,
thank you
Try it
Just add all the required libraries to the classpath when using java -jar target/PriseDeNotes-0.0.1-SNAPSHOT.jar with the --classpath argument.
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 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
I was able to create an executable using launch4j and it works fine on my machine. When I send it to someone to run on their windows machine they get the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: spark/TemplateEngine
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 sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: spark.TemplateEngine
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)
... 7 more
Any thoughts?
This exception may also occur if your maven dependencies do not have <scope> set to compile time (default) and dependency jars are not available at compile time. For instance if maven dependencies have <scope>provided</scope> in your pom.xml compiler will assume that the JRE/environment will provide these dependency jars but when the sources are compiled and these dependencies are not found, this exception will be thrown.
For example - below may lead to this exception if spark-mllib_2.11 dependency is not found during compile time although they are added and there is no error during editing;
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
I had this problem because my version of java that was as default was 9, and somehow Spark didn't recognize it. So I changed to version 8 and it worked. To change in linux :
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
In your case you may want another version, so choose yours (to list the versions you have in your computer use the -l option).
Had to set relative paths in the class path so the executable could locate the jar files
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>