I have a project which uses a TWAIN library in a jar file for purposes of scanning. I have successfully managed to use this library while running my project in Eclipse IDE. As you can see in this picture, it detects my list of installed devices as i expected.
But when i export my project into a Runnable JAR File and choose to 'Package required libraries into generated JAR', it suddenly stops scanning and when i check the same list of devices, it is blank like this .
Considering that the first time i tried to export my project i needed to configure my resources folder so it could load pictures from inside the JAR, i believe this is a similar problem. Yet, i don't know exactly why, because in both cases it returns the following message that indicates that the TWAIN library was loaded.
JarLib.load: Successfully loaded library[jar:rsrc:uk.co.mmscomputing.device.twain.jar!/uk/co/mmscomputing/device/twain/win64/jtwain.dll] from jar file location
But when i try to scan, this is what i get:
uk.co.mmscomputing.device.twain.TwainIOException: uk.co.mmscomputing.device.twain.TwainSource.select(String name)
Cannot find twain data source: 'Lenovo EasyCamera'
at uk.co.mmscomputing.device.twain.TwainSource.select(TwainSource.java:239)
at uk.co.mmscomputing.device.twain.TwainSourceManager.selectSource(TwainSourceManager.java:82)
at uk.co.mmscomputing.device.twain.jtwain.cbexecute(jtwain.java:231)
at uk.co.mmscomputing.device.twain.jtwain.nstart(Native Method)
at uk.co.mmscomputing.device.twain.jtwain.access$200(jtwain.java:12)
at uk.co.mmscomputing.device.twain.jtwain$1.run(jtwain.java:338)uk.co.mmscomputing.device.twain.TwainFailureException: Failed during call to twain source.
cc=No Data Source
rc=1
at uk.co.mmscomputing.device.twain.TwainSourceManager.call(TwainSourceManager.java:27)
at uk.co.mmscomputing.device.twain.TwainIdentity.open(TwainIdentity.java:70)
at uk.co.mmscomputing.device.twain.TwainSource.open(TwainSource.java:99)
at uk.co.mmscomputing.device.twain.TwainSourceManager.openSource(TwainSourceManager.java:93)
at uk.co.mmscomputing.device.twain.jtwain.cbexecute(jtwain.java:234)
at uk.co.mmscomputing.device.twain.jtwain.nstart(Native Method)
at uk.co.mmscomputing.device.twain.jtwain.access$200(jtwain.java:12)
at uk.co.mmscomputing.device.twain.jtwain$1.run(jtwain.java:338)
Is it possible that when i'm building my project into a JAR, it's still missing some dll or file that needs to be packaged?
I discovered the problem. It looks like when i was executing my .jar file through Eclipse, it was actually using the 32bit JVM that i had installed, and that way, it was able to retrieve my list of DataSources that were installed using a 32 bit driver.
But as i am using a 64bit machine, when i double-click the .jar file that has been generated, it would run a 64bit JVM that's installed on my computer. So, i just had to change the JVM version that it's using, by executing my .jar file via cmd
and through this command:
java -jar ScannerTest.jar -d32
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.