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.
Related
I have the following code:
public static final String _DRIVER_PATH = "c:\\Users\\Public\\Downloads\\chromedriver.exe";
.....
System.setProperty("webdriver.chrome.driver", Constants._DRIVER_PATH);
ChromeOptions options = new ChromeOptions();
My dependencies are:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
Then I get on the last line:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Lists
at org.openqa.selenium.chrome.ChromeOptions.<init>(ChromeOptions.java:74)
at com.FlashMain.main(FlashMain.java:39)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Lists
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
I run on Windows 10, ChromeDriver.exe version 2.29 and Chrome - 58.0.3029.110
You advise is appreciated.
It seems that you're using both selenium and other library that brings google common library with version that is not compatible with latest selenium.
Build dependency tree using:
mvn dependency:tree
Exclude old version by managing exclusions and add new one directly or simply try to update library that refers to old version of google common.
I encountered this recently using Selenium with Spring Boot, and the webdrivermanager maven plugin. The problem was that I used the latest webdrivermanager version, but relied on the selenium-java version provided by Spring Boot, which was a few versions back. If you find yourself in a similar scenario, the solution is quite easy, override the spring boot version for your Selenium dependency and make sure you are using consistent and appropriate versions!
Use Selenium version 2.x , Selenium 3.0 chromium implementation is different
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.
After 2 days of googling I am still unable to find the solution of my issue with Tess4j version 3.0: java.lang.UnsatisfiedLinkError: The specified module could not be found.
I write server side Spring boot app on my Windows 10 x64. I used this tutorial http://tess4j.sourceforge.net/tutorial/
I make ant test in tess4j project's source and this command works ok in my PC. I also have Visual C++ Redistributable for VS2012 and Visual C++ Redistributable for VS2013 installed.
But I have missed dlls in my PC, libtesseract304.dll depends on:
Can it be the reason of problem? But how it is possible, that Tess4J-3.0-src project works ok in my PC?
My full stack trace:
java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:263) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Library$Handler.<init>(Library.java:147) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:502) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:481) ~[jna.jar:4.2.1 (b0)]
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.init(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at ocr.OCRController.handleFileUpload(OCRController.java:109) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
My code:
ITesseract instance = new Tesseract(); // JNA Interface Mapping
instance.setDatapath(new File(datapath).getPath());
instance.setLanguage("eng");
try {
String result = instance.doOCR(imageFile); //error here
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
maven:
<dependency>
<groupId>jai_imageio</groupId>
<artifactId>com.jai_imageio</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jai_imageio.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-io-2.4</groupId>
<artifactId>com.commons-io-2.4</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-io-2.4.jar</systemPath>
</dependency>
<dependency>
<groupId>jna</groupId>
<artifactId>com.jna</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jna.jar</systemPath>
</dependency>
<dependency>
<groupId>tess4j-3.0</groupId>
<artifactId>com.tess4j-3.0</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/tess4j-3.0.jar</systemPath>
</dependency>
I also tried to load libs in force way:
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/gsdll64");
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/libtesseract304");
But without success:
There was an unexpected error (type=Internal Server Error, status=500).
C:\Users\Iuliia\IdeaProjects\ENumbersBackend\lib\win32-x86-64\libtesseract304.dll: Can't find dependent libraries
Thank you for any help!
I think you our misled by the output of depends.exe.
The DLL only imports these other dlls:
dumpbin libtesseract304.dll /imports|find ".dll"
Dump of file libtesseract304.dll
WS2_32.dll
liblept171.dll
MSVCP120.dll
MSVCR120.dll
KERNEL32.dll
To doublecheck you can get the linker version used to compile that dll:
dumpbin libtesseract304.dll /headers | find "linker version"
12.00 linker version
So all you need is the Visual Studio 2013 Runtime (again: don't be misled: 12.0 is 2013, which can be rather confusing)
Presumably the liblept171.dll is the thing that is missing, so you should check where it is stored and why the one project is able to find it and not the other. A good idea is to copy all dependencies into a common path and setting java.library.path to that directory (just for testing purposes)
liblept171.dll is part of lept4j, there is a accordingly named .jar in your lib directory which contains that dll:
7z l lib\lept4j-1.0.1.jar | find ".dll"
2015-11-14 11:46:04 ..... 2406400 2406400 win32-x86-64\liblept171.dll
2015-11-14 11:46:04 ..... 1834496 1834496 win32-x86\liblept171.dll
In addition you should take care that the bitness of your JRE, the Visual Studio Runtime and Tesseract do match. If in doubt: install x86 and x64.
As a further troubleshooting aid you might want to find out where the dll is being searched for. Use procmon.exe with a filter for that dll.
The problem is not connected with Windows 10.
I've already fix the error with adding
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.0.0</version>
</dependency>
instead all previous maven dependencies.
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
When I am using Elastic Search, my module compiles and runs properly.
In my pom.xml, I have included the following dependency,
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.5</version>
</dependency>
But I needed to do some changes(implement a timer in one of the methods of ES), so I forked the code, made a jar and saved it in my local repository:-
mvn install:install-file -Dfile=/Users/Mike/Desktop/MyElastic/elasticsearch/target/elasticsearch-1.4.6-SNAPSHOT.jar -DgroupId=org.elasticsearch -DartifactId=elasticsearch -Dversion=1.4.6-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
Now I am trying to use this locally saved repository instead of the remote repository.
So I made the following changes to my pom.xml
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.6-SNAPSHOT</version>
</dependency>
But now when I compile my module, some strange error is being thrown :-
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/lucene/util/Version at
org.elasticsearch.Version.(Version.java:44) at
org.elasticsearch.node.internal.InternalNode.(InternalNode.java:137)
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:159) at
org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:166) at
mike.practice.ES.PracticeES3.(PracticeES3.java:55) at
mike.practice.ES.PracticeES3.main(PracticeES3.java:177) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassNotFoundException:
org.apache.lucene.util.Version at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 11 more
Process finished with exit code 1
What could have been the possible error? Is it that my local repository is not being properly mapped. Or probably some issue with the version ?( was using 1.4.5 earlier but when I forked and reverted to 1.4, automatically 1.4.6 was selected)
It would be really helpful if somebody could help me find out what the real issue is and how to correct it.