在Eclipse 中调用 Hibern8IDE,同时解决中文问题
在Eclipse 中调用 Hibern8IDE,同时解决中文问题- -
系统环境:
hibernate 2.1
hibernate-extensions-2.1.2
Eclipse 3.0
Oracle 8.1.7
第一步
配置好你的 hibernate.cfg.xml 和你所有的 *.hbm.xml文件
将JDBC Driver 导入Libraries.
将Hibern8IDE\lib 下的*.jar包导入Libraries
将hibernate2.jar 和相关的包导入 Libraries
第二步
在你的工程中创建一个 StartHibern8IDE.java 文件,用于启动Hibern8IDE
看下列 java 代码
import java.awt.Font; import javax.swing.UIManager; import com.jgoodies.clearlook.ClearLookManager;
import net.sf.hibern8ide.AWTExceptionHandler;
public class StartHibern8IDE { public static void main(String[] args) throws Exception {
try {
Hibern8IDE.startWith(configuration);
public static void setUIFont (javax.swing.plaf.FontUIResource f){
|
以前也是用ant run 直接调用Hibern8IDE,当初始化,和apply 的时候总是找不到*.hbm.xml或者其他文件和包.
而且还存在着中文字符的问题.
使用这种方式可以直接 传送 net.sf.hibernate.cfg.Configuration 实例,启动Hibern8IDE,所以不需要再配置Mapping files,classpath
等文件了.
================================
参考:
Hibern8IDE中文问题的解决 http://forum.javaeye.com/viewtopic.php?t=5830&highlight=hibern8ide
===================================================
如果您想引用我的文章请您保留以下信息.
本人才疏学浅,文章必有不少的bugs,欢迎您来指正,我好做及时的调整,感谢!!!!
作者:小米Eugene
Blog http://deve.blogdriver.com
Email:javapattern(at)126.com
笨笨备注:
最新版本的这个工具叫做HibernateConsole,代码可以这么写,不过经过这么设置的HibernateConsole失去了界面对分辨率的适应能力:
package amao.helper;
import java.awt.Font;
import javax.swing.UIManager;
import com.jgoodies.clearlook.ClearLookManager;
import com.jgoodies.clearlook.ClearLookMode;
import com.jgoodies.plaf.plastic.PlasticXPLookAndFeel;
import net.sf.hibernate.console.AWTExceptionHandler;
import net.sf.hibernate.console.Start;
import net.sf.hibernate.cfg.Configuration;
/**
* @author wyn
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class StartHibernateConsole {
public static void main(String[] args) throws Exception {
//Configuration configuration = new Configuration();
try {
if (System.getProperty("sun.awt.exception.handler") == null) {
System.setProperty("sun.awt.exception.handler",
AWTExceptionHandler.class.getName());
} else {
System.err.println("could not install AWT handler ;(");
}
ClearLookManager.setMode(ClearLookMode.ON);
UIManager.setLookAndFeel(new PlasticXPLookAndFeel());
setUIFont(new javax.swing.plaf.FontUIResource("宋体", Font.BOLD, 12));
//以上设置是为了解决中文问题
//启动Hibern8IDE
//configuration.configure();
//Start.startWith(configuration);
Start.main(null);
} catch (Exception e) { // noop
e.printStackTrace();
}
}
public static void setUIFont(javax.swing.plaf.FontUIResource f) {
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource)
UIManager.put(key, f);
}
}
}