Where to put a file in the netbeans? - netbeans

In which location I should put any file in Netbeans project directory structure?
Also in the code how should I give the path(absolute or relative) to that file?
Thanks

If it is about Java,
I would suggest you to put it in default package , It would be directly available in classes folder after building, so you can directly access it from classpath.
Here is sample

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.

How exlude properties when building executable jar in Eclipse?

This question has been covered here before, but the only solutions I could find were in relation to a project using Ant or Maven. I am using neither. Here is the situation:
I have some application parameters in a properties file. This file is located in my Eclipse project (but in the src folder) and used when I run the application from Eclipse. In addition, I would like the application to also run as an executable jar file, in which case the user can provide the name of a properties file to use in a command line parameters.
The problem now is that the properties file from the project is always packaged into the executable jar and therefore the user is not able to easily modify the properties (yes, I know that (s)he could unzip the jar, but I want to avoid the extra steps).
How can I prevent the properties from being packages into the executable jar file?
Cheers,
Martin
Create a executable jar without properties file in it. Place both jar and properties file in a folder. Now add little code in your main program which should look for a properties file in the same folder and get the complete path of it. And then you can do something like this
System.getProperties().load(new FileInputStream(completepath));
So now your properties will be loaded into system properties with out affecting the actual system properties. You can access your properties by System.getProperty("Propertyname");
Hope this helps. Let me know if you have more questions.

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

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

how to put .properties file in classpath of an Eclipse plug-in

I have an application which is making use of a .jar file and a .properties file which must reside in the same directory as where the .jar file lies. On a normal java application, this works fine, however I'm building an Eclipse plug-in. I've tried attaching the .properties everywhere, in the classpath, build path, putting them in the same folder and calling the jar file from there (this gives an obsure error) and I've even tried putting the .properties file inside the .jar file even.... but no luck. Any ideas how this could be done please?
Thanks and regards,
Krt_Malta
Perhaps the FileLocator class will help you. The FileLocator provides a find method where you can specify the Bundle and a resource to look for.
Ingo

Eclipse configuration: where to put external libs?

I have configured my Eclipse to have a C:\Eclipse\external_libs directory where I place all my external libraries. In my case , my external libs are WATIJ, XMLUNIT, and XOM . Adding the external libs to the project is no problem... there is no question about that.
I also place my JDK at C:\Eclipse\Javasoft .
What I am wondering IS : is there a better location to place external libs? It's important to note that I like being able to pack my Eclipse directory into a zip file and move it and open it on another computer in a portable fashion.
It's normally done on a per app/project basis. For java webapps you normally have your external libs in WEB-INF/lib. However, if you share the libraries across projects AND you need to zip your eclipse directory, what you're doing now is probably the best solution imo.
In linux you could add them to something like /usr/lib/share and include that in your classpath (but you couldn't zip it all up), but not sure if that sort of directory exists in windows.
If you do place all your library in an external folder, please use "linked resources" to avoid putting any fixed path in your .classpath file.
You can then reference that external directory from within your project, with a linked folder.