0

We have a parent project with multiple sub projects below. Some of them are producing a war and other are producing a jar.

Inside the parent project, there is a dev.properties file. It is in the directory

/src/main/resources/config/environments/dev.properties

This file is used by multiple subprojects correctly withour a problem.

The project that causes the error has the following configuration for jetty in pom.xml

<profiles>
    <profile>
        <id>jetty</id>
        <build>
            <finalName>${project.artifactId}</finalName>
            <plugins>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>maven-jetty-plugin</artifactId>
                    <version>6.1.16</version>
                    <configuration>
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        <stopPort>8005</stopPort>
                        <stopKey>STOP</stopKey>
                        <contextPath>/</contextPath>
                        <useTestClasspath>true</useTestClasspath>
                    </configuration>
                    <executions>
                        <execution>
                            <id>start-jetty</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <scanIntervalSeconds>0</scanIntervalSeconds>
                                <daemon>true</daemon>
                            </configuration>
                        </execution>
                        <execution>
                            <id>stop-jetty</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

</profiles>

This project references with dependency our admin project like this:

<dependency>
            <groupId>sample.project</groupId>
            <artifactId>sample-project-admin-service</artifactId>
            <version>0.1.0-SNAPSHOT</version>
        </dependency>

Inside the sample project and in the file sample-project-admin-service-context.xml there is this configuration :

<bean id="cacheMan"
        class="org.infinispan.spring.provider.SpringRemoteCacheManagerFactoryBean"
        p:configurationPropertiesFileLocation="/WEB-INF/classes/config/environments/${SERVER_ENV}.properties" />

This should read the properties file and initialize the cacheMan. The sample-project-admin-service-context.xml lies in the path:

/sample-project-admin-service/src/main/resources/META-INF/spring/flash-air-admin-service-context.xml

When we make a war file and deploy it to tomcat. the application deployes correctly without any problem. But when I try to load it with jetty I get the following error:

Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in class path resource [META-INF/spring/sample-project-admin-service-context.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/config/environments/dev.properties]:

Jetty maven is run using the command:

mvn install -Pjetty

any help would be appreciated.

thanks in advance

giannisapi
  • 2,641
  • 3
  • 24
  • 31

2 Answers2

0

At deployment time all file the are suited whitin the src/main/resources are packaged in the classpath. Then when the Ioc container tries to instantiate the cacheMan bean it wansn't able to locate it. The trouble is that you can't recover the file inside the parent at definition time because it has an opaque path Get reosurce in a modular project and the the only thing to do is:

  • Move the file from parent project in the sub-module project

and change the bean definition in this way.

if the path is

/src/main/resources/config/environments/dev.properties

your bean definition will be:

<bean id="cacheMan"
    class="org.infinispan.spring.provider.SpringRemoteCacheManagerFactoryBean"
    p:configurationPropertiesFileLocation="/config/environments/dev.properties" />

in this way the Ioc container is able to locate the file

Community
  • 1
  • 1
Skizzo
  • 2,883
  • 8
  • 52
  • 99
  • hi, thanks for your reply. The problem is that the file dev.properties is used by multiple projects and I do not think that it is a good practise to keep a copy of the file at every subproject. is there a way probably yo move the file at compile time with maven somehow? – giannisapi Jul 03 '14 at 06:38
  • @giannisapi Try to change only the path **p:configurationPropertiesFileLocation** leaving the file in the parent project, it should work – Skizzo Jul 03 '14 at 07:37
  • hi Skizzo, i already use p:configurationPropertiesFileLocation could you please explain a bit more what you mean? – giannisapi Jul 03 '14 at 08:02
  • @giannisapi Can you change the value to **p:configurationPropertiesFileLocation** from /WEB-INF/classes/config/environments/${SERVER_ENV}.properties to /config/environments/dev.properties and try to install your app, because all resources file will be packaged in the classpath – Skizzo Jul 03 '14 at 08:17
  • thanks again but I have already tryied that and it does not seem to work, I still get the sam error – giannisapi Jul 03 '14 at 08:37
  • it seems that changing the version of the plugin to 9.2.1.v20140609 solves the problem. – giannisapi Jul 03 '14 at 09:20
  • @giannisapi good job, remerber to tag the question like solved and to explain how to solved – Skizzo Jul 03 '14 at 09:35
0

Ok I seem to have solved the problem. The steps I followed are:

This is the final profile for jetty plugin:

<profile>
            <id>jetty</id>
            <build>
                <finalName>${project.artifactId}</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <version>9.2.1.v20140609</version>
                        <configuration>
                            <scanIntervalSeconds>10</scanIntervalSeconds>
                            <stopPort>8005</stopPort>
                            <stopKey>STOP</stopKey>
                            <contextPath>/</contextPath>
                            <useTestClasspath>true</useTestClasspath>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-jetty</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <scanIntervalSeconds>0</scanIntervalSeconds>
                                    <daemon>true</daemon>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-jetty</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

As you can see I have changed the verion to 9.2.1.v20140609. This seems to have solved the problem.

Thank you

giannisapi
  • 2,641
  • 3
  • 24
  • 31