r/javahelp • • Jul 20 '21

Solved Can't create executable jar file

Hey guys,

i use Bluej for programming java (it's for school) and we made a little project with JFrames, etc... I didn't want to open bluej everytime just to start the program so I wanted to export it to a .jar file.

BlueJ includes this feature so I only have to say which is the class with the main-method and if I want to download the java libraries too.

That's fine but if I now open the Jar file there's just this error:

"error a jni error has occurred please check your installation and try again"

this is my class with the main-method: (is there my mistake?)

public class Simulation
{
   private Controller controller;
   private Login_Model lm;
   private Game_Model gm;
   
    public static void main(String[] args) {
        new Simulation();
    }
    public Simulation() {
        lm = new Login_Model();
        gm = new Game_Model();
        controller = new Controller(lm, gm);
    }
}
0 Upvotes

4 comments sorted by

•

u/AutoModerator Jul 20 '21

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/[deleted] Jul 20 '21

You might want to search for a BlueJ specific forum. This is a generic Java forum, and you're telling us what you did in BlueJ.

Some "generic Java" instructions I can give is this. A JAR file is actually a zip file. What files do you see if you rename your JAR file to a ZIP file and unzip it?

0

u/johnmc325 Jul 20 '21

This does not sound like there is any problem with your code rather the problem is with different versions of Java. When you compiled java in BlueJ you will have used a version of Java. Now you are trying to run the JAR file outside BlueJ it will look on the machine for a version of Java and this may well be different. Go to a command prompt and type "java -version" to see what you get. Now check in BlueJ what version you are using to build your project. Getting them the same will help. See if that moves you forward.

0

u/leifk3 Jul 20 '21

Thank you so much! It works now fine. Thank you for the fast response, you helped me so much!