How can I include external jar on my Netbeans project

后端 未结 12 2760
挽巷
挽巷 2020-11-27 06:25

When I run \"clean and build\" the .jar file that is being created only runs if the lib folder is at the same folder of the .jar file.

12条回答
  •  抹茶落季
    2020-11-27 07:24

    That's really easy to package every dependent library (*.jar) into one single myProject.jar.

    Just follow these steps and you will finally pack every dependent library into single jar. If you are using NetBeans then you can follow exactly or else you need to find your build.xml file in project files.

    Follow these steps to edit build.xml

    1) Click on Files tab on the left side of the project panel in NetBeans.

    2) Double click on the build.xml file and add these lines in it just before line

     
        
        
        
        
        
        
        
            
            
            
                
            
        
        
            
        
        
    
    

    3) Change value in second line of the code as per your project name which is

     //<---Just value not name
    

    4) Save it and right click on build.xml and choose Run Target and then Other Targets and finally click on Package-for-store

    5) And here you done. Now you can go and check just like dist folder there will be a store folder which will be containing your final complete jar including all of your dependent libraries. Now whenever you want to change / add more libraries or so, just follow step 4.

    Picture for step 4

    enter image description here

提交回复
热议问题