1

我尝试在http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin中使用 jetty-maven-plugin 启动 webapp 。但我想外部化我的环境配置文件。这是我的项目层次结构:

myapp-webapp
- src
- - test
- - - ressources
- - - java
- - main
- - - ressources
- - - java
- - - webapp
- - - - WEB-INF
- - - - META-INF
- - - - templates
- - - - ressources
- - - - index.xhtml
+ target (I don't detail it)
- configuration
- - local
- - - databaseLocal.properties
- - - ... others config files
- - dev
- - test
- - prod

这是我的 pom 文件:

<profiles>
    <profile>
    <id>myapp-work</id>
    <activation>
        <property>
            <name>!env</name>
        </property>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <webApp>
                        <contextPath>/</contextPath>
                        <extraClasspath>configuration/local/</extraClasspath>
                    </webApp>
                    <scanTargetPatterns>
                    <scanTargetPattern>
                      <directory>configuration/local/</directory>
                      <includes>
                        <include>**/*.xml</include>
                        <include>**/*.properties</include>
                      </includes>
                    </scanTargetPattern>
                  </scanTargetPatterns>
                </configuration>
                <dependencies>
                    <dependency>
                    ...
                </dependencies>
            </plugin>
            ...
        <plugins>

我正面临这个错误 2012-07-04 10:33:26.460:WARN::Failed startup of context JettyWebAppContext@29b829b8@29b829b8/,file:/C:/DEV/RTCworkspace/myapp/myapp-webapp/src/ main/webapp/,file:/C:/DEV/RTCworkspace/myapp/myapp-webapp/src/main/webapp/ org.springframework.beans.factory.BeanInitializationException: 无法加载属性;嵌套异常是 java.io.FileNotFoundException:类路径资源 [databaseLocal.properties] 无法打开,因为它不存在

我找到了很多信息,但没有任何效果: - http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin -无法在 Jetty + Spring + Tiles 部署中找到配置文件 - maven-jetty 插件没有使用正确的路径

我也尝试:${basedir}/${externalConfiguration.directory}

这是启动日志的摘录(我的 webapp 名称是 cct,直到现在我才替换它):

[INFO] webAppSourceDirectory C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp does not exist. Defaulting to C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp\WEB-INF\classes
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\database.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\databaseLocal.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\efrit-security.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\efrit.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\efrit_logback.xml
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\ldap.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\logback.properties
[INFO] Adding extra scan target from pattern: C:\DEV\RTCworkspace\cct\cct-webapp\configuration\local\logback.xml
[INFO] Context path = /
[INFO] Tmp directory = C:\DEV\RTCworkspace\cct\cct-webapp\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/C:/DEV/RTCworkspace/cct/cct-webapp/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = C:\DEV\RTCworkspace\cct\cct-webapp\src\main\webapp
[INFO] Starting jetty 7.1.6.v20100715 ...2012-07-04 11:16:56.349:INFO::jetty-7.1.6.v20100715

所以他说,他看到了我的配置文件,但他无法读取它。

4

2 回答 2

0

I try the precedent answer and it's not working. In fact , I found the problem. A profil hide a bean wich load this file. I had the profile and it's work well. It's an impact to spring 3.1 migration.

于 2012-07-04T13:24:35.543 回答
0

尝试设置:

<directory>configuration/local/</directory>

至:

<directory>${basedir}/configuration/local</directory>
于 2012-07-04T12:37:23.950 回答