栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Maven中指定额外的源/资源文件夹,以便IDE知道它们?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Maven中指定额外的源/资源文件夹,以便IDE知道它们?

这是我的方法。

基本上,我声明了要在默认配置下在Eclipse中看到的所有资源文件夹(由于在配置文件处于活动状态时,将节点附加到最终POM而不是(我认为)替换现有的);然后我告诉Maven使用属性从哪个文件夹复制资源,属性的值由活动配置文件驱动。

任何评论,当然,非常感谢!

<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/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>...</groupId>    <artifactId>...</artifactId>    <version>...</version>    <packaging>war</packaging>    <name>...</name>    <!-- My prerequisite was that when working in Eclipse no extra steps          should be required to make the IDE use the right configuration than         Configure -> Convert to Maven Project, so I didn't like having          default settings in a profile that must be enabled in Eclipse project         configuration -->    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <war-name>/</war-name>        <!-- These solve the problem: AFAICT, each <resource /> is added to the final POM,  so declaring a resources folder in a profile didn't exclude other resources   folders declared in the default (i.e. without profiles active) configuration.  So, the solution is to change what Maven brings in from each folder depending  on the profile currently active. What follows is the default, no-profile  active configuration. -->        <res.devel.includes>**/*</res.devel.includes>        <res.devel.excludes></res.devel.excludes>        <res.local.includes></res.local.includes>        <res.local.excludes>*</res.local.excludes>        <res.release.includes></res.release.includes>        <res.release.excludes>*</res.release.excludes>    </properties>    <build>        <resources><!-- Here I declare all the resources folders, so that they will all be shown in Eclipse. Property values drive what is included and excluded. --> <resource><!-- This is the default Maven main resource directory -->     <directory>${basedir}/src/main/resources-local</directory>     <filtering>true</filtering>     <includes>         <include>${res.devel.includes}</include>     </includes>     <excludes>         <exclude>${res.devel.excludes}</exclude>     </excludes> </resource> <resource><!-- This is the resources directory for when the WAR is deployed on a local standalone Tomcan installation (useful for web pages editing) -->     <directory>${basedir}/src/main/resources-local</directory>     <filtering>true</filtering>     <includes>         <include>${res.local.includes}</include>     </includes>     <excludes>         <exclude>${res.local.excludes}</exclude>     </excludes> </resource> <resource><!-- This is the resource directory for when the WAR will be deployed -->     <directory>${basedir}/src/main/resources-release</directory>     <filtering>true</filtering>     <includes>         <include>${res.release.includes}</include>     </includes>     <excludes>         <exclude>${res.release.excludes}</exclude>     </excludes> </resource>        </resources>        <plugins> <!-- Plugins configurations -->        </plugins>    </build>    <dependencies>        <!-- Dependencies declarations -->    </dependencies>    <profiles><!-- Here are the profiles. When working in Eclipse no profile is active, so the resources will be taken only from src/main/resources (as per default properties values). -->        <profile> <id>local</id><!-- This is for when the WAR is deployed on a local standalone Tomcat instance (i.e. outside of Eclipse) --> <properties>     <war-name>ROOT</war-name>     <!-- The resources will be taken only from src/main/resources-local -->     <res.devel.includes></res.devel.includes>     <res.devel.excludes>*</res.devel.excludes>     <res.local.includes>*</res.local.includes>     <res.local.excludes></res.local.excludes>     <res.release.includes></res.release.includes>     <res.release.excludes>*</res.release.excludes> </properties>        </profile>        <profile> <id>release</id><!-- This is for when the WAR is deployed on the production server --> <properties>     <war-name>ROOT</war-name>     <!-- The resources will be taken only from src/main/resources-release -->     <res.devel.includes></res.devel.includes>     <res.devel.excludes>*</res.devel.excludes>     <res.local.includes></res.local.includes>     <res.local.excludes>*</res.local.excludes>     <res.release.includes>*</res.release.includes>     <res.release.excludes></res.release.excludes> </properties>        </profile>    </profiles></project>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/496491.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号