简体   繁体   English

打包成jar文件后Java应用程序无法正常工作

[英]Java Application not working after Packaging into jar file

I had a java app working properly by Intellij IDEA but not working after packaging into jar file 我有一个Java应用程序可以通过Intellij IDEA正常工作,但打包到jar文件后无法正常工作

what are the possible causes ? 可能的原因是什么? and how can I find the mistake ? 以及如何找到错误?

the app is a gradle project ( libgdx ) and I packaged it by command line gradlew desktop:dist 该应用程序是gradle项目( libgdx ),我通过命令行gradlew desktop:dist打包了它

it give me this 它给我这个

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRun timeException: Error reading file: json\levels.json <Absolute>
at com.badlogic.gdx.files.FileHandle.read<FileHandle.java:144>

After packaging the application JAR file, is the JSON file part of the JAR? 打包应用程序JAR文件后,JSON文件是JAR的一部分吗? Then you have to change the way of accessing the file. 然后,您必须更改访问文件的方式。 You can't access a file through an absolute file path, but instead you should use 您不能通过绝对文件路径访问文件,而应使用

InputStream in = ClassLoader.getSystemResourceAsStream("path/to/file/in/jar")

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM