Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven doesn't generate the "persistence.xml" file

Tags:

java

maven-2

jpa

I read this article on the maven project web page that lists the different directory layouts (like: src/main/resources which is for Application/Library resources).

The problem is that when I run the following command (found here):

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

the src/main/resources/META-INF directory isn't created. It's important for me because I'd like to reach the "persistence.xml" that is found in that directory.

Should I add an option in the mvn command? How can I automatically generate the "src/main/resources" that contains the "META-INF/persistence.xml" file?

Thank you, Regards

like image 409
Zakaria Avatar asked Aug 17 '10 21:08

Zakaria


3 Answers

The problem is that when I run the following command (...) the src/main/resources/META-INF directory isn't created. It's important for me because I'd like to reach the "persistence.xml" that is found in that directory.

The maven quickstart archetype does NOT create src/main/resources nor src/test/resources. There are several explanations:

  • As stated by its name, this archetype allows to quickstart a project, it's up to you to shape it.
  • Why should this archetype create src/main/resources and not, say, src/main/assembly?
  • Creating empty directories was actually not possible during a long time (see ARCHETYPE-57).

In other words, just add src/main/resources/META-INF/persistence.xml manually if you use this archetype.

Should I add an option in the mvn command? How can I automatically generate the "src/main/resources" that contains the "META-INF/persistence.xml" file?

You can't with this archetype - and I don't really understand why this is a such big issue.

There is a JPA archetype though:

mvn archetype:create \
  -DgroupId=com.mycompany.project \
  -DartifactId=my-project-domain \
  -DpackageName=com.company.project.domain \
  -DarchetypeGroupId=com.rfc.maven.archetypes \
  -DarchetypeArtifactId=jpa-maven-archetype  \
  -DarchetypeVersion=1.0.0  \
  -DremoteRepositories=http://maven.rodcoffin.com/repo

That creates the following bootstrap JPA project:

$ tree my-project-domain/
my-project-domain/
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── company
    │   │           └── project
    │   │               └── domain
    │   │                   └── User.java
    │   └── resources
    │       └── META-INF
    │           └── persistence.xml
    └── test
        ├── java
        │   └── com
        │       └── company
        │           └── project
        │               └── domain
        │                   ├── DbUnitDataLoader.java
        │                   └── UserTest.java
        └── resources
            └── user.db.xml

16 directories, 6 files
like image 156
Pascal Thivent Avatar answered Nov 18 '22 14:11

Pascal Thivent


Don't be too dependant on maven doing things for you. These archetypes are just there to provide basic templates. If they don't create a file for you, just go ahead and create it yourself.

like image 45
drekka Avatar answered Nov 18 '22 15:11

drekka


Here you used the quickstart archetype which is the sample, more informations here. If you want a Java EE standard layout you shoud use the maven-archetype-j2ee-simple archetype :

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-j2ee-simple -DinteractiveMode=false
like image 1
Colin Hebert Avatar answered Nov 18 '22 16:11

Colin Hebert