How can I include external jar on my Netbeans project

后端 未结 12 2721
挽巷
挽巷 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 06:59

    Try this - in the Netbeans IDE:

    1. Go to Tools --> Libraries
    2. In the dialog box, on the bottom left click "New Library", give a name
    3. On the right side, click on "Add JAR/Folder"
    4. Click OK on the bottom right
    5. Re-start the IDE and check.
    0 讨论(0)
  • 2020-11-27 07:01

    If you copy your jars into the source code directory, they will be in your final jar. Nevetheless, I am not sure if this will work 100% of the time.

    There is a great post at java-forum that states the following:

    Except for a select few circumstances, what works best for me is to simply merge the files manually. A .jar is basically a .zip with organized contents, and you can open them in almost any .zip capable archive program (I just use gnome's standard archiver, File Roller, and it works great). Backup your jar file and open it in the archiver of your choice, and do the same for each library jar in the library directory. Drag and drop the working folders (IE, everything EXCEPT the META-INF Directory) from each library into your jar's root path (alongside your META-INF and your app's root package). Now drag the META-INF/MANIFEST.MF file from your jar to your Desktop or any other folder. Open it, and erase the Class-Path and X-COMMENT lines. Don't forget to leave a blank newline at the end of the file! Save the new manifest file and drag it back to your jar's META-INF directory, overwriting the old one. Test the jar.

    0 讨论(0)
  • 2020-11-27 07:01

    Follow these:- 1. Right click on project opened in netbeans editor 2. select properties 3. choose libraries 4. add jar 5. click ok

    0 讨论(0)
  • 2020-11-27 07:04

    This is what worked for me:

    I built in excel export functionality into my project. The 2 external .jars I used for this purpose was jxl.jar end sx.jar

    Unpack these 2 jars into a folder(java classes) using 7-Zip without any META files. Unpack your project jar into the same folder including the META file.

    Re-Pack the whole java classes folder using JARMaker to recreate your Project .jar in its original distribution folder ... and there you go ... full excel functionality.

    0 讨论(0)
  • 2020-11-27 07:12

    Copy that jar file to:

    C:\Program Files\Java\jdk\jre\lib\ext

    and

    C:\Program Files\Java\jre\lib\ext

    You should be able to use it in Netbeans and in your manual imports, just like standard imports.

    0 讨论(0)
  • 2020-11-27 07:13

    I solved this by creating just one jar file with all libraries inside, adding the following to my build.xml file in NetBeans:

    <target name="-post-jar">
      <jar jarfile="dist/Combined-dist.jar">
        <zipfileset src="${dist.jar}" excludes="META-INF/*" />
        <zipfileset src="lib/commons-io-1.4.jar" excludes="META-INF/*" />
        <zipfileset src="lib/ninja-utils-3.2.jar" excludes="META-INF/*" />
        <zipfileset src="lib/unicorn-1.0.jar" excludes="META-INF/*" />
        <manifest>
            <attribute name="Main-Class" value="com.example.mypackage.Main"/>
        </manifest>
      </jar>
    </target>
    

    This creates a jar file (Combined-dist.jar) which is the combination of the dist jar and the specified library jars (in this case, commons-io-1.4.jar,ninja-utils-3.2.jar and unicorn-1.0.jar). You have to be sure to specify your Main Class package for the new jar file or it won't run when you try to open it.

    0 讨论(0)
提交回复
热议问题