0

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.

bjarven
  • 771
  • 2
  • 10
  • 27
  • FYI… In NetBeans 8, projects tend to be based on [**Maven**](https://en.wikipedia.org/wiki/Apache_Maven). For help adding libraries (dependencies) to such Maven-based projects see the Questions, [How to setup classpath in Netbeans?](http://stackoverflow.com/q/7598623/642706), and [Adding dependencies in Maven Netbeans](http://stackoverflow.com/q/6819317/642706). – Basil Bourque Aug 19 '15 at 05:30

2 Answers2

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.

Community
  • 1
  • 1
Jonathan Spooner
  • 7,682
  • 2
  • 34
  • 41
  • This is exactly what we did eventually, works like a charm. If only we could have a reference to %SOME_ENV_VARIABLE% in my.conf it would be perfect, but that doesn't seem doable. But for most usercases the 3'rd party program will be installed to the same directory so it won't be that much a problem to edit my.conf in the few cases it's not installed there. – bjarven Jul 13 '12 at 12:21
  • I'm glad that you solved this. Just FYI, you *can* answer your own question (and mark it as accepted) if you have the solution. This way others who are having a similar issue can learn from your discoveries. – Jonathan Spooner Jul 13 '12 at 14:44
0

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.

codeDEXTER
  • 1,181
  • 7
  • 14
  • There's no such option on a "NetBeans module" project, or on a "NetBeans Platform Application"-project. That can only be done on a standard java project. Or am i missing something? – bjarven Jul 06 '12 at 09:46
  • Generally project tab in which it shows your projects,modules,etc are shown, is in the left hand side of the screen. and if not, then press "Ctrl+1" or go to the menu bar and click "Window" and a drop down menu will open and there you select "Projects". Then in the project menu select/maximize your project or module and then there will be your Library Folder. And then proceed as explained above. – codeDEXTER Jul 06 '12 at 12:44
  • Yes I know where the project tab is... But under "Libraries" for a netbeans module project there's only the options "Add module dependency" or "Add new library", the option "Add JAR/Folder" can only be selected if the project is a standard Java project, not a NetBeans module. – bjarven Jul 06 '12 at 12:59
  • OK i think i found the answer.In a module,you can only use a .jar file by wrapping it.Now Right click your Module Project and select "Properties" in it.Now in the properties select "Library" from the left hand side panel.Then in the section opened select "Wrapped JARs" tab and then "Add" your desired .jar file.See these: [Link 1](http://stackoverflow.com/questions/2904913/how-to-simply-add-jar-files-as-libraries-in-a-netbeans-module-suite) and [Link 2](http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r2mx/index.jsp?topic=/com.ibm.wbit.620.help.addev.doc/topics/timpjar.html). – codeDEXTER Jul 06 '12 at 14:36
  • NetBeans will still copy the jar into modules/ext and read that jar when the program is deployed, not the one placed in C:\Progam Files\Other Program\lib\theJAR.jar. The jar must not be copied... – bjarven Jul 06 '12 at 15:10
  • so you want to use the .jar files from where it is and not copy it from its location.And did you see the two links i attached. – codeDEXTER Jul 06 '12 at 15:16
  • Exactly. I said that in the question, but perhaps it was unclear. I edited it to be more clear on that. I've come across those links before when I've searched for this. – bjarven Jul 06 '12 at 15:37
  • Are there other .jar file in there and if there are, then how many.And is there a Manifest file in there. – codeDEXTER Jul 06 '12 at 15:46