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.