java Maven中资源文件夹的用途是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25786185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the purpose for the resource folder in Maven?
提问by Elijah
Using Eclipse that was being used prior on the project by another developer. Most things are flagged as red and broken. Seeing files in
src/main/java/...
and the same exact files over in
java resources/src/main/java...
使用其他开发人员之前在项目中使用过的 Eclipse。大多数东西都被标记为红色和破损。src/main/java/...
在java中查看文件
和相同的文件resources/src/main/java...
Just confused over what is what, what is temp, what to keep to trash or how to fix the project environment.
只是对什么是什么、什么是临时、什么要保留垃圾或如何修复项目环境感到困惑。
Any easy fix to this?
有什么简单的解决方法吗?
采纳答案by Dave Newton
There's no standard for anything at the rootlevel called resources
.
根级别的任何东西都没有标准,称为resources
.
src/main/resources
is normally where you put non-Java artifacts that should be moved into the normal package hierarchy, like XML config files loaded as classpath resources.
src/main/resources
通常是放置非 Java 工件的地方,这些工件应该移动到正常的包层次结构中,例如作为类路径资源加载的 XML 配置文件。
It's impossible to help much beyond that, other than to say "check your Maven file to see if anything actually references those files", particularly if anything generates files to there, or moves them there as part of an assembly process, but again, that would be non-standard Maven usage.
除了说“检查您的 Maven 文件以查看是否有任何内容实际引用了这些文件”之外,无法提供更多帮助,特别是如果任何内容生成文件到那里,或将它们作为组装过程的一部分移动到那里,但同样,那将是非标准的 Maven 用法。
回答by prem
Your question's has multiple answer since they already exists everywhere and easy to get them I am just pointing you to them with links and little description.
你的问题有多个答案,因为它们已经存在于任何地方并且很容易得到它们我只是通过链接和很少的描述将你指向它们。
What is Maven ?
什么是Maven?
- Maven is a build tool,it helps to manage dependencies (jars) easily and efficiently.
- Maven does everything what ANT can do,even it has plugin to do some specific ANT activities.
- Very easy to migrate from third-party library.
- Unit testing also bit easy to configure,overall configuration is very simple.
- Maven 是一个构建工具,它有助于轻松高效地管理依赖项(jar)。
- Maven 做 ANT 能做的一切,甚至它有插件来做一些特定的 ANT 活动。
- 很容易从第三方库迁移。
- 单元测试也有点容易配置,整体配置很简单。
For more information -> http://maven.apache.org/what-is-maven.html
有关更多信息-> http://maven.apache.org/what-is-maven.html
Why Maven ?
为什么是 Maven?
Why resources directory ?
为什么是资源目录?
Before maven exists we used to have resources package within application,which will actually contain some application configuration properties file,Internalization property files , XML files (basically non java files which are required for application run-time ).
在 maven 存在之前,我们曾经在应用程序中有资源包,它实际上会包含一些应用程序配置属性文件、内部化属性文件、XML 文件(基本上是应用程序运行时所需的非 java 文件)。
One case study i were been using Resource directory
我一直在使用资源目录的一个案例研究
In our company we wanted have different property values for development,staging, pre-production,production environment.So we had four directories and Resources folder saying environment name.Each directory will contain its own property files and properties.During maven build we should mention which profile is this build for ?.Based upon that only specific resource files are loaded in the deployment assembly.
在我们公司,我们希望为开发、暂存、预生产、生产环境设置不同的属性值。所以我们有四个目录和 Resources 文件夹,上面写着环境名称。每个目录将包含自己的属性文件和属性。在 maven 构建期间,我们应该提到此构建用于哪个配置文件?.基于在部署程序集中仅加载特定资源文件。
More information about profile in maven -> http://maven.apache.org/guides/introduction/introduction-to-profiles.html
有关 maven 中的配置文件的更多信息 -> http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Eclipse error's solving
Eclipse 错误的解决
And your eclipse is having red flags you need to fix the build path issues,if it gets the respective source code.Red flags will be vanished.Since you didn't mention what errors you are seeing i am placing general discussion on build path fixing - > Problem with Java Buildpath in Eclipse
并且您的 eclipse 有红旗,您需要修复构建路径问题,如果它获得相应的源代码。红旗将消失。由于您没有提到您看到的错误,我正在对构建路径修复进行一般性讨论-> Eclipse 中 Java Buildpath 的问题
回答by DeepInJava
Go to your Project folder e.g. MyProject in command Prompt
在命令提示符中转到您的项目文件夹,例如 MyProject
run below commands one by one (assuming you have installed maven in your system)
一一运行下面的命令(假设你已经在你的系统中安装了 maven)
cd C:\MyWorkSpace
cd MyProject
mvn clean install -DskipTests=true
mvn eclipse:eclipse
and then right click your project and click Refresh
然后右键单击您的项目并单击刷新
That might solve your problem.
那可能会解决您的问题。