Eclipse下配置和使用Hibernate Tools

合集下载

Eclipse IDE开发环境使用教程说明书

Eclipse IDE开发环境使用教程说明书

iAbout the T utorialEclipse is an integrated development environment (IDE) for Java and other programming languages like C, C++, PHP, and Ruby etc. Development environment provided by Eclipse includes the Eclipse Java development tools (JDT) for Java, Eclipse CDT for C/C++, and Eclipse PDT for PHP, among others.This tutorial will teach you how to use Eclipse in your day-2-day life while developing any software project using Eclipse IDE. We will give special emphasis on Java project. AudienceThis tutorial has been prepared for beginners to help them understand basic functionality of Eclipse tool. After completing this tutorial, you will find yourself at a moderate level of expertise in using Eclipse IDE from where you can take yourself to next levels. PrerequisitesWe assume you are going to use Eclipse IDE to handle all levels of Java projects development. So it will be good if you have knowledge of software development using any programming language specially Java programming.Copyright & Disclaimer© Copyright 2015 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book can retain a copy for future reference but commercial use of this data is not allowed. Distribution or republishing any content or a part of the content of this e-book in any manner is also not allowed without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or inthistutorial,******************************************iT able of ContentsAbout the Tutorial (i)Audience (i)Prerequisites (i)Copyright & Disclaimer (i)Table of Contents .................................................................................................................................... i i 1.OVERVIEW (1)What is Eclipse? (1)Licensing (1)Eclipse Releases (1)2.INSTALLATION (3)Downloading Eclipse (3)Installing Eclipse (3)Launching Eclipse (4)3.EXPLORE WINDOWS (5)Parts of an Eclipse Window (5)Using Multiple Windows (6)4.EXPLORE MENUS (7)Typical Eclipse Menus (7)Brief Description of Menus (8)Customizing Menus (8)5.EXPLORE VIEWS (9)About Views (9)Organizing Views (9)Moving Views (9)Creating View Folders (10)Opening a view (10)6.PERSPECTIVES (13)What is a Perspective? (13)Opening a Perspective (13)Switching between Perspectives (13)Closing a Perspective (14)Customizing a Perspective (14)7.WORKSPACES (16)About Eclipse Workspace (16)UI Elements for Managing the Workspace (16)8.CREATE JAVA PROJECT (18)Opening the New Java Project wizard (18)Using the New Java Project wizard (18)Viewing the Newly Created Project (20)9.CREATE JAVA PACKAGE (21)Opening the New Java Package wizard (21)Using the New Java Package Wizard (21)Viewing the Newly Created Package (22)10.CREATE JAVA CLASS (23)Opening the New Java Class Wizard (23)Using the New Java Class Wizard (23)Viewing the Newly Created Java class (24)11.CREATE JAVA INTERFACE (25)Opening the New Java Interface Wizard (25)Using the New Java Interface Wizard (25)Viewing the Newly Created Java Interface (26)12.CREATE XML FILE (27)Opening the New XML File wizard (27)Using the New XML File wizard (28)Viewing the Newly Created XML File (29)13.JAVA BUILD PATH (30)Setting the Java Build Path (30)14.RUN CONFIGURATION (31)Creating and Using a Run Configuration (31)15.RUNNING A PROGRAM (33)Running a Java Program (33)16.CREATE JAR FILES (35)Opening the Jar File wizard (35)Using the Jar File wizard (35)17.CLOSE PROJECT (37)Why Close a Project? (37)How to Close a Project? (37)Closed Project in Package Explorer (38)18.REOPEN PROJECT (39)Reopening a Closed Project (39)19.BUILD PROJECT (40)Building a Java Project (40)20.DEBUG CONFIGURATION (42)Creating and Using a Debug Configuration (42)21.DEBUGGING A PROGRAM (44)Debugging a Java Program (44)22.PREFERENCES (48)Setting Preferences (48)23.CONTENT ASSIST (50)Using Content Assist (50)24.QUICK FIX (52)Using Quix Fix (52)25.HOVER HELP (54)Using Hover Help (54)26.SEARCH MENU (56)Searching the Workspace (56)27.NAVIGATION (58)Navigating the Eclipse Workspace (58)Open Type (58)Open Type in Hierarchy (60)Open Resource (61)28.REFACTORING (63)Refactoring using Eclipse (63)29.ADD BOOKMARKS (64)About Bookmarks (64)Adding a Bookmark (64)Opening the Bookmarks View (64)Using the Bookmarks View (65)30.TASK MANAGEMENT (66)Managing Tasks (66)Opening the Tasks View (67)Using the Tasks View (67)31.INSTALL PLUGINS (69)Locating and Installing Plug-ins (69)32.CODE TEMPLATES (73)Using Code Templates (73)Modifying/Adding code templates (74)33.SHORTCUTS (75)About Shortcuts (75)34.RESTART OPTION (78)Restarting Eclipse (78)35.TIPS & TRICKS (79)36.WEB BROWSERS (81)Internal Web Browser (81)Eclipse 7What is Eclipse?In the context of computing, Eclipse is an integrated development environment (IDE) for developing applications using the Java programming language and other programming languages such as C/C++, Python, PERL, Ruby etc.The Eclipse platform which provides the foundation for the Eclipse IDE is composed of plug-ins and is designed to be extensible using additional plug-ins. Developed using Java, the Eclipse platform can be used to develop rich client applications, integrated development environments, and other tools. Eclipse can be used as an IDE for any programming language for which a plug-in is available.The Java Development Tools (JDT) project provides a plug-in that allows Eclipse to be used as a Java IDE, PyDev is a plugin that allows Eclipse to be used as a Python IDE, C/C++ Development Tools (CDT) is a plug-in that allows Eclipse to be used for developing application using C/C++, the Eclipse Scala plug-in allows Eclipse to be used an IDE to develop Scala applications and PHPeclipse is a plug-in to eclipse that provides complete development tool for PHP.LicensingEclipse platform and other plug-ins from the Eclipse foundation is released under the Eclipse Public License (EPL). EPL ensures that Eclipse is free to download and install. It also allows Eclipse to be modified and distributed.Eclipse ReleasesEvery year, since 2006, the Eclipse foundation releases the Eclipse Platform and a number of other plug-ins in June.1.Eclipse8Eclipse 9Downloading EclipseYou can download eclipse from /downloads/. The download page lists a number of flavors of eclipse.The capabilities of each packaging of eclipse are different. Java developers typically use Eclipse Classic or Eclipse IDE for developing Java applications.The drop down box in the right corner of the download page allows you to set the operating system on which eclipse is to be installed. You can choose between Windows, Linux and Mac. Eclipse is packaged as a zip file.Installing EclipseTo install on windows, you need a tool that can extract the contents of a zip file. For example you can use:∙7-zip ∙PeaZip ∙ IZArcUsing any one of these tools, extract the contents of the eclipse zip file to any folder of your choice.2.Launching EclipseOn the windows platform, if you extracted the contents of the zip file to c:\, then you can start eclipse by using c:\eclipse\eclipse.exeWhen eclipse starts up for the first time it prompts you for the location of the workspace folder. All your data will be stored in the workspace folder. You can accept the default or choose a new location.1011If you select "Use this as the default and do not ask again", this dialog box will not come up again. You can change this preference using the Workspaces Preference Page. See the Preference tutorialpage for more details.Eclipse 12Parts of an Eclipse WindowThe major visible parts of an eclipse window are:∙Views ∙Editors (all appear in one editor area) ∙Menu Bar ∙ ToolbarAn eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective can be active at any point of time. A user can switch between open perspectives or open a new perspective. A perspective controls what appears in some menus and tool bars.3.EclipseA perspective has only one editor area in which multiple editors can be open. The editor area is usually surrounded by multiple views. In general, editors are used to edit the project data and views are used to view the project metadata. For example, the package explorer shows the java files in the project and the java editor is used to edit a java file.The eclipse window can contain multiple editors and views but only one of them is active at any given point of time. The title bar of the active editor or view looks different from all the others.The UI elements on the menu bar and tool bar represent commands that can be triggered by an end user.Using Multiple WindowsMultiple Eclipse Windows can be open at the same time. To open a new window, click on the Windows menu and select the New Window menu item.Each window can have a different perspective open in them. For example you could open two Eclipse windows one in the Java perspective and the other in the Debug perspective. The window showing the Java perspective can be used for editing the java code and the window showing the debug perspective can be used for debugging the application being developed.13Eclipse 14T ypical Eclipse MenusThe typical menus available on the menu bar of an Eclipse window are:∙File menu ∙Edit menu ∙Navigate menu ∙Search menu ∙Project menu ∙Run menu ∙Window menu ∙ Help menu4.Plug-ins can add new menus and menu items. For example when the java editor is open, you will see the Source menu and when the XML editor is open, you will see the Design menu. Brief Description of Menus15Customizing MenusThe visible menu items on a menu depend on the installed plug-ins and customization done using the Customize Perspective dialog box.16Eclipse 17About ViewsEclipse views allow users to see a graphical representation of project metadata. For example the project navigator view presents a graphical representation of the folders and files associated with a project and properties view presents a graphical representation of an element selected in another view or editor.An eclipse perspective can show any number of views and editors. All editor instances appear in a single editor area, whereas views are placed inside view folders. A workbench window can display any number of view folders. Each view folder can display one or more views. Organizing ViewsThe following picture shows four views arranged in a view folder.The picture given below shows the same four views arranged in two view folders.5.Moving ViewsTo move a view from one view folder to another, just click on the view title and drag to the title bar area of another view folder. The green line shown below is a result of dragging the title bar of the Properties view from one view folder to the title bar area of another view folder. The Properties view can be moved to where the green line is by releasing the mouse button and sending out a drop event.Creating View FoldersView folders can be dynamically created by dragging the title bar of a view to anywhere outside the editor area and title bar of another view folder. As you drag the title bar around, green lines will indicate where exactly the new view folder will be created.Moving the drag icon to the bottom of a window allows you to create a view folder that spans the entire width of the window. Moving the drag icon to the left or right edge of window allows you to create a view folder that spans the entire height of the window.18Opening a viewTo open a view, click on the Window menu and select the Show View menu item.19Clicking on the Other menu item brings up the Show View dialog box that allows you to locate and activate a view.20The views are organized by category. To quickly locate a view, just type the name of a view into the filter text box. To open a view, select it and click on the OK button. The subsequent pages of this tutorial introduce you to a number of useful views.21End of ebook previewIf you liked what you saw…Buy it from our store @ https://22。

hibernate的基本用法

hibernate的基本用法

hibernate的基本用法Hibernate是一个开源的Java框架,用于简化数据库操作。

它为开发人员提供了一个更加简单、直观的方式来管理数据库,同时也提高了应用程序的性能和可维护性。

本文将逐步介绍Hibernate的基本用法,包括配置、实体映射、数据操作等。

一、配置Hibernate1. 下载和安装Hibernate:首先,我们需要下载Hibernate的压缩包并解压。

然后将解压后的文件夹添加到Java项目的构建路径中。

2. 创建Hibernate配置文件:在解压后的文件夹中,可以找到一个名为"hibernate.cfg.xml"的文件。

这是Hibernate的主要配置文件,我们需要在其中指定数据库连接信息和其他相关配置。

3. 配置数据库连接:在"hibernate.cfg.xml"文件中,我们可以添加一个名为"hibernate.connection.url"的属性,用于指定数据库的连接URL。

除此之外,还需要指定数据库的用户名和密码等信息。

4. 配置实体映射:Hibernate使用对象关系映射(ORM)来将Java类映射到数据库表。

我们需要在配置文件中使用"mapping"元素来指定实体类的映射文件。

这个映射文件描述了实体类与数据库表之间的对应关系。

二、实体映射1. 创建实体类:我们需要创建一个Java类,用于表示数据库中的一行数据。

这个类的字段通常与数据库表的列对应。

同时,我们可以使用Hibernate提供的注解或XML文件来配置实体的映射关系。

2. 创建映射文件:可以根据个人喜好选择使用注解还是XML文件来配置实体类的映射关系。

如果使用XML文件,需要创建一个与实体类同名的XML文件,并在其中定义实体类与数据库表之间的映射关系。

3. 配置实体映射:在配置文件中,我们需要使用"mapping"元素来指定实体类的映射文件。

IDEA、Eclipse的详细安装配置及Tomcat服务集成介绍

IDEA、Eclipse的详细安装配置及Tomcat服务集成介绍

IDEA、Eclipse的详细安装配置及Tomcat服务集成介绍说到开发工具,我们大家都知道每一个开发语言对会对应多个比较合适自己的开发工具,好的开发工具可以帮助提高写代码的效果及排错,比如拿java来说吧~最早及现在用的人最多的想必应该是eclipse了吧~那具体功能怎么样呢,对我一个新手来说没有资格评价了,最近看见有人用IDEA工具来编写代码,而且还说到IDEA工具比eclipse的效率高,而且好,于是我在网上找了一些关于idea和eclipse的对比文档,查看后,多少对idea有些触动,之前就会使用eclipse,可idea不会使用,所以就慢慢学吧~通过idea编写玩代码后,如果需要测试的话,貌似没有eclipse下集成tomcat那样的方便,所以就找相关的文档,经过测试后,idea可以集成tomcat服务,这样在编写代码的过程中可以很好的更方便的去测试了。

因为idea默认测试web服务的话,比较麻烦,需要运行maven debug,然后通过浏览器会自动蹦出来,而不是在idea页面上显示,所以很方便,今天呢,我把在eclipse和idea下的tomcat集成方便做了一个文档,供有需要的参考。

首先是,准备环境了,不管是eclipse还是idea也好,都需要配置java运行环境,jdk及环境变量配置。

JDK下载我们可以在百度上搜索JDK,然后会下载到最新的JDK软件;在此JDK和JRE均安装到了C盘下接下来就是配置环境变量 C:\Java\jdk1.8.0_31再次就是下载安装Eclipse了,也可以在百度上下载注意:在使用Eclipse的时候注意一个问题,JDK的版本和Eclipse的版本需要(都是x64的或者x86的)统一,不然安装完eclipse是无法启动的;下载link: /安装好后,我们接下来就是下载apache for tomcat了,我们也可以通过百度上进行搜索下载或者在官网进行下载:下载后,无需要安装解压即可我们知道默认tomcat的端口为8080,如果想修改需要进行修改一下配置选项在tomcat的安装目录下的conf文件下的server.xml文件默认端口8080以上工作准备好后,我们就准备给eclipse集成tomcat了为了方便我们创建一个项目在新建一个html文件,为了更好的演示单击windows---PreferencesServer-àruntime environment--àadd选择apache tomcat 版本,我们一般选择最新为tomcat指定一个显示名称及路径确认信息接下来我们给项目配置,右击项目--àbuild path-àconfigure build pathLibrary-----àadd library选择server runtime选择刚才添加的apache tomcat添加完成我们运行新建测hello.html文件,我们选择tomcat服务进行访问添加需要通过tomcat运行的项目我们使用tomcat运行正常访问接下来就是idea的安装配置了;在此我们就不演示对idea的安装了,因为安装只需要下一步下一步默认完成即可我们可以通过以下链接进行下载/idea/ideaIU-14.1.4.exe/idea/注:在安装的时候会提示选择jdk的安装路径,指定即可下载安装后,我们新建了一个web项目,同时创建了一个可测试的html文件同时也安装好了IDEA,然后我们新建了一个web我们按组合键盘ctrl+alt+shift+s 打开设置,单击Moduls--->Dependencies---à +选择Library,因为是tomcat所以必须选择该类型选择apache for tomcat即可Ok添加完成Ctrl+alt+s 输入application过滤服务----单击添加Application servers---à tomcat server指定apache for tomcat 安装路径选定目录路径添加完成单击右上角--à下拉菜单-àedit configuration单击左边的添加即可选择tomcat server-àlocal定义名称我们同样勾选tomcat相关的log,以便发现问题添加完成我们发现通过tomcat访问无法显示页面通过右上角---edit configuration单击fix检查修复Fix检查修复完成后,单击ok即可再次使用tomcat运行,会提示更新,然后我们再次运行会手动选择restart server即可访问完成附件中附带了注册机,请将扩展名从txt修改为.7z后解压即可。

eclipse中,由数据库反向生成hibernate实体类(图解)

eclipse中,由数据库反向生成hibernate实体类(图解)

Eclipse中反向生成hibernate实体类+jpa注释2011-01-24一、配置数据源,sqlServer2000数据库1、菜单栏“Window”……,截图如下:2、Database Connecttions右击“new”,选择要使用的数据库,本例中是SQL Server,给数据源随便命名,此处为MedicalInfoDB,然后单击“next”,截图如下:3、单击Drivers一行最后那个按钮,配置数据库驱动:配置驱动类和url等……最后点击“OK”,截图如下:4、点击“OK”之后,配置“General”选项卡,“Optional”选项卡不用管,截图如下,5、然后点击“Next”,核对一下数据源信息,点击“Finish”。

截图如下:6、二、反向生成实体类1、打开eclipse,在顶部菜单栏右击选择“Customize Per……”,截图如下:2、选择之后弹出如下选项卡,选择“Command Groups A vailability”,在下面勾选“Hibernate Code Generation”,然后点击“OK”,截图如下:3、点击“OK”之后会在菜单栏中显示如下图所示最后一个快捷按钮:4、点击按钮右边的小箭头,选择下拉菜单中第二项“Hibernate Code Generation……”,截图如下:5、选中之后,弹出如下窗口,右击“New”一个New_configuration:6、左键单击选中新建的New_configuration,右边出现好多选项卡,截图如下:参数说明:(1)、没用;(2)、选择保存……的位置。

(3)、如果反向生成实体类,则将勾上。

保存实体类的文件夹的位置(可不填写),Reveng.xml最右边的Setup……,点击后“新建”或者“使用已存在的”reveng.xml。

选择保存reveng.xml文件的项目的包,点击“Next”,然后点击,单击选中要使用的数据库,或者数据库的某些表(包括表和视图!!!),点击,然后“Finish”。

Eclipse+Struts+Spring+Hibernate+Mysql环境搭建及访问数据库实例

Eclipse+Struts+Spring+Hibernate+Mysql环境搭建及访问数据库实例

前言:这个例子的view层用到了struts,DAO层用到了hibernate,由于逻辑及其简单(只是往数据库添加一条记录),所以暂时没有用到spring。

一、使用eclipse+struts+spring+hibernate+myeclipse+mysql开发配置过程。

1.jdk的安装:安装文件:jdk-1_5_0_15-windows-i586-p.exe说明:最好用jdk1.5,可以去sun主页下载,我这里已经下了,可以提供。

注意:最好在新装系统下安装,并且此前没有装过java相关的软件,以免出现版本或者path问题。

过程:可以直接安装到c盘根目录下即可,注意要记住安装路径,以后可能会用到。

2.web应用服务器tomcat的安装:安装文件:apache-tomcat-5.5.26.exe说明:要想构建jsp应用,web应用服务器是必须要有的,asp服务器为IIS,php服务器为Apache,jsp服务器比较多有weblogic和websphere(两者是商业级的,比较强大,但要收费),tomcat和resin(免费的,比较适用中小级应用,如果是大型应用则须考虑集群)。

在这里,我选用tomcat,因为它使用较广泛,网上相关的资料也比较多。

我并没有选择最新版本,原因是次新版本往往比最新版本更加稳定。

注意:必须先装jdk,否则不能安装tomcat(原因之一是tomcat在对jsp进行编译时用到了jdk,并且jdk是tomcat正常工作的前提)。

过程:可以直接安装到c盘默认路径,选择前面安装的jdk路径,并且修改端口8080为80(tomcat默认端口为8080,而一般我们通过IE访问时端口为80,需要注意的是要保证没有其他程序已经占用80端口(比如你已经装了iis或者apache),否则tomcat不能正常启动),控制台页面的管理员admin帐号暂时不设置密码。

测试页面http://127.0.0.1,检测是否安装成功,如果进入欢迎页面就表示tomcat安装成功。

Eclipse的插件

Eclipse的插件

Eclipse插件大观Properties Editor 点击次数:6615Properties Editor 编辑java的属性文件,并可以自动存盘为Unicode格式Colorer Take 点击次数:4102Colorer Take 为上百种类型的文件按语法着色XMLBuddy 点击次数:5464XMLBuddy 编辑xml文件Code Folding 点击次数:3136Code Folding 加入多种代码折叠功能(比eclipse自带的更多)Easy Explorer 点击次数:2469Easy Explorer 打开在eclipse中选定文件所在的目录。

Fat Jar 点击次数:3618Fat Jar 打包插件,可以方便的完成各种打包任务,可以包含外部的包等RegEx Test 点击次数:2253RegEx Test 测试正则表达式Jigloo GUI Builder 点击次数:4166Jigloo GUI Builder JAVA的GUI编辑插件Profiler 点击次数:2623Profiler 性能跟踪、测量工具,能跟踪、测量BS程序AdvanQas 点击次数:1201AdvanQas 提供对if/else等条件语句的提示和快捷帮助(自动更改结构等)Log4E 点击次数:3340Log4E Log4j插件,提供各种和Log4j相关的任务,如为方法、类添加一个logger等VSSPlugin 点击次数:2935VSSPlugin VSS插件Implementors 点击次数:2179当追踪方法代码时,Eclipse默认是转到方法的接口类,而接口中是只有方法名称没有具体的实现代码,此插件提供了追踪到具体实现类的实现代码的功能。

Call Hierarchy 点击次数:1595Call Hierarchy 显示一个方法的调用层次EclipseTidy 点击次数:2369EclipseTidy基于HTML Tidy提供校验和格式化HTML/XML文件的功能Checkclipse 点击次数:2527Checkclipse 检查代码的风格、写法是否符合规范Hibernate Synchronizer 点击次数:14526Hibernate Synchronizer Hibernate插件,自动映射等VeloEclipse 点击次数:3328Velocity插件在线更新地址: http://log4e.jayefem.de/updateEditorList 点击次数:1161方便的列出所有打开的EditorMemoryManager 点击次数:2007内存占用率的监视TomcatPlugin 点击次数:7280支持Tomcat插件lomboz 点击次数:9638Lomboz是Eclipse的一个J2EE的插件,它将很多Java应用服务器、J2EE组件和Web应用开发集成到Eclipse 中,可以帮助Java开发者使用Eclipse建立、测试、部署J2EE应用。

Eclipse开发环境配置

Eclipse开发环境配置

Eclipse开发环境配置 最近要在2个多年前的⽼项⽬⾥添加功能,⽤idea启动失败之后,尝试使⽤Eclipse启动成功了。

⽼项⽬到什么程度呢? ⼀个是Maven项⽬,SpringMVC,要在Tomcat8上运⾏,数据源是在Tomcat的context.xml⽂件⾥的。

另⼀个是传统JavaWeb项⽬,jdk1.6,框架是:Spring + Struts + itatis,引⼊lib的jar,在Tomcat上运⾏,数据源也是在Tomcat6的context.xml⽂件⾥的。

所以本⼈只能重新捡起来多年未⽤的Eclipse,配置了1天时间,把配置过程,和启动项⽬过程总结⼀下。

1. Eclipse配置1.1 基础配置 Eclipse修改字体:Window --> Preferences --> General --> Appearance --> Colors and Fonts 修改通⽤字体:Basic --> Text Font 修改Java⽂件字体:Java --> Java Editor Text Font Eclipse修改项⽬字符集:右击项⽬ --> Properties --> Resource1.2 开发环境配置 配置过程默认JDK、Maven等环境变量都是配置好的。

开发模式:新装的Eclipse,默认是JavaEE模式,需要我们点击右上⾓的“Open Perspective”图标,选择Java,时候要使⽤Java模式开发。

Eclipse配置JDK:Window -> Preferences -> java -> install jres -> add -> standard vm -> 设置好相应的jre home(虽然名字叫jre home,建议选择jdk路径) Eclipse配置Maven:Window --> Preferences --> Maven --> Installations --> 设置maven Eclipse配置Tomcat:Window --> Preferences --> Servers --> 选择Tomcat对应的版本,添加Tomcat地址。

使用Eclipse进行Java应用程序开发的入门教程

使用Eclipse进行Java应用程序开发的入门教程

使用Eclipse进行Java应用程序开发的入门教程第一章:介绍Eclipse和Java开发环境Eclipse是一款流行的集成开发环境(IDE),可用于开发各种编程语言,包括Java。

它提供了强大的工具和功能,使Java开发变得更加高效和便捷。

1.1 Eclipse的安装首先,下载适用于Java开发的Eclipse版本。

安装过程相对简单,按照向导提示顺序执行即可完成。

确保选择Java开发工具(Java Development Tools,JDT)的安装。

1.2 JDK的安装和配置Eclipse需要Java Development Kit(JDK)才能编译和运行Java 代码。

确保已安装最新版本的JDK,并将其配置为Eclipse的默认JDK。

1.3 创建Java项目启动Eclipse后,选择"File -> New -> Java Project"来创建一个新的Java项目。

在弹出的对话框中,输入项目名称并选择所需的JDK版本。

点击"Finish"来创建项目。

第二章:Eclipse的基本功能和工作空间2.1 工作空间Eclipse使用工作空间(Workspace)来组织项目和资源文件。

在启动Eclipse时,会要求选择工作空间文件夹。

一个工作空间可以包含多个项目。

2.2 项目资源Eclipse的"Package Explorer"窗口显示项目中的所有文件和文件夹。

你可以在此窗口中创建、删除和管理项目资源。

2.3 编辑器Eclipse的编辑器是主要的编码区域,用于编写和编辑Java代码。

当你双击项目中的Java文件时,它会在编辑器中打开。

2.4 调试器Eclipse提供强大的调试功能,可帮助你发现和修复代码中的错误。

你可以设置断点、单步执行代码、查看变量的值等。

调试器是开发过程中非常有用的工具。

第三章:Java项目的创建和配置3.1 创建包和类在Eclipse的"Package Explorer"窗口中,右键点击项目,选择"New -> Package"来创建一个包。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Eclipse下配置和使用Hibernate Tools
文章分类:Web前端关键字: hibernate tools eclipse 插件配置
Hibernate Tools可以通过访问已经建立好的数据库以反向工程方式生成POJO文件。

今天就来说一下如何使用Hibernate Tools来生成POJO。

1、首先,要去Hibernate的网站下载这个工具包。

一个大约14M的ZIP压缩文件。

/sourceforge/jboss/HibernateTools-3.2.4.Beta1-R200810311334.zip
2、解压缩下载好的文件,释放出features和plugins这两个文件夹和其中的内容。

完成后将这两个文件夹复制到Eclipse的目录下(这两个文件夹在Eclipse中是默认存在的,直接复制就行了)。

3、到这步为止HibernateTools的安装就算结束了,下面开始配置和具体使用。

一开始选择工程下的SRC 目录,然后右键New->Other->Hibernate->Hibernate Configuration File(cfg.xml),在弹出的窗口中选择Next ,进入到下面的选项中。

注意,这个地方有几项是一定要填写的。

他们分别是Database dialect(数据库方言)、Driver class(数据库驱动)、Connection URL(链接字符串)以及Username和Password(访问数据库的用户名和密码)。

上图图中使用的是MySQL5数据库的配置,vane是我机器中已经创建好的数据库。

使用其他数据库的时候会略有不同。

填好之后选择Finish。

4、选择Eclipse的下拉菜单Window->Show View->Other->Hibernate->Hibernate Configurations,现在就可以查看Hibernate的配置窗口了。

在窗口中单击右键Add Configuration,出现Edit Configuration窗口。

这里需要给Configuration起个名字,然后在Project项目中选择当前工程。

单击OK。

5、如果上一步的配置是正确的,那么在Hibernate的配置窗口中就可以看见Hibernate访问数据库得到的数据信息。

没有访问成功的话会弹出对话框,可以根据提示信息来判断自己的工程中出现了什么问题。

大多数情况是由于工程中没有MySQL的驱动造成的。

如果再有什么解决不了的问题,可以给我留言,我会跟您一起研究的。

驱动包的官方下载地址:
/downloads/connector/j/5.1.html
6、第5步成功的话就可以进行最后一步生成Code的工作了,多么激动人心的时刻啊o(∩_∩)o...
不着急,这里我们先做一个准备工作。

右键单击Eclipse的工具条,选择Customize
Perspective->Commands->Hibernate Code Generation,单击OK。

这样工具栏中就增加了Hibernate的图标。

左键单击图标右边的下箭头,在下拉菜单中选择Hibernate Code Generation Configurations,
在弹出的窗口中进行最后的设置。

Main标签下的Output directory选择的是生成文件的位置,选择到src目录即可。

Reverse engineer from JDBC Connection这个单选框很重要,选上就是了。

Package选择的是生成POJO的包名,可以根据需求自己起名字。

reveng.xml这个地方选择Setup->Create new->工程名->Next->Refresh->include->Finish,搞定!(reveng可不是变形金刚~)
Exporters标签下选择您要生成的文件,其中Domain code(.java)是一定要选的,第二项Hibernate XML Mappings(.hbm.xml)是生成配置文件的,如果您的工程中决定使用Annotation的话可以忽略这一项。

最后一步,点击Run,这样就得到您想要的POJO代码了。

觉得不满意自己再慢慢修改吧,也可以写一个格式化代码的程序,这个下次再说吧。

PS:第一次写技术博客,可能有很多地方讲得不清楚或者有地方说错了,希望大家给我一一指出,我会尽快改正的!
youjianbo_han_87 写道
第四步时,加上加入Hibernate gencode下所需的jar包会更好。

呵呵
多谢指教。

相关文档
最新文档