在 Eclipse 中创建 META-INF/services 文件夹
我正在尝试用 Java 创建一个可扩展的应用程序并选择使用 SPI。根据这个 教程 我正在关注,我应该创建我的 jar 中的 META-INF/services 中的特定文件,但不知道如何。 我知道如何使用 META-INF
创建 jar,但找不到如何创建 services
文件夹以及此文件夹中的特定文件的方法。 (我正在使用Eclipse)
感谢您的帮助。
I am trying to create an extensible app in Java and chose to use SPI. According to this tutorial I am following, I am supposed to create a specific file in META-INF/services
in my jar, but don't know how.
I know how to create jar with META-INF
, but can't find a way how to create the services
folder and particular file in this folder. (I am using Eclipse)
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于本教程指导手动创建它,而不是使用 ant 或 maven 或其他构建工具,因此只需在根级别创建一个名为 META-INF 的文件夹,并创建一个名为 services< 的子文件夹。 /em> 和一个名为 MANIFEST.MF 的文件。
我不确定您打算如何执行您的 jar 文件,现在您只需将这一行放入您的
MANIFEST.MF
中:对于您的 services 文件夹,您需要创建一个名为
的文件com.example.dictionary.spi.Dictionary
具有教程中提到的以下一行内容:-仅供参考 - META-INF 是一个内部 Java meta目录。通常,您希望依靠 ant 或 maven 等打包工具来构建 META-INF 文件夹的内容,而不是自己完成。
您可以查看 META-INF 文件夹内容的详细信息 此处:-
Since the tutorial is instructing to create it manually rather than using ant or maven or other build tools then just create a folder named META-INF at the root level with a sub-folder named services and a file called MANIFEST.MF.
I am not sure how you plan to execute your jar file, for now you can just put this one line in your
MANIFEST.MF
:For your services folder, you need to create a file named
com.example.dictionary.spi.Dictionary
with the following one line content as mentioned in the tutorial:-FYI - META-INF is an internal Java meta directory. Generally, you want to rely on your packaging tool such as ant or maven to build the content of META-INF folder rather than doing it by yourself.
You can see the details on the content of META-INF folder here:-
假设您正在使用 Apache 的 Ant 构建 jar 文件,您需要添加一个 metainf 文件集,或者更好,使用像这样的服务指令
如果您不使用apache的Ant,那么您需要将一个文件添加到您的jar中
,其中包含服务实现的名称
如果您使用Eclipse下的“可运行Jar文件导出”生成JAR文件项目中,选择“另存为ANT脚本”,然后修改ant脚本以将其打包到服务中,如上所述。
Assuming you are building your jar file with Apache's Ant, you need to add a metainf fileset, or better yet, use a services directive like so
If you don't use apache's Ant, then you need to add a file to your jar
which contains the name of the service's implementation
If you are generating the JAR file using Eclipse's "Runnable Jar file export" under the project, select "save as ANT script" and then modify the ant script to pack in the services as described above.