0

I have a java package with many java class and many main. i wish to make jar from these package ? can you help me please ? (i work with netbeans )

0

3 Answers 3

3

If the project is under netbeans IDE, you should follow these steps:

  • Right click on the project and then click on Properties

  • Click on Packaging

  • Click on Compress JAR File

  • Accept changes, click OK

  • Right click on the project and then click on Clean and Build

  • Go to the directory where your project is stored

  • Look in the dist folder for the JAR file

    To select the main class that will be executed

  • Click on Run

  • Click on Browse near to Main Class label

    enter image description here

    EDIT :

    If you are using netbeans under windows, and if the jar file does not generate any output, try the following command in cmd :

    start /b <jar file>
    

    Then an error should appear

    So you can know what is the problem

  • Sign up to request clarification or add additional context in comments.

    3 Comments

    How can i select the main class that will be executed ?
    @SaberMhadhbi : Please check the answer again, I update it.
    @SaberMhadhbi : No you can't, each project should have one main class only. So when you execute the project, this main class will be executed first, and from this main class you can switch to other classes.
    0

    I found this site useful... Hope it helps deploying jar

    1 Comment

    So you want one project and more than one Jars I think: so I think in that case you probably need to go for a 'free-form project': so you can customise the build (ant/mvn/etc) scripts to do this. I usually just work on two projects in that scenario : unless you really need to share a lot of code between the two projects: then consider creating a third 'library' project - you can then add that as a dependant library to the other two. [I hope that makes sense!]
    0

    Right click on the the project in net beans project window and choose Project Properties -> run , there you can setup your main class

    clean and build your project and go to your netbeans project -> your project -> dist there is the executable jar file.

    selected main class will be executed when you execute the generated jar file

    3 Comments

    i do these but when i execute the .jar, nothing happen
    select a main class that should be executed in the project and then clean and build the project since you said that you have many main methods you should pick one.
    made some changes on the answer on how to set up a main class check that

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.