静态报表系统需要将excel转换成html,在利用jacob.jar提供的com组件实现时进行调试代码,在工程中导入jacob.jar后编译运行,意外发生:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.jacob.com.Dispatch.createInstanceNative
(Ljava/lang/String;)V
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:161)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:54)
at myfile.OfficeToXML.PPttoHtml(OfficeToXML.java:50)
at myfile.OfficeToXML.main(OfficeToXML.java:111)
脑子蒙了,第一次遇到这个异常而不知所云。搜索百度后,找到可参考的解决办法:
1) 把jacob.dll在 C:\Program Files\Java\jdk1.5.0_08\bin、C:\Program Files\Java\jdk1.5.0_08\jre\bin、C:\WINDOWS\system32 目录下各放一份
2) 把jacob.jar放入 项目的lib包下,并且在“java构建路径”中也要加载此jar包。
这也让我意识到如果用这种方式来将excel转换成html需要调用本地的DLL文件而存在平台相关性的问题,同样的实现若在linux系统下那就玩完了。按照上面的方法搜索下载匹配的版本jar后添加编译运行,上面的异常消失了。在内心突然对提示我的朋友产生崇敬感的同时,也有种莫名伤感。
控制台又出现下面的非常诡异的提示信息:
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x76ea4605, pid=7908, tid=7912
#
# Java VM: Java HotSpot(TM) Client VM (11.0-b15 mixed mode, sharing windows-x86)
# Problematic frame:
# C [ntdll.dll+0x34605]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
差点没吐血,于是打开日志文件一看,天书啊。。。上帝,日志如下:
--------------- T H R E A D ---------------
Current thread (0x01259000): JavaThread "main" [_thread_in_native, id=7912, stack(0x00390000,0x003e0000)]
siginfo: ExceptionCode=0xc0000005, writing address 0x04290000
Registers:
EAX=0x00000000, EBX=0x003df174, ECX=0x00000001, EDX=0x00000000
ESP=0x003deff4, EBP=0x003df028, ESI=0x76fcb20c, EDI=0x04290000
EIP=0x76ea4605, EFLAGS=0x00010202
Top of Stack: (sp=0x003deff4)
0x003deff4: 003df070 75d7321c 04290000 00000000
0x003df004: 00000004 00000001 76fc6840 002c539c
0x003df014: 00000000 76fc6892 00000000 00000007
0x003df024: 476cf044 003df444 75de56cf 003df170
0x003df034: 13e7509d 00000000 003df768 00000000
0x003df044: 00000000 01a6d098 003df060 754df14c
0x003df054: 00000006 00000000 00000000 003df0a8
0x003df064: 7c34218a 01250000 00000000 003df044
Instructions: (pc=0x76ea4605)
0x76ea45f5: c8 c1 e0 10 03 c1 8b ca 83 e2 03 c1 e9 02 74 06
0x76ea4605: f3 ab 85 d2 74 0a 88 07 83 c7 01 83 ea 01 75 f6
Stack: [0x00390000,0x003e0000], sp=0x003deff4, free space=315k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ntdll.dll+0x34605]
C [RPCRT4.dll+0x956cf]
C [OLEAUT32.dll+0x342b3]
C [OLEAUT32.dll+0x34280]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.jacob.com.Dispatch.invokev(Ljava/lang/Object;Ljava/lang/String;III[Lcom/jacob/com/Variant;[I)Lcom/jacob/com/Variant;+0
j com.jacob.activeX.ActiveXComponent.getProperty(Ljava/lang/String;)Lcom/jacob/com/Variant;+39
j OfficeToXML.PPttoHtml(Ljava/lang/String;Ljava/lang/String;)Z+25
j OfficeToXML.main([Ljava/lang/String;)V+9
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x01a6cc00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=7652, stack(0x03d30000,0x03d80000)]
0x01a5d800 JavaThread "CompilerThread0" daemon [_thread_blocked, id=7548, stack(0x03ce0000,0x03d30000)]
0x01a5b000 JavaThread "Attach Listener" daemon [_thread_blocked, id=8008, stack(0x03c90000,0x03ce0000)]
0x01a58400 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=8004, stack(0x03c40000,0x03c90000)]
0x01a12000 JavaThread "Finalizer" daemon [_thread_blocked, id=8000, stack(0x03bf0000,0x03c40000)]
0x01a10c00 JavaThread "Reference Handler" daemon [_thread_blocked, id=7856, stack(0x03ba0000,0x03bf0000)]
=>0x01259000 JavaThread "main" [_thread_in_native, id=7912, stack(0x00390000,0x003e0000)]
Other Threads:
0x01a0f000 VMThread [stack: 0x03b50000,0x03ba0000] [id=7896]
0x01a6dc00 WatcherThread [stack: 0x03d80000,0x03dd0000] [id=7164]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 960K, used 485K [0x23bf0000, 0x23cf0000, 0x240d0000)
eden space 896K, 54% used [0x23bf0000, 0x23c69740, 0x23cd0000)
from space 64K, 0% used [0x23cd0000, 0x23cd0000, 0x23ce0000)
to space 64K, 0% used [0x23ce0000, 0x23ce0000, 0x23cf0000)
tenured generation total 4096K, used 0K [0x240d0000, 0x244d0000, 0x27bf0000)
the space 4096K, 0% used [0x240d0000, 0x240d0000, 0x240d0200, 0x244d0000)
compacting perm gen total 12288K, used 431K [0x27bf0000, 0x287f0000, 0x2bbf0000)
the space 12288K, 3% used [0x27bf0000, 0x27c5bdf8, 0x27c5be00, 0x287f0000)
ro space 8192K, 67% used [0x2bbf0000, 0x2c152f30, 0x2c153000, 0x2c3f0000)
rw space 12288K, 53% used [0x2c3f0000, 0x2ca60180, 0x2ca60200, 0x2cff0000)
Dynamic libraries:
0x00400000 - 0x00424000 F:\Java\jdk1.6.0_10\bin\javaw.exe
0x76e70000 - 0x76fad000 C:\Windows\SYSTEM32\ntdll.dll
0x75490000 - 0x75564000 C:\Windows\system32\kernel32.dll
0x75210000 - 0x7525a000 C:\Windows\system32\KERNELBASE.dll
0x76af0000 - 0x76b90000 C:\Windows\system32\ADVAPI32.dll
0x753e0000 - 0x7548c000 C:\Windows\system32\msvcrt.dll
0x75d30000 - 0x75d49000 C:\Windows\SYSTEM32\sechost.dll
0x75d50000 - 0x75df1000 C:\Windows\system32\RPCRT4.dll
0x75a10000 - 0x75ad9000 C:\Windows\system32\USER32.dll
0x77050000 - 0x7709e000 C:\Windows\system32\GDI32.dll
0x76fb0000 - 0x76fba000 C:\Windows\system32\LPK.dll
0x75e00000 - 0x75e9d000 C:\Windows\system32\USP10.dll
0x75580000 - 0x7559f000 C:\Windows\system32\IMM32.DLL
0x755a0000 - 0x7566c000 C:\Windows\system32\MSCTF.dll
0x7c340000 - 0x7c396000 F:\Java\jdk1.6.0_10\jre\bin\msvcr71.dll
0x6d8b0000 - 0x6db06000 F:\Java\jdk1.6.0_10\jre\bin\client\jvm.dll
0x73340000 - 0x73372000 C:\Windows\system32\WINMM.dll
0x74f40000 - 0x74f8b000 C:\Windows\system32\apphelp.dll
0x6d330000 - 0x6d338000 F:\Java\jdk1.6.0_10\jre\bin\hpi.dll
0x75570000 - 0x75575000 C:\Windows\system32\PSAPI.DLL
0x6d860000 - 0x6d86c000 F:\Java\jdk1.6.0_10\jre\bin\verify.dll
0x6d3d0000 - 0x6d3ef000 F:\Java\jdk1.6.0_10\jre\bin\java.dll
0x6d8a0000 - 0x6d8af000 F:\Java\jdk1.6.0_10\jre\bin\zip.dll
0x10000000 - 0x10018000 F:\Java\jdk1.6.0_10\jre\bin\jacob.dll
0x76fc0000 - 0x7704f000 C:\Windows\system32\OLEAUT32.dll
0x75bd0000 - 0x75d2c000 C:\Windows\system32\ole32.dll
0x74f90000 - 0x74f9c000 C:\Windows\system32\CRYPTBASE.dll
0x739a0000 - 0x739e0000 C:\Windows\system32\uxtheme.dll
0x04000000 - 0x04065000 C:\Program Files\360\360Safe\safemon\safemon.dll
0x75ea0000 - 0x76ae9000 C:\Windows\system32\SHELL32.dll
0x75b70000 - 0x75bc7000 C:\Windows\system32\SHLWAPI.dll
0x04070000 - 0x040d6000 C:\Windows\system32\MSVCP60.dll
0x758f0000 - 0x75a0a000 C:\Windows\system32\WININET.dll
0x758e0000 - 0x758e3000 C:\Windows\system32\Normaliz.dll
0x76b90000 - 0x76d48000 C:\Windows\system32\iertutil.dll
0x76d60000 - 0x76e70000 C:\Windows\system32\urlmon.dll
0x753a0000 - 0x753d5000 C:\Windows\system32\WS2_32.dll
0x76d50000 - 0x76d56000 C:\Windows\system32\NSI.dll
0x74340000 - 0x74349000 C:\Windows\system32\VERSION.dll
0x75ae0000 - 0x75b63000 C:\Windows\system32\CLBCatQ.DLL
0x74ac0000 - 0x74ad6000 C:\Windows\system32\CRYPTSP.dll
0x74860000 - 0x7489b000 C:\Windows\system32\rsaenh.dll
0x75000000 - 0x7500e000 C:\Windows\system32\RpcRtRemote.dll
VM Arguments:
jvm_args: -Dfile.encoding=GBK
java_command: OfficeToXML
Launcher Type: SUN_STANDARD
Environment Variables:
JAVA_HOME=F:\Java\jdk1.6.0_10
CLASSPATH=.;F:\Java\jdk1.6.0_10\jre\lib\rt.jar;F:\Java\jdk1.6.0_10\lib\tools.jar
PATH=F:/Java/jdk1.6.0_10/bin/../jre/bin/client;F:/Java/jdk1.6.0_10/bin/../jre/bin;F:\Oracle\product\11.2.0\dbhome_1\bin;F:\Java\jdk1.6.0_10\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Services\IPT\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;F:\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\IDM Computer Solutions\UltraEdit\
USERNAME=pangmc
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 42 Stepping 7, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows NT 6.1 Build 7600
CPU:total 4 (8 cores per cpu, 2 threads per core) family 6 model 10 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, ht
Memory: 4k page, physical 1975536k(557872k free), swap 3951072k(2307424k free)
vm_info: Java HotSpot(TM) Client VM (11.0-b15) for windows-x86 JRE (1.6.0_10-rc2-b32), built on Sep 12 2008 00:52:11 by "java_re" with MS VC++ 7.1
time: Sat Sep 24 15:49:13 2011
elapsed time: 0 seconds
于是继续在网上搜索寻找帮助,偶然一个朋友的文章中对上面的类似问题提出可能还是jacob与jdk的版本不一致,最后下载了一个最新的版本jacob_1.9.1更新之后,完美了!程序调试通过。对上面的日志文件内容不是很明白,即使问题解决了,还是很伤感!
前车之鉴:做以上转换程序,使用jacob时请保证jacob与JDK的版本统一,切忌!
在编程中需找快乐,在快乐中自由编程!