Getting weird behavior when creating jar executable on eclipse for my chess project

As the topic says, I created a chess game as my first 2D game, but when I try to create an executable jar file from it, I get strange behavior, and when I move the pieces, the game becomes chaotic and nothing works. The strange thing is that inside the eclipse, everything works fine. When it creates the executable file of the jar file, eclipse gives the following error:

Resource is out of sync with the file system: '/Chess_Project/src/.DS_Store'.

I don’t remember that even such a file was in my project, so I think it is a hidden file or a system file. Then I tried to export it as a regular Jar file with eclipse and after it through the terminal (by the way, I am a Mac OSX lion user), but I failed in both directions and got NullPointerExceptiona few more errors. I got a little familiar with the manifest files and tried to compile my code myself, and then export each of the methods that I mentioned above.

I tried to solve it for a week or so and asked for help in various forums, but no luck.

Thanks to the Francis, I realized that the problem could arise from my code. And also my question: "why am I getting weird behavior in the runnable jar file (which means that everything is not working as it should), when I run it inside eclipse, everything works fine?" , here is the main class of my code:

import java.awt.*;
import javax.swing.SwingUtilities;
import javax.swing.*;

public class MainWindowChess {

    /**
    *
    */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                JFrame f = new JFrame("Chess");
                SwingUtilities.isEventDispatchThread();
                f.setLayout(new BorderLayout());
                f.setSize(40 * 8, 40 * 9 - 20);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setResizable(false);
                Board b = new Board();
                f.add(b);
                f.setVisible(true);
                System.out.println("check");

            }
        });

    }
}

By the way, it is amazing that people respond so quickly, I am glad to see so many people who want to help others.

Here is the paintComponent method:

protected void paintComponent(Graphics g) {
    super.paintComponents(g);

    if (boardDrawn == false) {
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                g.drawImage(getRect(i, j), cors[i][j].getXCor(), cors[i][j].getYCor(), null);
            }
        }

        for (int i = 0; i < bp.length; i++) {
            bp[i].drawPiece(g, bp[i].getImage(), bp[i].getLocationX(), bp[i].getLocationY());
        }
        for (int i = 0; i < wp.length; i++) {
            wp[i].drawPiece(g, wp[i].getImage(), wp[i].getLocationX(), wp[i].getLocationY());
        }

        boardDrawn = true;
    } else if (boardDrawn == true) {


        if (tempPiece instanceof BlackPiece) {
            for (int i = 0; i < bp.length; i++) {

                //if the piece was found
                if (tempPiece == bp[i]) {

                    if (bp[i].isMoveAvailable(bp[i].getTypeID(), bp[i].getLocationX(), bp[i].getLocationY(), tempCor.
                            getXCor(), tempCor.getYCor())) {
                        killTime = true;
                        //if the rectangle which we want to draw the Piece on is not occupied by another Piece
                        if (isRectBlocked(bp[i].getTypeID(), oldCor.getXCor(), oldCor.getYCor(), tempCor.
                                getXCor(), tempCor.getYCor()) == false) {

                            g.drawImage(getCompatitableRect(oldCor.getXCor(), oldCor.getYCor()), oldCor.
                                    getXCor(), oldCor.getYCor(), null);
                            bp[i].drawPiece(g, bp[i].getImage(), tempCor.getXCor(), tempCor.getYCor());
                            bp[i].setX(tempCor.getXCor());
                            bp[i].setY(tempCor.getYCor());

                        } else if (canRectBeOccupied(bp[i], tempCor.getXCor(), tempCor.getYCor())
                                && isRectBlocked(bp[i].getTypeID(), oldCor.getXCor(), oldCor.getYCor(), tempCor.
                                getXCor(), tempCor.getYCor()) == false) {

                            g.drawImage(getCompatitableRect(oldCor.getXCor(), oldCor.getYCor()), oldCor.
                                    getXCor(), oldCor.getYCor(), null);
                            g.drawImage(getCompatitableRect(tempCor.getXCor(), tempCor.getYCor()), tempCor.
                                    getXCor(), tempCor.getYCor(), null);
                            bp[i].drawPiece(g, bp[i].getImage(), tempCor.getXCor(), tempCor.getYCor());
                            bp[i].setX(tempCor.getXCor());
                            bp[i].setY(tempCor.getYCor());
                        }
                    }
                }
            }
        }
        if (tempPiece instanceof WhitePiece) {
            for (int i = 0; i < wp.length; i++) {

                //if the piece was found
                if (tempPiece == wp[i]) {
                    if (wp[i].isMoveAvailable(wp[i].getTypeID(), wp[i].getLocationX(), wp[i].getLocationY(), tempCor.
                            getXCor(), tempCor.getYCor())) {
                        killTime = true;

                        if (isRectBlocked(wp[i].getTypeID(), oldCor.getXCor(), oldCor.getYCor(), tempCor.
                                getXCor(), tempCor.getYCor()) == false) {
                            System.out.println("");
                            g.drawImage(getCompatitableRect(oldCor.getXCor(), oldCor.getYCor()), oldCor.
                                    getXCor(), oldCor.getYCor(), null);
                            wp[i].drawPiece(g, wp[i].getImage(), tempCor.getXCor(), tempCor.getYCor());
                            wp[i].setX(tempCor.getXCor());
                            wp[i].setY(tempCor.getYCor());

                        } else if (canRectBeOccupied(wp[i], tempCor.getXCor(), tempCor.getYCor())
                                && isRectBlocked(wp[i].getTypeID(), oldCor.getXCor(), oldCor.getYCor(), tempCor.
                                getXCor(), tempCor.getYCor()) == false) {

                            g.drawImage(getCompatitableRect(oldCor.getXCor(), oldCor.getYCor()), oldCor.
                                    getXCor(), oldCor.getYCor(), null);
                            g.drawImage(getCompatitableRect(tempCor.getXCor(), tempCor.getYCor()), tempCor.
                                    getXCor(), tempCor.getYCor(), null);
                            wp[i].drawPiece(g, wp[i].getImage(), tempCor.getXCor(), tempCor.getYCor());
                            wp[i].setX(tempCor.getXCor());
                            wp[i].setY(tempCor.getYCor());
                        }
                    }
                }
            }
        }

        killTime = false;
        tempPiece = null;
    }
}
+1
source share
2 answers

In the Package / Project Explorer, right-click on your project and select Update. In export, you should be able to exclude it from the jar file (since it does not have a business there).

.DS_Store Mac OS, , Eclipse , , , .

+7

.DS_Store (Desktop Services Store) - , Apple Inc. Mac OS X , .

+1

All Articles