You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Colin Young <co...@travelgator.com> on 2007/04/14 13:56:03 UTC

Problems with Maven, Hibernate and Spring

I'm building a project that uses Spring and Hibernate with Maven. So far
I've been able to get a jar of just my project or a jar of everything
with dependencies (using assembly:assembly). Unfortunately, when I do
the with dependencies build, I'm getting errors from Spring trying to
find the Hibernate mapping files inside the jar. They are in the same
location inside the jar as in the non-dependency jar (and the same as
the manually built jars from the pre-Maven builds). I'm using the
standard Maven directory structure for my project.

Is there something special about the with dependency jars? Is there a
special way I need to specify the classpath? Previously I was able to
just specify the jar as part of the classpath, but that doesn't seem to
be working for the Maven-built jar.

Also, the assembly:assembly build is placing my Spring xml configuration
and properties files inside the jar. I'm having a bit of trouble
figuring out how to configure my pom to achieve that, since the
documentation is a bit sparse. Does someone have an example of how to do
that?

Thanks

Colin



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problems with Maven, Hibernate and Spring

Posted by Trevor Torrez <ja...@gmail.com>.
You should be referencing the hibernate mappings as
"classpath:/path/to/**/*.hbm.xml".  Having a path is imoprtant -- do
not just dump the config files for spring or hibernate in the top
level of src/main/resources; then in the resource location specify at
least one folder in the "package" structure before using any
wildcards; this is to work around a known issue with the JVM and
wildcard pattern matching.  See the documentation for the pattern
matcher (http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html).
 Note in Spring 2.x you should be using "classpath*:/etc/etc", not
just "classpath:".

As for leaving the config outside the jar for assemblies, configure
the assembly profile as follows:

Several tricks are used to achieve the result:
* The main resources go to (effectively) target/config
* The main classes still go to target/classes
* The jar plugin is explicitly told to only include the classes
* The surefire plugin is told to skip tests
* The assembly plugin is configured as normal.

The reason that you cannot run tests is because the normal configs (if
your tests rely on them) are no longer in the classapth, and there is
no way I can figure to get maven to add an "arbitrary" folder to the
classpath (despite the build being told where the resources are :-/ ).
 Because this is an abberation, the assembly execution cannot coincide
with the "normal" development execution.

Anyway, here's the pom:

    <profile>
      <id>assembly</id>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <targetPath>../config</targetPath>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>jar</goal>
                </goals>
                <configuration>
                  <classesDirectory>target/classes</classesDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>assembly</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <descriptors>
                <descriptor>src/assembly/dos.xml</descriptor>
              </descriptors>
              <outputDirectory>target/artifacts</outputDirectory>
              <workDirectory>target/assembly/work</workDirectory>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>


See the documentation on the maven assembly plugin for how to create assemblies.

-t.

On 4/14/07, Colin Young <co...@travelgator.com> wrote:
> I'm building a project that uses Spring and Hibernate with Maven. So far
> I've been able to get a jar of just my project or a jar of everything
> with dependencies (using assembly:assembly). Unfortunately, when I do
> the with dependencies build, I'm getting errors from Spring trying to
> find the Hibernate mapping files inside the jar. They are in the same
> location inside the jar as in the non-dependency jar (and the same as
> the manually built jars from the pre-Maven builds). I'm using the
> standard Maven directory structure for my project.
>
> Is there something special about the with dependency jars? Is there a
> special way I need to specify the classpath? Previously I was able to
> just specify the jar as part of the classpath, but that doesn't seem to
> be working for the Maven-built jar.
>
> Also, the assembly:assembly build is placing my Spring xml configuration
> and properties files inside the jar. I'm having a bit of trouble
> figuring out how to configure my pom to achieve that, since the
> documentation is a bit sparse. Does someone have an example of how to do
> that?
>
> Thanks
>
> Colin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org