简体   繁体   English

从intellij idea IDE运行时使用jar文件资源

[英]Use jar file resource while running from intellij idea IDE

I have a java project that uses a resource file that is put into the jar file. 我有一个Java项目,该项目使用放入jar文件中的资源文件。 All runs well while starting it with java -jar app.jar. 使用java -jar app.jar启动它时,所有程序运行良好。 But running it from a IDE, it doesn't find the file. 但是从IDE运行它时,找不到文件。

Is it possible to run and debug the project from the IDE? 是否可以从IDE运行和调试项目?

Just in case anyone is still looking I solved this by creating the jar as an artefact. 以防万一有人还在寻找,我通过将罐子制成人工制品解决了这个问题。

To get the resources I use -jar path/to/my.jar in VM options in Edit configurations in the Run menu. 为了获得资源,我在“运行”菜单的“编辑配置”中的VM选项中使用-jar path / to / my.jar。

Goto "open module setting" by right clicking the project. 通过右键单击项目转到“打开模块设置”。 add the jar as a library in project setting. 在项目设置中将jar添加为库。 go to dependency tab of the module and add that. 转到模块的依赖项标签并添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 JAR 时出现 ClassNotFoundException,在 IntelliJ IDEA 中运行时没有错误 - ClassNotFoundException upon running JAR, no errors while running in IntelliJ IDEA 将jar文件导入IntelliJ Idea? - Importing jar file into IntelliJ Idea? 在从 Intellij IDEA 创建的 jar 文件中播放 .wav 时遇到问题 - Trouble with .wav playing in jar file created from Intellij IDEA 在 Intellij Idea 中从全局 JAR 文件中搜索字符串 - Search string from JAR file global in Intellij Idea 如何在运行 java 文件时在工具提示上显示结果 - IntelliJ IDEA - How to show the result on Tooltip while running java file - IntelliJ IDEA 如何通过IntelliJ Idea中的xml文件通过路径导航到资源? - How to navigate to a resource by path from the xml file in IntelliJ Idea? 从 IntelliJ Idea 运行 Maven 目标时使用 IntelliJ Idea 模块类路径 - Use IntelliJ Idea module classpath when running Maven goal from IntelliJ Idea 在IntelliJ中从类路径之外的JAR加载资源文件 - Loading a resource file from a JAR, outside classpath, in IntelliJ 如何在IntelliJ IDEA中使用“自定义jar”? - How to use a “custom jar” in IntelliJ IDEA? 从我的类文件在IDE netbeans中运行jar文件 - running jar file from my class file in the IDE netbeans
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM