我在哪里把 META-INF 放在 Eclipse 中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9998360/
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
Where do I put META-INF in Eclipse?
提问by user1258361
I'm using the Kundera tutorial at https://github.com/impetus-opensource/Kundera/wiki/Getting-Started-in-5-minutes. Eclipse does not find it when I create a folder META-INF at the project root and place persistence.xml in it.
我在https://github.com/impetus-opensource/Kundera/wiki/Getting-Started-in-5-minutes使用昆德拉教程。当我在项目根目录下创建一个文件夹 META-INF 并将 persistence.xml 放入其中时,Eclipse 没有找到它。
I did a quick search and there was no real solution posted.
我进行了快速搜索,但没有发布真正的解决方案。
There is no valid reason why a simple file path should be difficult to configure. I'm looking for a simple answer to what should be a simple issue.
没有正当理由说明为什么一个简单的文件路径很难配置。我正在寻找一个简单的答案来解决什么应该是一个简单的问题。
回答by JB Nizet
It shouldn't be at the project root, but directly under the source folder.
它不应该在项目根目录下,而是直接在源文件夹下。
At runtime, the persistence.xml file is searched in the classpath, under META-INF. So if you want the META-INF folder to be put at the top of the compiled package tree, you need to put it at the top of the source tree. Eclipse copies every non-Java file to its output directory (bin, by default), respecting the package/folder hierarchy.
在运行时,在类路径中的 META-INF 下搜索 persistence.xml 文件。所以如果你想让 META-INF 文件夹放在编译好的包树的顶部,你需要把它放在源代码树的顶部。Eclipse 将每个非 Java 文件复制到其输出目录(默认情况下为 bin),尊重包/文件夹层次结构。
回答by vivek mishra
Basically it has to be in your classpath(under /META-INF/
). You can manually enable it in eclipse by configuring properties. If your project is maven based, then it should be automatically picked from /src/main/resources/META-INF/
folder (provided entities are under the same hood).
基本上它必须在你的类路径中(在 下/META-INF/
)。您可以通过配置属性在 Eclipse 中手动启用它。如果您的项目是基于 Maven 的,那么它应该自动从/src/main/resources/META-INF/
文件夹中选取(前提是实体在同一引擎盖下)。
回答by Lucky
It should be under src/main/resources
directory,
它应该在src/main/resources
目录下,
The full path will be /src/main/resources/META-INF/persistence.xml
完整路径将是 /src/main/resources/META-INF/persistence.xml
After creating the META-INF folder under resources directory and having a persistence.xml file loads the entityMangerFactory bean properly,
在资源目录下创建 META-INF 文件夹并有一个 persistence.xml 文件正确加载 entityMangerFactory bean 后,
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
The above line reads the path correctly.
上面的行正确读取路径。
回答by dellasavia
If you are using Eclipse, right-click on 'src' folder, choose 'Build Path', then 'Use as Source Folder'
如果您使用的是 Eclipse,请右键单击“src”文件夹,选择“构建路径”,然后选择“用作源文件夹”