Netbeans: need to include 3'rd party directory in classpath

a 夏天 提交于 2019-12-02 18:25:26

问题


We have an application developed in NetBeans, based on the NetBeans platform. There's a 3'rd party program that we have a runtime dependency on, more specifically a jar in the other progams lib folder.

How should we include the other progam's jar in our classpath?

The recommendation from the other progam's manufacturer is to set environment variable CLASSPATH to include

C:\Progam Files\Other Program\lib\theJAR.jar

And if that's not possible, we should copy theJAR.jar to JRE-HOME\lib\ext

We must not copy theJAR.jar anywhere else, that might cause it to stop working...

Now NetBeans takes no notice of what's on environment variable CLASSPATH. Their recommended way seems to be to make a wrapper, but that would lead to copying the jar, unless there's some way to make a wrapper module that points to CLASSPATH?

At the moment we are copying the jar into JRE-HOME\lib\ext. But then there's unnecessary hassle when we install some java update.

Do you have any solution to this problem? It seems like something that might be simple, but I haven't found the right place to look yet...

Edit: The application is ant-based.


回答1:


From the documentation for the Module System API's overview of the runtime infrastructure (bottom of the page under the section "Common Problems and Solutions"):

Q: Can my module add a library JAR to the classpath from outside the IDE [read: platform] installation?...

A: Not easily. You have a few options:

  1. Add an entry to ide.cfg [your app's .config file]. For example:

-cp:a c:\eak\lib\eak.jar This startup file provides the ability to add classpath entries to the IDE's Java invocation.
...

It goes on to list two more options. The second option is the same solution you've come up with. The third is to "partition your module and use a new classloader" which I can't recommend either way since I have no experience doing this (but it's worth a read).

Assuming that this first option is what you are looking for, you will need to add a custom .conf file to your project and point to it in your project.properties file, like so: app.conf=nbproject/my.conf. This will add your custom .conf file to your app's install directory instead of the default config file that is normally added. Of course, you'll need to add the -cp:a c:\eak\lib\eak.jar entry to this custom config file in order to load the .jar.

During development you'll need to add the following entry to the project.properties file: run.args.extra=-cp:a c:\eak\lib\eak.jar. This will pass the command line option to your debug instance.




回答2:


You can add that .jar file by following the steps below:

  1. In the left side panel named "Projects" open your project and right click on the "Libraries", then select "Add JAR/Folder...".

  2. Then select your .jar file from the location where you have stored it in the next dialog box that opens and then press "Open".

  3. Vola Finished!!! (with the same process you can add other libraries also like JavaCV, JMF,etc)

  4. And Now You Can Use That .Jar File From Your Project Library.

Hope It Helps.



来源:https://stackoverflow.com/questions/11358953/netbeans-need-to-include-3rd-party-directory-in-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!