My LibGDX project runs in Eclipse but when I export it to an executable JAR file I get "Couldn't load file: play_button_inactive.png" and "File not found: play_button_inactive.png (Internal)".
I refreshed and cleaned the project. I deleted my assets link in the Desktop Project and re-loaded it in the Build Path but the same errors persisted.
I looked inside the jar file and Eclipse packaged in the assets separately into the Jar file so I put them all into a new "assets" folder manually but I got the same errors when I ran it. I used the command
java -jar fileName.jar
Here is my Build Path.
Thanks for any suggestions as to what I am doing wrong.
UPDATE: After reading around I found a solution which is to put all the assets into the same directory as the jar file. Is there any way to package them into the jar file?
I fixed the problem by not using Eclipse's jar file building tools and used gradlew desktop:dist instead.
This works perfectly and packages all resources and files into the generated jar file.
Related
I am trying to add external jars to my Java (without Maven) Project.
But I don't get it to work at all.
The official documentation: https://code.visualstudio.com/docs/java/java-project
says there are 2 ways to do it:
1."You can use the Java Dependency Viewer to add any JAR file to your project."
https://code.visualstudio.com/assets/docs/java/java-project/manage-dependencies.gif
As you can seee in the gif, the dev opens a "referenced libraries" folder.
This folder DOES NOT EXIST for me.
or 2."The other easy way to bring additional JAR files as dependencies is to create a lib/ folder in the root directory of the standalone files and place your JAR files there. Source for foo.jar is automatically detected if there is a foo-sources.jar in the lib/ folder."
https://code.visualstudio.com/docs/java/java-project/lib.mp4
I have the Jar file in the lib\ folder but it still shows me he same error messages.
Are there any steps I am missing?
As it says, place the external jar files in the ...\JAVArpg\lib folder.
So copy them from wherever you have them now. cp ../lib/*.jar lib/ is just an example.
You can use the Windows Explorer. You don't have to copy the files using a command-line.
I have a project where I open some XML files to read and edit information.
This works fine when running in the IDE (Netbeans) but fails when I am building the project and running the .jar file.
Is there a reason why this might not work?
The path of the project in Netbeans is
NetBeansProjects\project\src\data
but when I am running the jar file, this path is
NetBeansProjects\project\build\classes
However, when I create the files in this folder, they still cannot be opened.
The XML files need to be in the classpath when the jar file is executed.
You can give the classpath using -cp option when executing the jar file. Similar question was answered here as well - Run a JAR file from the command line and specify classpath
I created a miniTennis program,with Sounds files included in it. But when I am trying to build it from NetBeans (Creating jar file) , those sound files are automatically deleted from my classes folder and also they are not included in .jar file.
I have no idea ,what's the problem?
You probably have the usual (my src/ folder only should contain java sources) rule in your ant file.
Create a resources folder and mark it respectively. It should then be picked up when building a jar file.
I have a java desktop application in netbeans. I have created an executable jar file for the project using clean and build command provided by the netbeans. By using this command the executable jar file gets created under netbeansProjects//dist/.jar. I am able to execute this jar file from command line using java -jar .jar from within project path. But the problem is that when i move this jar outside of netbeans projects folder, say to desktop and run the jar file, it is giving error of type "Exception in thread "main" java.lang.NoClassDefFoundError". How to solve this problem and make the jar file executable from any location of the system.
Complete instructions may be found in dist/README.TXT:
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Ensure that the manifest inside of the jar file contains the necessary classpaths. If you are unfamiliar with the concept, go here: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Netbeans has probably included any external projects/libraries/Jars in the dist/lib folder.
In order to run the application, you must include all the files in the dist folder when you copy the application
Check if in your projects Manifest.mf file has the Attribute
"Main-Class" set to your projects current main Class file.
I am trying to create and use jar file in an Android project under Eclipse. I have tried various methods without any success. Here are the steps:
Create jar file from the source files jar -cf lib.jar *.java
Copy jar file to libs folder
Right click, Build Path->Add to Build path
Now, compiler gives unresolved symbols if I try to use a class from the jar file?
Can someone please let me know correct method to create and use an external jar file for the Android project under eclipse.
This worked fine for me:
1)Place Jars in assets folder.
2)Right click on project name.
3)Select properties.
4)Select Java build path.
5) Select Libraries.
6) Click Add Jars.