Search code examples
javaexecutableprogram-entry-pointexecutable-jarbluej

Applying the main function to my bluej project / Making my bluej program a executable .jar


    public class Player
{
        // Fields for tracking Class, health and name
        private String name;
        private String playerClass;
        private int health;

        // Array of classes
        String[] classes = {
            "Warrior", "Mage", "Rogue",
            "Hunter", "Druid", "Priest",
            "Paladin", "Monk", "Warlock"
        };
        //Available Classes are "Warrior", "Mage", "Rogue", "Hunter", "Druid", "Priest", "Paladin", "Monk" and "Warlock"  

        // ##Constructor##
        public Player(String setName, String setClass)
        {....
}

Is the beginning of my code, with the constructor of the program, how do i apply the main function to this so that I can create an executable .jar file? It's written in Bluej all within one class.

Edit - I understand i need a main function, and kind know how it works. However what do i put in the brackets of the main function in this scenario to get things rolling?


Solution

  • To start a stand-alone Java application, there is needed the main method with strictly predefined modifiers and paramteres:

    public static void main(String[] args) {}
    

    In the BlueJ, you can start the program by clicking the right button on the class in the diagram and selecting void main(String[] args) or create a new instance of the class (in your case new Circle).

    For more information, read this article: Getting Started with BlueJ.