Does Java EE 6 framework only for Web Application Or can I use it for Client Application as well

二次信任 提交于 2019-12-24 04:47:06

问题


I always use Jave EE 6 framework for web application. So I am not sure what I about to do is correct. I need to create an native client command-line application that has database access. So simple java Project with JDBC would do that job. But the requirements for db access include connection pool, concurrency handle, and transaction ..., Now the requirement of the projects does eventually build a web interface, but first it will build a command line application first. And this is when i am thinking about framework. I love Java EE 6. So does java EE 6 the right choice here? Can I use java EE 6 to develop native client application, and later add a web module to it?

I am using Netbeans 7.0 btw


回答1:


You can perfectly use JPA in a standalone client application with a main() class as entry point. Just add the JPA JAR(s) to the buildpath/classpath and configure the persistence.xml to use a RESOURCE_LOCAL transaction type. You can find kickoff examples in EclipseLink Wiki - Running JPA Outside Container. Here's an extract of relevance:

<persistence-unit name="LocalPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
        <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
        <property name="javax.persistence.jdbc.user" value="scott"/>
        <property name="javax.persistence.jdbc.password" value="tiger"/>
    </properties>
</persistence-unit>

You can reuse the client project with JPA models and eventual DAOs in the web project by adding the client project as a module of the web project. On Eclipse for example, you just have to add the client project to the buildpath of the web project by Java Build Path > Projects > Add and configure the Deployment Assembly to let it end up as JAR in /WEB-INF/lib.

Finally, in your web project you can have another persistence.xml which basically points the JAR file of the client project and overriddes the transaction type.

<persistence-unit name="WebPersistenceUnit" transaction-type="JTA">
    <jta-data-source>jdbc/DataSourceName</jta-data-source>
    <jar-file>lib/JavaProject.jar</jar-file>
</persistence-unit>

This way you don't need to repeat the model classes in persistence.xml.




回答2:


Well, JavaEE is a compilation of different frameworks (EJB, JSF, JAXP, JAXB, WS, ...). Not all of them need a full featured application server.

It really depends on your requirements (and your knowledge on the different frameworks), but with the web module request in mind, the following approach might be useful:

  • Model your data with Entity EJB
  • Create your business logic with Session Beans (or POJOs which can be easily migrated to EJB)
  • Use the required additional frameworks (e.g. JAXB)
  • Start with your command line application

If your applications becomes more and more complex or you need additional features (like persistence with JPA, transaction control with JTA or a web framework like JSF) you can consider to use a application server.




回答3:


There are a couple 'view' technologies in Java EE 6: web applications and application clients. The web application is the most common view technology used for Java EE 6, but you can create a 'native command-line' client of your EJBs and entity classes.

You can read about application clients in JSR-000316 Java Platform, Enterprise Edition 6 Specification 6.0 Final Release, section 'EE.10 Application Clients'.

There is an article that describes how to use NetBeans to create, deploy and execute a Java EE 6 application that uses an application client.

One of the primary impediments to the adoption of application clients has been burden of deploying them to desktops across a large number of clients. The GlassFish implementation of the Java EE 6 spec includes features that help lower these burdens.




回答4:


It is not meant to build native client applications. What you are looking for would be Swing or RCP.



来源:https://stackoverflow.com/questions/6347788/does-java-ee-6-framework-only-for-web-application-or-can-i-use-it-for-client-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!