tags:

views:

46

answers:

3

Hi everybody,

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

+1  A: 

Here you used the quickstart archetype which is the sample, more informations here. If you want a JEE 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
Colin Hebert
+2  A: 

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
Pascal Thivent
@downvoter Care to explain why this answer deserves a downvote? Can you please show me what part of this answer is incorrect?
Pascal Thivent
+2  A: 

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.

Derek Clarkson