Thursday, May 27, 2010

Setting Environment Variables for Netbeans

I use both NetBeans and Eclipse as IDEs for developing Java code.  In some cases (notably when the code employs the CPLEX optimization library), I need to set an environment variable at run time (in the case of CPLEX, to point to the license file).  Eclipse provides an easy way to do this as part of the run time configuration for the project, but for whatever reason NetBeans lacks this feature (a singularly dopey omission IMHO).

After considerable time spent with Google, it appears that if you need to set environment variables on a project-level basis, the best option in NetBeans involves hacking the build.xml file in ways that I cannot begin to fathom.  Fortunately, if the environment variable works globally (across projects), there's a simpler answer.  In the NetBeans installation tree there's an etc/ folder containing a configuration file (netbeans.conf).  Just add the line export key=value and the problem is solved.

5 comments:

  1. How do you call cplex from Java? Through JNI? Is it reliable?

    ReplyDelete
  2. CPLEX offers a Java API (part of the Concert library), so I'm calling library routines as if they were Java libraries. So I'm not using JNI directly. The CPLEX executable code is in a shared library (DLL on Windows, SO on Linux), and it's the same shared library whether you're using C, C++, Java, C# or Python, so I'm pretty sure the library was written mainly in C, and I suspect that CPLEX is using JNI to hook to it. Yes, it's quite reliable (and essentially seamless). You have to include a jar file (provided by CPLEX) in the compile library path, you have to add the DLL or SO file to the execution library path, and you have to have either a license server running or an environment variable pointing to a license file, but that's pretty much it.

    ReplyDelete
  3. Oops. Turns out the export command does not seem to work in Windows (nor does set key=value in netbeans.conf). Back to the drawing board ...

    ReplyDelete
  4. Dr. Rubin,
    I would like to implement a branch-and-price. I would like to build on any tools that are available. Do you have any suggestions? I prefer Java but I am open to using another language.

    Thanks,
    Hugh Medal
    Ph.D. Candidate
    University of Arkansas

    ReplyDelete
  5. A disclaimer first: I have not done any branch-cut-price work myself, so I have no first-hand experience with any of these. That said, I know that COIN-OR hosts at least two projects, Bcp (http://www.coin-or.org/projects/Bcp.xml) and SYMPHONY (http://www.coin-or.org/projects/SYMPHONY.xml), designed to do b-c-p. Ted Ralphs also has a web page (http://www.coin-or.org/SYMPHONY/branchandcut/software.htm) listing various software useful for b-c-p. Most of it (including Bcp and SYMPHONY, as far as I know) is written in C++ (or maybe C).

    ReplyDelete

If this is your first time commenting on the blog, please read the Ground Rules for Comments. In particular, if you want to ask an operations research-related question not relevant to this post, consider asking it on OR-Exchange.