单元测试出错Native library for Attach API not available in this JRE
来源:互联网 发布:宁波知乎 编辑:程序博客网 时间:2024/05/17 22:49
转自:
http://blog.csdn.net/gold_fly/article/details/7732413
http://techiedan.com/2009/10/19/set-up-jdk-in-eclipse/
偶然一天,运行eclipse单元测试,报错:
- java.lang.IllegalStateException: Native library for Attach API not available in this JRE
- at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:81)
- at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
- at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
- at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:208)
- java.lang.IllegalStateException: Native library for Attach API not available in this JRE
- at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:81)
- at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
- at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
- at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:208)
检查了下,发现由于最近jmockit升级,导致eclipse的参数出了问题影响的。进入eclipse-->preference-->TestNG-->Run/Debug,这里有个设置运行时JVM args,把jmockit.jar设置下,格式为:-javaagent:D:\repository\com\alibaba\external\test.jmockit\0.999.11\test.jmockit-0.999.11.jar。
重新跑单元测试,运行正常!问题解决;
这个出错有点奇怪,通过出错类,进行跟踪,发现最后的出错信息如下:
- Class JDK6AgentLoader{
- private VirtualMachine attachToThisVM()
- {
- try {
- return VirtualMachine.attach(pid);
- }
- catch (AttachNotSupportedException e) {
- throw new RuntimeException(e);
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- private VirtualMachine getVirtualMachineImplementationFromEmbeddedOnes()
- {
- try {
- if (File.separatorChar == '\\') {
- return new WindowsVirtualMachine(ATTACH_PROVIDER, pid);
- }
- else {
- return new LinuxVirtualMachine(ATTACH_PROVIDER, pid);
- }
- }
- catch (AttachNotSupportedException e) {
- throw new RuntimeException(e);
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- catch (UnsatisfiedLinkError e) {
- throw new IllegalStateException("Native library for Attach API not available in this JRE", e);
- }
- }
通过文件路径判断是windwo,还是linux操作系统,从代码看catch并抛出异常的处理很常见;
- WindowsVirtualMachine{
- static
- /* */ {
- /* 167 */ System.loadLibrary("attach");
- /* 168 */ init();
- /* 169 */ stub = generateStub();
- /* */ }
- }
jmockit里面用到了jdk6.0的不少特性,jdk6.0的动态修改和装载还是挺强大的。
【yasi】遇到相同的问题,是这样解决的:
参考这篇帖子,将工程的Library中的 JRE7 换成 JDK 1.7,如图
0 0
- 单元测试出错Native library for Attach API not available in this JRE
- 单元测试出错Native library for Attach API not available in this JRE
- jMock出错java.lang.IllegalStateException: Native library for Attach API not available in this JRE的解决方
- eclipse run提示错误解决办法: Native library for Attach API not available in this JRE
- Native library for Attach API not available in this JRE解决
- Subversion Native Library Not Available
- Subversion Native Library Not Available
- eclipse subversion native library not available
- 【转】Subversion Native Library Not Available
- Subversion Native Library Not Available 解决异常
- Subversion Native Library not available 解决办法
- eclipse总弹框Subversion Native Library Not Available
- Subversion Native Library Not Available & Incompatible JavaHL library loaded
- Subversion Native Library Not Available & Incompatible JavaHL library loaded
- Extended information for this URL is not available in HttpWatch Basic Edition 的解决方案
- eclipse 异常 Subversion Native Library Not Available解决方案
- eclipse下svn报Subversion Native Library Not Available解决方案
- eclipse 异常 Subversion Native Library Not Available解决方案
- 初学linux 常用指令
- html中的js调用c#的winform程序
- 精通安卓性能优化(Pro Android Apps Performance Optimization)-前言
- 数据,数据类型,数据运算符
- QUERY_REWRITE_ENABLED
- 单元测试出错Native library for Attach API not available in this JRE
- Database ERROR:Table 'snort.acid_ag' doesn't exist
- WebBrowser 打印 总结
- Selenium介绍及原理解析
- Java第二课之从键盘上键入一个数
- Python<10>文件基础
- 重要经验五:block作为属性的注意事项
- 学习C/C++语言:用数组处理Fibonacci数列
- centos 6.2安装ar8152网卡驱动