卡了一下午仍没找到问题所在

最近定制swt内嵌的Browser来抓数据,工作基本完成。到了最后,一个问题却卡了一下午没有头绪。

当把整个工程部署在Tomcat下跑,结果却出现异常:

写道
org.eclipse.swt.SWTError: Unable to load library (java.io.FileNotFound
Exception: GRE not found)

 这是XULRunner找不到所发出的异常。

但是我的xulrunner放在c:\xulrunner下,并且已经注册成功,在Eclipse工程下跑生成的script通过。

于是使用WTP来Debug我的Web工程,Debug过程居然xulrunner找到,并且运行正常。

于是再一次启动tomcat,把Debug的时候部署的工程跑一下,结果还是失败。

但在Eclipse下的Sever来启动tomcat,居然运行正常。

于是写了一段程序看是否能够得到xulrunner的path:

 

import java.io.File;
import java.io.FileNotFoundException;

import org.mozilla.xpcom.GREVersionRange;
import org.mozilla.xpcom.Mozilla;

public class XulRunnerTest {
	public static void main(String[] args) {
		GREVersionRange[] range = new GREVersionRange[1];
		range[0] = new GREVersionRange("1.7.*", false, "1.8.*", true);
		try {
			File grePath = Mozilla.getGREPathWithProperties(range, null);
			System.out.println(grePath);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}
 

 结果成功得到xulrunner的path:c:\xulrunner

于是在Servlet初始化的时候把这段代码放过去,看是在不用Eclipse下面的Server启动Tomcat是否能成功:

public void init() throws ServletException { 
		super.init();
		GREVersionRange[] range = new GREVersionRange[1];
		range[0] = new GREVersionRange("1.7.*", false, "1.8.*", true);
		try {
			File grePath = Mozilla.getGREPathWithProperties(range, null);
			logger.debug(grePath);
		} catch (FileNotFoundException e) {
			logger.debug(e.getMessage());
		}
	}

 结果log中得到输出:GRE not found.

难道是用Eclipse下面的Server启动Tomcat和正常启动tomcat环境变量不同所致?但又是哪些变量导致的?

 

最后在SWT FAQ找到:

写道
Q: Can I specify which XULRunner installation gets used?
A: Typically a Mozilla-based Browser uses XULRunner's lookup mechanism to find a registered XULRunner at runtime. If you wish to override this mechanism you can set the value of java system property org.eclipse.swt.browser.XULRunnerPath to point at the target XULRunner's path. This property must be set before the first Browser instance is created.

 在init方法中加上:

System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "C:\\xulrunner");

 结果没有任何效果, log仍然输出:GRE not found.

最后只能到博客发泄一下。。。

你可能感兴趣的:(eclipse,tomcat,C++,c,OS)