Settings file (settings.json) does not compile along with my program - java

So I have a program which allows you to edit a couple settings through a "settings.json" file as seen here: https://prnt.sc/jzx8p8
My problem is that this file seems to not compile along with my program, as seen here: https://prnt.sc/jzx8t2
(If you're wondering I have that error message pop up myself: https://prnt.sc/jzx8y2)
I am using IntelliJ's artifact support to compile my program.
Help is appreciated, thanks!
Edit: The program runs 100% as it should when I run it through IntelliJ but not when I try to run it through my VPS.

Your json file is not in the classpath and thus is not visible. Move it into resources folder and that should work

You are loading it from the working directory as a file, not as a resource from the classpath. Either specify/calculate the full file path so that it works on any system or change your code to load the resource from the classpath and move the file into resources directory.

Related

Java: could not find or load main class main - not sure why

I am trying to upload a .jar file onto eclipse in order to be able to edit it.
The purpose of the .jar file is to track player coordinates on minecraft.
I have decompiled this .jar file on Eclipse, using the eclipse Java Decompiler.
However, when I try to run this decompiled code, I am getting the error: 'Could not find or load main class main'.
This happens when I try to run the 'decompiled code' by creating a run configuration and specify the main class: 'main'.
I have looked at other forums on this topic and have tried different things without success. However, none of these options have worked.
The decompiled 'main.class' file is currently stored within the 'JRE system library' folder. Is this the wrong place to store it?
I would be so grateful for a helping hand!
I have provided an image of the decompiled code:
And the run configuration tab, where I specify how I want the code to run.
I have now created a plugin using 'Maven', which allows me to edit the code given that to use Bukkit as an API requires the tool 'Maven'.
https://bukkit.fandom.com/wiki/Plugin_Tutorial_(Eclipse)#Example_Files_and_Templates
Thanks so much for the help :)

Problems exporting, File not loading from project

What's going on is that I have my images and .wav files in a a project folder and it's running fine in eclipse, however once I export it into a executable jar file it stops loading images. I've tried Extracting libraries into jar file and I've tried packaging them in a jar file. What do I do? I'm panicking because I need to get this ready by tomorrow! I know I have the path right, it's starts the code, but stops after a little.
I get this error:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings:
AdventureQuestv4.0.2/src/adventureQuestv/AdventureQuestMain.java
Here's the code I use to load an image
URL GiantT2 = AdventureQuestBetaMain.class.getResource("GiantT.png");
giantT = ImageIO.read(GiantT2);
I know the images are in the file, it's just that they're not loading.
check out this post.May be you are also having the same issue.
How to export jar with images on Eclipse?
Use fat jar eclipse plugin. Select all resources like .wav and image files etc while exporting.
Before exporting resolve all Java compiler errors and warnings(to the maximum extent).
While exporting the jar file with images in your eclipse ,
You must check these in the Jar Export dialog box,
1.Export generated class files and resources
2.Export Java source file and resources
Options:
Compress the content of the jar file
Add directory entries
please delete the existing workspace and reimport the source code
i hope this may resolve issue

Fat jar instantly closes

I created a fat jar file using JarSplice, but when I launch it i get a window (the size is okay) and it closes after half a seccond...
In the "add jars" section I'm adding the jar file that I exported from Eclipse, and all library jars that I'm using. In the natives section I'm adding only Windows natives for lwjgl. I think I wrote the correct main class.
What am i doing wrong? How can I fix this problem?
Note: I'm using the newest version of eclipse and jdk.
The file no longer is really on the "file system" but is instead in the jar, so you will need to load the resource from within the jar. When you run from within eclipse it is still on the file system, but when you create the jar it's not, that's why it works in eclipse but not when you package it up. The answer to this question should give you a good start on loading a file within a jar as a resource. That said, I'm not sure if you can do something similar to your listFiles call.

Java Export - Text Files

I tried to export a Java program from Eclipse to a .jar file, but I came across a problem. It ran fine, but for some reason it didn't find the text files it was supposed to get data from. If anyone could help with this, I would be very grateful.
Where are these text files ? If they're packaged within your .jar file, I would expect to be able to find them within the class hierarchy using ClassLoader.getResourceAsStream(), specifying the complete path relative to the classloader base.
If your program depends on internal text files, put them in classpath and package them in the jar. Find them with the Class.getResourceAsStream.
I guess we need some more information to help you solve this problem. Where are your text files located while debugging and developing your code? Make sure that they are accessible from the path you are running the jar in.

Error running Jar File

I have created a project in java project using NetBeans IDE. I have few forms in it. The netBeans created a Jar file by its own. when i try to run that Jar file its give an error "Failed to load Main-Class manifest attribute from". I Have set my Starting form in application and when i run from netbeans its running correctly but when i try to run my Jar file its give me this error. Please any one can help me how to solve this netbeans.
Thanks
I don't use NetBeans myself, but there's a good step-by-step guide which has screenshots for everything you need to build an executable jar file.
In particular, did you fill in the "Main Class" property in the project properties? I know you says you've filled in the "Starting form" but that may not be the same thing...
Look in the MANIFEST.MF file in the jar file. It should contain a Main-Class line containing the name of the class you want to start when invoking in this manner. If the line is there, doublecheck the spelling of both the class name and Main-Class.

Categories

Resources