maven - 为什么Maven在构建过程中不复制属性文件?

标签 maven java-ee-6 resourcebundle

我发现没有什么能够帮助我解决这一具体情况。我最近从一个普通的旧Java Web应用程序项目(正在运行)切换到一个Maven Web项目。我收到以下运行时异常:

java.util.MissingResourceException: Can't find bundle for base name com.myapp.config, locale en


我正在使用Netbeans创建JSF 2.0,Spring和Hibernate Web应用程序。我有以下目录结构:


src \ main \ java \ com \ myapp包含config.properties
src \ main \ resources空
target \ myapp \ WEB-INF \ classes \ com \ myapp包含没有config.properties的已编译类文件
src \ main \ java \ com \ myapp包含config.properties


检查目标文件夹中的WAR文件不会显示属性文件的任何迹象,因此就好像Maven构建插件未在属性文件上进行复制一样。我知道您可以在pom内放置一个标签,但对我不起作用。下面的链接提到在构建过程中资源文件夹(对我来说是空的)包含其内容,但是如果是这种情况,您如何从Netbeans中进行操作?我只希望将属性文件与war打包在一起,以便在将其部署到服务器时可以访问。
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>myapp</name>
<url>http://maven.apache.org</url>
<repositories>
    <repository>
        <id>java.net</id>
        <name>Repository hosting the Java EE 6 artifacts</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-hibernate3</artifactId>
        <version>2.0.8</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.1.8</version>
    </dependency>
    <dependency>
        <groupId>net.authorize</groupId>
        <artifactId>java-anet-sdk</artifactId>
        <version>1.4.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.15</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
    <finalName>${artifactId}</finalName>
</build>
<profiles>
    <profile>
        <id>endorsed</id>
        <activation>
            <property>
                <name>sun.boot.class.path</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <!-- javaee6 contains upgrades of APIs contained within the JDK itself.
                             As such these need to be placed on the bootclasspath, rather than classpath of the
                             compiler.
                             If you don't make use of these new updated API, you can delete the profile.
                             On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.-->
                        <compilerArguments>
                            <bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
                        </compilerArguments>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>javax</groupId>
                            <artifactId>javaee-endorsed-api</artifactId>
                            <version>6.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<properties>
    <netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
</properties>

最佳答案

您的项目在Netbeans中配置的构建路径是什么?您可以尝试将其更改为src/main/webapp/WEB-INF/classes。这样,从src/main/java文件夹编译的类文件以及在src/main/resources下拥有的所有资源都应包含在生成的WAR中。如果将config.properties文件放在src/main/resources文件夹下,则可以访问它。

您还可以检查pom.xml中的任何includes部分,并确保您不会意外地排除某些内容(如果您明确包含某些内容,则可能会隐式排除其他所有内容)。

关于maven - 为什么Maven在构建过程中不复制属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527100/

相关文章:

java - 如何使用 swagger-jaxrs-doclet 的输出来生成 swagger 文档?

java - 在 Maven 程序集中包含共享对象

java - 无法将 '' 下的属性绑定(bind)到 com.zaxxer.hikari.HikariDataSource : spring boot 2. 4.1

java - 在 Java Swing 应用程序中实现 WebSocket

java - @Startup @Singleton 在 WebLogic (EJB 3.1) 中实例化了两次

java - JSF 以清晰的方式显示条件文本

java - 应用引擎始终更新LocalIOException

android - 为什么gradle android插件不为intellij idea模块生成依赖项

java - 如何在未运行的情况下检查从 ResourceBundle 调用的字符串是否存在?

java - 如何从动态插入属性文件/资源​​包中的键值中的数字中删除逗号?