如何在 Eclipse 中启动 Java EE 6 项目

发布于 2024-12-09 00:03:48 字数 535 浏览 0 评论 0原文

在学习 Java SE 几年(以及其他语言)之后,我最近开始学习 Java EE 6。我买了关于 Maven、EJB、JSF、Glassfish 等的不同书籍(不过还没有全部读完),我对制作一个项目的复杂性感到绝对不知所措。

我如何在 Eclipse 中从“从头开始”(不是从书中的示例复制)开始一个项目?我可以从 Dynamic Web 项目、Maven 项目、EJB 项目、EAR 应用程序等中进行选择。如果我想制作一个内部包含 EJB/JPA 和 JSF 的应用程序(Web 应用程序),我应该使用哪个?

我了解标准 Maven 目录布局和原型,但是我不知道如果这样做的话应该选择哪个。当然,我知道有很多方法可以做到这一点,这取决于我将用它做什么,但我正在学习 Java EE 6,所以我想至少了解一些如何设置基本项目的知识出色地。

我也对 POM 文件感到不知所措。我如何知道开始使用 Web 应用程序时需要哪些依赖项?或者这是否包含在正确的原型中(如果我找到了?)

我使用 Glassfish 作为应用程序服务器、Eclipse、EJB、JPA 和 JSF。目前仅从书本示例中学习。

I have recently begun learning Java EE 6 after doing Java SE for some years now (together with other languages). I have bought different books about Maven, EJB, JSF, Glassfish and so on (not read them all yet though), and I feel absolutely overwhelmed of the complexity of just making a project.

How would I start a project from "scratch" (Not copying a from an example in the book) in eclipse? I can choose from Dynamic Web project, Maven project, EJB project, EAR application etc. Which should I use if I want to make an application that has EJB/JPA and JSF inside (web application)?

I know about the Standard Maven Directory Layout and archetypes, however I do not know which to choose if this is the way to do it. Of course, I understand that there are many ways of doing it and it is dependent on what I will use it for, but I am learning Java EE 6 so I want to at least have some knowledge of how to set up a basic project as well.

I am also rather overwhelmed by the POM file. How do I know which dependencies I need just to get started with a web application? Or is this included in the correct archetype (if I find one?)

I am using Glassfish as application server, Eclipse, EJB, JPA and JSF. Currently learning from book examples only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冰魂雪魄 2024-12-16 00:03:48

好吧,要完整回答你的问题几乎需要一整本书,但这里有一些提示。

  • Java EE 应用程序的概念代表使用一个或多个 Java EE API 实现并需要 Java EE 应用程序服务器才能运行的任何类型的 Java 应用程序。 Java API 包括:Servlet、JSP、EJB、JPA 等。这些 API 的实现通常由应用程序服务器提供(例如 Tomcat 有 servlet 和 JSP 实现,Glassfish 也有这些以及 EJB 等)。比如说,有非应用程序服务器 Java EE API 实现,例如 Hibernate 的 JPA 实现。简而言之,如果您在应用程序中使用其中一些 API 实现并将其部署到 Tomcat、Glassfish、JBoss AS 等应用程序服务器中,您就拥有了一个 Java EE 应用程序。

    • 我告诉你这一切是因为实际上,大多数项目管理工具(如 Eclipse、Maven 等)都使用这些细分,如 Web 应用程序、EJB 模块、动态 Web 项目等,作为自定义确定您的应用程序将使用哪组 Java EE API 的大致范围。 IE 中,Web 应用程序或动态 Web 项目更有可能使用 Servlet 和 JSP API,EJB 模块将(废话)使用 EJB API 等等。正如我所说,这些都是大致的教派。动态 Web 应用程序也可以使用 EJB 或 JPA,这并不是一成不变的。

    • 当您使用这些工具(例如 Eclipse 或 Maven)来启动上述命名项目之一(例如 Elcipse 中的动态 Web 项目或使用 Maven 的标准 Web 应用程序)时,相应的工具将将常识依赖项添加到您的模板项目(如本例中的 Servlet 和 JSP),然后让您从这里处理它。

    • 这里的想法是在项目开始使用之前了解所选工具的每种类型的模板。就像如果您决定使用 Eclipse 并从动态 Web 项目开始一样,您应该检查 Eclipse 到底要求您做什么以及执行此操作时执行的操作(它会询问您本地安装的 Java EE 应用程序服务器的位置)将引入 Servlet 实现和 JSP 实现等依赖项)。或者,如果您选择 Maven,并启动一个标准的 Web 项目,您应该检查它通过 pom.xml 文件向您的项目添加了哪些依赖项,该 pom.xml 文件的基本功能是什么,等等。您还应该查看当您告诉这些工具这样做时,它们如何部署您的应用程序,它是否使用 Java EE 服务器的某些热部署功能,是否需要凭据才能首先访问该服务器等。

我的简短建议是从非常基本的开始示例:安装 Tomcat(版本 7 是推荐),启动 Eclipse 进行 Java EE 开发,将 Tomcat 安装添加到 Eclipse 配置中,启动一个使用 Tomcat 作为应用程序服务器的动态 Web 项目,只做一些基本的 servlet 和 JSP 页面,然后使用 Eclipse 将该傻瓜部署到tomcat 并运行它。然后你可以分支到更高级的东西,比如用 Maven 做同样的事情,将 Maven 项目与 Eclipse 集成,添加一些更多的 Java EE 东西(比如 JPA 实现)等等。

Well, a complete answer to your question would pretty much need an entire book on it's own, but here's some pointers.

  • The notion of Java EE applications represents any kind of Java application that uses one or more of the Java EE APIs implementation and needs a Java EE application server to run. Java APIs are those such: Servlet,JSP, EJB, JPA, etc. Implementations of these APIs are usually provided by the application Server (like Tomcat has servlet and JSP implementations, Glassfish has those as well plus EJB, etc). There are, let's say non-application server Java EE APIs implementations like Hibernate's implementation of JPA. So in short if you use some of these APIs implementations in your app and deploy it into some application server like Tomcat, Glassfish, JBoss AS, etc, you have a Java EE application.

    • I've told you all this because in reality, most of the project management tools (like Eclipse, Maven, etc) use these subdivisions like Web-Application, EJB Module, Dynamic Web Project etc, as a custom denomination that establishes the ball park of what set of Java EE APIs your application will use. I.E. a Web Application or Dynamic Web Project will more likely use Servlet and JSP APIs, an EJB Module will (duh) use the EJB APIs and so on. These are, as I said, ball park denominations. A Dynamic Web Application can use EJB or JPA as well, it's not like it's written in stone.

    • When you use either of these tools such as Eclipse or Maven, to start one of these above mentioned, denominated projects, such as a Dynamic Web Project in Elcipse or a Standard Web Application with Maven, that respective tool will add the common sense dependencies to your template project (like Servlet and JSP in this case), and then let you handle it from here.

    • The idea here is to understand each type of template of your chosen tool before you use it at the start of your project. Like if you decide to use Eclipse and start with a Dynamic Web Project, you should check out what exactly Eclipse asks of you and does when you do that (it will ask you for the location of a locally installed Java EE application server from where it will pull in such dependencies as a Servlet Implemnentation and a JSP implementation amongs others). Or if you chose Maven, and start a standard web project, you should check out what dependencies it adds to your project via the pom.xml file, what the basic functions of THAT pom.xml file are, etc. You should also check out how each of these tools deploys your application when you tell it to do that, does it use some hot deploy feature of your Java EE server, does it need credentials to access that server first etc.

My brief advice is to start with the very basic example: Install a Tomcat (version 7 is recommended), start Eclipse for Java EE Development, add that Tomcat installation to your Eclipse config, start a Dynamic Web project that uses that Tomcat as Application server, and just do some basic servlets and JSP pages, then use Eclipse to deploy that sucker to tomcat and run it. Then you can branch off to more advanced stuff, like doing the same thing with Maven, integrating a Maven project with Eclipse, adding some more Java EE Stuff (like a JPA Implenentation), etc etc.

伏妖词 2024-12-16 00:03:48

http://blogs.oracle.com/arungupta/entry/web_app_development_using_java 提供了完整的解释介绍如何使用 Eclipse 和 GlassFish 创建 Java EE 6 项目。

或者,您也可以使用 NetBeans 创建 Java EE 6 项目,如下所述:

http://blogs。 oracle.com/arungupta/entry/screencast_37_java_ee_6

http://blogs.oracle.com/arungupta/entry/web_app_development_using_java provides a complete explanation of how to create a Java EE 6 project using Eclipse and GlassFish.

Alternatively, you can also NetBeans to create a Java EE 6 project as explained at:

http://blogs.oracle.com/arungupta/entry/screencast_37_java_ee_6

魄砕の薆 2024-12-16 00:03:48

我可以从Dynamic Web项目、Maven项目、EJB项目中进行选择,
EAR 应用程序等。如果我想做一个,我应该使用哪个
内部包含 EJB/JPA 和 JSF 的应用程序(Web 应用程序)?

在 EJB 3.1 规范之前,不可能在 war 文件中部署 EJB,但现在可以了。因此,对于快速原型,如果您需要并且更熟悉它,您可以使用 war 文件而不是 Ear 文件。当然您也可以将其部署在 .ear 文件中。

我相信 Eclipse 中的动态 Web 项目会生成一个 .war 文件,您可以将其部署在 AS 中。

如果您使用 Maven,您还可以预先使用 Maven 创建项目,然后使用 Maven 导入(通过 M2Eclipse 插件)。这对我来说效果很好。然后,使用 Glassfish Maven 插件,您可以通过命令行将应用程序部署到 Glassfish。

我也对 POM 文件感到不知所措。我怎么知道哪个
我刚开始使用 Web 应用程序时需要依赖项吗?或者是
这包含在正确的原型中(如果我找到一个?)

您至少需要在“提供”范围内的 Java EE 依赖项,因为服务器可能会为您提供这些依赖项。这样您就可以在编译模式下使用它们。例如,JBoss Java EE 5 堆栈的堆栈如下(不确定 GlassFissh 依赖项,但重要的是不要将该库包含在 .ear / .war 中以避免库冲突):

<dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>javaee-api</artifactId>
    <version>5.0-1</version>
    <scope>provided</scope>
</dependency>

添加:正如你所说,一开始这可能会让人不知所措,我认为 是关于如何设置 Glassfish / Java EE 项目的好资源。选择您感兴趣的部分并祝您好运。

I can choose from Dynamic Web project, Maven project, EJB project,
EAR application etc. Which should I use if I want to make an
application that has EJB/JPA and JSF inside (web application)?

Before EJB 3.1 spec it was not possible to deploy EJBs in war files, but now, you can. So for a quick prototype you can use a war file rather than an ear file if that's all you require and you are more familiar with it. Of course you can also deploy it in an .ear file.

I believe the Dynamic Web project in Eclipse generates a .war file that you can deploy in your AS.

If you are using Maven, you can also create your project with Maven beforehand, and then import using Maven (via M2Eclipse plugin). This works pretty well for me. Then, with the Glassfish Maven plugin, you can deploy your app to Glassfish via command line.

I am also rather overwhelmed by the POM file. How do I know which
dependencies I need just to get started with a web application? Or is
this included in the correct archetype (if I find one?)

You need the Java EE dependencies at least in a "provided" scope as the server will probably provide these for you. This way they will be available for you in compilation mode. For instance, the one for the JBoss Java EE 5 stack is as follows (not sure about the GlassFissh dependency, but the important stuff is not to include the library in your .ear / .war in order to avoid library conflicts):

<dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>javaee-api</artifactId>
    <version>5.0-1</version>
    <scope>provided</scope>
</dependency>

Added: As you said, this can be overwhelming at the start, I think this is a good resource on how to setup a Glassfish / Java EE project. Pick the bits you are interested on and good luck.

秋凉 2024-12-16 00:03:48

我要问你的第一件事是为什么你要学习这么多技术。如果您的目的是找工作,根据我的经验,公司有一种趋势,即远离 Java EE,转向更简单的解决方案。例如,应用程序服务器对于大多数组织来说都是多余的,而 Tomcat(或其他 Web 服务器)则采用 Spring 和独立 JMS 服务器等辅助技术来取代功能齐全且复杂得多的 Java EE 服务器。

我认为,当您开始使用并远离 IDE、复杂构建、EAR 等时,您最好专注于核心概念和更简单的技术。相反,从一两项技术开始(例如带有简单 Ant 的 hello Tomcat 应用程序) build)并根据需要逐步添加每种技术。如果你有一个现实世界的问题需要解决,即使没有回报,那就更好了。

大多数公司(至少是那些掌握技术线索的公司)宁愿雇用一位了解 JSF 等技术的价值以及复杂性成本的程序员,而不是简历中包含大量缩写词的程序员。

The first thing I'd ask you is why you're learning so many technologies. If your purpose is getting a job, in my experience, there's a trend in companies away from Java EE and towards simpler solutions. For example, application servers are overkill for most organizations and Tomcat (or another web server) with helper technologies like Spring and standalone JMS servers replacing full-featured and much more complex Java EE servers.

I think you'd be better served focusing on core concepts and simpler technologies as you get started and staying away from IDEs, complex builds, EARs, etc. Instead, start with one or two technologies (e.g. a hello Tomcat app with a simple Ant build) and gradually add each technology in as you find the need. Better yet if you have a real world problem to solve, even if it doesn't pay.

Most companies (at least those with a technical clue) would rather hire a programmer who understands what value a technology like JSF adds and at what cost of complexity than someone with a lot of acronyms on their resume.

幸福%小乖 2024-12-16 00:03:48

如何启动新的 Web 应用程序项目在 Eclipse 中使用 Maven?

只需输入“archetype:generate”并选择 JSF + EJB/JPA(如果可用)。

这个看起来不错:360:远程 ->
org.jboss.weld.archetypes:weld-jsf-jee(用于创建焊接原型
使用 JSF 2.0、CDI 1.0、EJB 3.1 和 JPA 2.0 的 Java EE 6 应用程序
(包括持久性单元))

Appfuse 更加完整,可能会嵌入你永远不会的东西
使用并且您必须将其删除。

之后 mvn eclipse:eclipse 就可以在 eclipse 中加载项目了。

How to start a new web app project in Eclipse with Maven?

Just type "archetype:generate" and select JSF + EJB/JPA if available.

This one seems fine: 360: remote ->
org.jboss.weld.archetypes:weld-jsf-jee (Weld archetype for creating a
Java EE 6 application using JSF 2.0, CDI 1.0, EJB 3.1 and JPA 2.0
(persistence unit included))

The Appfuse are quite more complete and may embed stuff you will never
use and that you will have to remove.

After that mvn eclipse:eclipse to be able to load the project in eclipse.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文