How to set reference to the folder which contains multiple jar files? - netbeans

My environment:
Netbean 6.9.1
Glassfish 3.0.1
Windows 7
Goal:
When my coworkers opens the Netbean Project, the library is already referenced without them manually create library, adding jars into it and reference it.
Detail:
I created Netbean project and the project has reference to few jar files in the folder.
Currently whoever opens the project for the first time, they have to manually create library and refer it to the project.
My project location:
C:\Users\masatosan\Desktop\myProject\myApp
My library location:
C:\Users\masatosan\Desktop\myProject\lib\myLib
The myLib folder contains:
some1.jar
some2.jar
some3.jar
I can achieve my goal if I create reference to individual jar file by defining to project.properties file like below: (creating reference to sqljdbc4.jar)
file.reference.sqljdbc4.jar=../lib/sqljdbc4.jar
javac.classpath=\
${libs.restlib_gfv3ee6.classpath}:\
${file.reference.sqljdbc4.jar}:
But my case is different since I have 3 jars in the myLib folder and wanting to reference them all.
Is it possible to reference all jars in myLib folder?
Please let me know if you need more clarification.

I'm sorry, but it doesn't work that way. When you create a project, you have to add the jar files individually.
However, if you put your lib folder under your project, netbeans will refer to them via relative paths. Then when you share the project (lib directory included), netbeans will be able to automatically find the jar files when the next person uses the project. That way you only have to add jar files once.
Short of using a dependency management tool like maven (which Netbeans has good support for), this is really the best solution. It uses a bit more disk space (obviously), but that's never been a huge issue for me.

I figured how so let me share.
Tool --> Library then library window pop up.
Create library called "MyLib" which contains multiple jars.
Add "MyLib" to your project. This change will be written to project.properties file under nbproject folder.
project.properties file indicates the classpath of lib reference you just added.
It should look like something below
javac.classpath=\
${libs.Excella.classpath}:\
${libs.MyLib.classpath}
Now someone else opens the project from different machine and she just needs to do step#1 and #2, which is to create library with same library name i.e. "MyLib"
I think this is what Bill was saying originally but thought it would be helpful to give step by step instructions since I finally figured .... after long time :D

Related

NetBeans Include External JAR in Export to Zip

I have a NetBeans project that uses the GSON library. I've tried including the GSON.jar file without requiring future users to separately download it. However it doesn't seem to work. The project looks for the file from the relative path of my computer so the file isn't found on another user's computer. Is there a way to include GSON.jar and "Export to Zip" and keep the reference in the project itself? I'm lost!
Thank you
Exporting a Project to ZIP zips up the project folder only, and not anything outside of the folder, including dependencies. If you include the GSON.jar file in the project folder, then the JAR file will be included in the .ZIP file. It's a good practice anyway since NetBeans will use a relative classpath and thus if you move the project itself NetBeans won't give you an error message when loading the project.

Eclipse build path: library with native library folder

I created an Eclipse project and I need to use the Super CSV library with Dozer. I downloaded the Super CSV and created a new folder "super-csv" in /usr/lib.
Now I have: /usr/lib/super-csv/super-csv that contains the super csv jar (+ javadoc and source),
/usr/lib/super-csv/super-csv-dozer that contains the super csv dozer jar, javadoc and source plus a "lib" folder.
Inside /usr/lib/super-csv/super-csv-dozer/lib there are many .jar files that are needed for super-csv-dozer to work, so I added it as native library for super-csv-dozer entry in library tab of java build path in Eclipse.
When I try to compile the project, I receive a java.lang.ClassNotFoundException pointing a class that is contained in one of the jar files in the lib folder.
Everything works only if I manually add every jar in lib folder as an external jar.
Can someone explain me where I am doing wrong?
I'd recommend using Maven - it's a widely used tool for Java builds. To start using Super CSV, it would be as simple as adding the 2 dependencies (listed on the Super CSV website), and your Eclipse project would be ready to go.
There's a bit of a learning curve though, so if you want to just add the jars to Eclipse's build path manually, I'd recommend creating a lib directory at the root of your project and putting all of the jars there.
my-project
|-src
| |- (your source in here)
|
|-lib
|-commons-beanutils-1.8.3.jar
|-commons-lang-2.5.jar
|-commons-logging-1.1.1.jar
|-dozer-5.3.2.jar
|-slf4j-api-1.7.1.jar
|-super-csv-2.0.1.jar
|-super-csv-dozer-2.0.1.jar
You can then add them to the build path (here's a good guide).
Just a note: if you're not using the Dozer extension, then you'll only need super-csv-2.0.1.jar on the build path.

Set a classpath just for jUnit in Netbeans [duplicate]

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.
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:
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.
You can add that .jar file by following the steps below:
In the left side panel named "Projects" open your project and right click on the "Libraries", then select "Add JAR/Folder...".
Then select your .jar file from the location where you have stored it in the next dialog box that opens and then press "Open".
Vola Finished!!! (with the same process you can add other libraries also like JavaCV, JMF,etc)
And Now You Can Use That .Jar File From Your Project Library.
Hope It Helps.

Eclipse buildpath automatically taking all JARs of a linked directory

This issue is a variation on the one described here: Eclipse buildpath automatically taking all JARs of a internal directory
But instead of any local folder, I'd rather have a linked folder from another project be picked up automatically in the buildpath.
Basically, I have a main project in my workspace that holds directories lib, ext-lib that contain multiple jar files each. These jar files may be upgraded/removed or new ones added every few days.
I also have many other projects in the workspace that relay on the exact same (up-to-date) jars from my main project.
My goal is that as I modify the jars in these two folders in my main project, to have them as linked folders in all other projects and have those linked projects dynamically picked up as part of the buildpath of all those projects.
Any suggestion on how to do that in eclipse would be highly appreciated.
Unfortunately, the "dynamic directory" plugins people mention can not work with "linked" folders :(
Sincerely,
Guy
I would suggest creating a USER LIBRARY in eclipse and then using that in all of your eclipse projects.
Try going into preferences Java -> Build Path -> User Libraries and creating a new user library with all your jars. Then use this everywhere you need these jars.
See this page for more details.
Also, this page explains creating a user library in a bit more detail. There is also a use-case there which seems a bit more aligned to what you had in mind:
6.2.1. Linked Library Project
A useful hybrid strategy is to configure a user library that is also available as a linked folder in your Eclipse workspace. Follow these steps:
1.
Create a simple project in your workspace. Unlike Java projects, a simple project has no Java build path configuration in its properties. Use the command File > New > Project > Simple Project.
2.
Uncheck the option to use a default project location within the workspace folder and enter the path for your \eclipse-contrib\libraries folder (see Figure 6-8).

how to setup the sphinx with netbeans

i have successfully configured sphinx4 with eclipse.
for that these steps i have used.
copy my java and config files to SRC folder
all the necessary jar files (in the lib). the lib folder added to the root of the project
build those jar files (jsapi files too)
change the configuration file and give the proper path
test the java file
but in Netbeans i really dont understand how to do the proper steps. can someone help me. the jar files should be added to "Libraries" rite.
then after adding them how to build them.
in the netbeans it dont show a SRC folder. so all the java files and configuration files should go to Source Packages folder rite.
can someone help me with this. please
If you have sphinx4-1.0beta6 then you can just open the folder up as a netbeans project. Open netbeans, click open project, then navigate to the sphinx folder and open it. It is already a netbeans project file type as of this version. I assume this will work in later versions also. I have no clue why sphinx doesn't say this on their website.
Sphinx4 is a Java library available in OSS repository, so you can use it as any library.
If your project uses maven/gradle, add repository in your project configuration, then add dependency on two packages - sphinx4 core and sphinx4-data. The former is the main library, the latter is required if you want to recognize US English. Then just start writing the code.
If you want to rely on jar files, just download sphinx4-core and sphinx4-data files from the repository and add them as dependency to the project, then start writing code.
If you want to modify or develop sphinx4 itself, install Gradle support in your IDE, then import latest sphinx4 sources as a Gradle project.
For more details and links see the tutorial
http://cmusphinx.sourceforge.net/wiki/tutorialsphinx4
click on Add JAR/Folder
select jar file you want to add