久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我應該把我的文件放在哪里以便在我運行 jar 時能

Where should i place my files in order to be able to access them when i run the jar?(我應該把我的文件放在哪里以便在我運行 jar 時能夠訪問它們?)
本文介紹了我應該把我的文件放在哪里以便在我運行 jar 時能夠訪問它們?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我將一些對象存儲在文件中,并且在 Netbeans 控制臺中一切正常.但是當我通過命令行(java -jar myapp.jar)運行 JAR 時,我得到了這個:

I store some objects in files and everything works fine in Netbeans console. But when i run the JAR through the command line (java -jar myapp.jar) i get this:

我應該將文件放在哪里才能通過命令行運行應用程序?

Where should i place the files in order to be able run the app through the command line?

推薦答案

答案將取決于您是否要寫入文件...

The answer will depend on if you want to write to the files or not...

確保文件相對于 Jar 文件放置并使用相對路徑.這樣做的問題是,如果執行上下文與存儲 jar 和文件的目錄不同,您將無法再次找到它們...

Ensure that the files are placed relative to the Jar file and use a relative path. The problem with this is if the execution context is not the same directory as where the jar and files are stored, you won't be able to find them again...

這也將取決于您的構建過程,以確保將所有需要的文件復制到 Jar 的構建位置

This will also be dependent on your build process to make sure that any required files are placed copied to the build location of the Jar

將文件放在眾所周知的位置,例如,在 Windows 上您可以使用 {user.home}/AppData/Local/{application name} 或在 Mac 上您可以使用 {user.home}/Library/Application Support/{application name} 并將文件放在這里,然后您可以使用文件的絕對路徑

Place the files within a well know location, for example, on Windows you could use {user.home}/AppData/Local/{application name} or on Mac you could use {user.home}/Library/Application Support/{application name} and place the files here, then you could use an absolute path to the files

這可能會成為安裝問題,因為您需要確保在安裝應用程序時將所有所需文件復制到所需位置.

This likely becomes an installation issue, as you need to ensure that any required files are copied to the required location when the application is installed.

如果文件是在運行時自動生成的,那么您只需要確保目錄存在,如果不存在則創建它們

If the files are auto generated at runtime, then you just need to make sure the directories exists and make them if they don't

將文件存儲在 Jar 上下文(也稱為嵌入式資源)中,執行此操作的方式取決于您的 IDE 和構建過程,例如,在 Netbeans 中,您可以將文件復制到 src 目錄,它們將自動包含在生成的 Jar 文件中.我相信 Eclipse 可以以同樣的方式工作.但是,如果您使用 Maven,則需要將文件放入 resources 目錄中.

Store the files within the Jar context (AKA embedded resources), the means by which you do this will depend on your IDE and build process, for example, in Netbeans, you can copy files into the src directory of your project and they will automatically be included in the resulting Jar file. I believe that Eclipse can work the same way. However, if you're using Maven, you will need to place the files into the resources directory instead.

然后您可以使用 Class#getResourceClass#getResourceAsStream 取決于你的需要.

You would then access these resources using Class#getResource or Class#getResourceAsStream depending on your needs.

這將使資源只讀.

這篇關于我應該把我的文件放在哪里以便在我運行 jar 時能夠訪問它們?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 亚洲精品视频在线播放 | 日韩高清中文字幕 | 日韩欧美一二三区 | 国产91一区 | 久久久久久久一区 | av日韩在线播放 | 欧美aⅴ在线观看 | 亚洲一区二区三区四区五区午夜 | 香蕉久久网 | 欧美精品一区二区三区四区 | 国产福利在线 | 国产精品jizz在线观看老狼 | 久久久精品视频免费 | 亚洲精品亚洲人成人网 | 欧美日韩综合 | 日日夜夜天天 | 我要看黄色录像一级片 | 91麻豆产精品久久久久久夏晴子 | 亚洲激精日韩激精欧美精品 | 亚洲欧美一区二区三区国产精品 | 久久av一区二区 | 成人视屏在线观看 | 国产精品视频一区二区三区四蜜臂 | 国产丝袜一区二区三区免费视频 | 夜夜爽99久久国产综合精品女不卡 | 日本涩涩网 | 在线中文视频 | 国产精品久久久久久久免费大片 | 色综合久久天天综合网 | 日韩一区二区免费视频 | 91久久精品视频 | 黄色网毛片 | 成人影院网站ww555久久精品 | 久久国产日韩欧美 | 伊人二区 | 亚洲国产精品一区二区三区 | 国产精品99久久免费观看 | 国产精品一区二区三区四区 | 国内自拍偷拍视频 | 成人免费在线视频 | 国产精品国产三级国产aⅴ中文 |