java 客户端软件框架,Java EE 6框架仅用于Web应用程序还是我也可以将它用于客户端应用程序...

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

解决方案

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:

org.eclipse.persistence.jpa.PersistenceProvider

false

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.

jdbc/DataSourceName

lib/JavaProject.jar

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值