Where should I place the java properties file under netbeans - netbeans

In my netbeans IDE I am creating one project.That project(Web Application) needs properties file.Since my application is having several packages.And all packages need to read this properties file in their code.So where should I place this java properties file.If I place the file out side of the packages that is under sourcepackages seperately,I am getting FilenotFound Exception.So where should I place it.
And one more doubt is if I want to change any content in the file in future where should I change the contents since it is present in Projects folder and under Files->build->classes folder also.From where should I modify it.From where the changes will be effected.
Please help.
Thank you.

Put your file under /src/resources/, then use it like below:
ResourceBundle props = ResourceBundle.getBundle("resources.config");

You may put this in any package. The point ist to read with
MyClass.getResourceAsStream("my.properties");
Read further here.
You always change in the project src folder. The build folder is only for building your app.
If you want to change the properties file on a deployed system you may put the properties into the WEB-INF folder and then access with ServletContext#getRealPath().

I put the .properties file in the same folder as the src and it works :)

Alright, so I'm working on Windows and here's my solution...
It actually doesn't matter much where you put the .properties file--but assuming you created the file in NetBeans and let it save to its default location, you can simply call the data with the full directory attached.
Just for reference, here's what I did:
SimpleDataSource sds = new SimpleDataSource("src\\simpledatasource\\mystuff.properties");
Notice you'll need to escape the backslash, so use two of them.

Related

Can we overlay the file to our custom path

Can we overlay the file to our custom path or we have to overlay the file to exact folder structure location as in libs?
For example, I want to overlay the constants.js (/libs/cq/ui/widgets/source/constants.js) file, in this adobe recommended Copy this file to /apps/cq/ui/widgets/source/constants.js for overlaying, but in my project that folder structure is not there, so I have copied to the custom path in apps folder and tested the changes and overlaying is working fine.
The file needs to have the same path as the one in libs except for replacing 'libs' with 'apps'. It does not work with custom paths*. If the project does not already have the structure, you can always create it. Don't forget to update the META-INF/Vault/filter.xml file to register the new path with projects package definition.
*Technically you can change the configs to add new searchpaths. But do remember that you might have to share the AEM instance with different tenants and sticking to the usual conventions goes a long way in having a predictable setup. I honestly don't see a reason to do this, it is already an acceptable practice to overlay under '/apps'. The filters on package provide enough flexibility to get along with other tenants while modifying similar areas.
I think you want to create the overlay in your custom project under /apps. If my assumption is correct, then you can certainly do it.
Taking your example in consideration, /libs/cq/ui/widgets/source/constants.js can be overlayed to /apps/<your-project>/cq/ui/widgets/source/constants.js by adding an entry in the Apache Sling Resource Resolver Factory configuration.
See this answer for the detailed steps. I hope this helps.

How to read a file in Play Framework 2.2.1?

I have a static file that I want to read in one of my Play Framework models. The file contains some simple text in it. I can't find any examples or API that shows where the appropriate location is to store such a resource and second, how to access that resource. For whatever it is worth I'm using Play for Scala, but I don't think that's relevant here.
There is no real designated location where data files should go. I usually set a path in my application.conf and then read it in the application via
Play.application().configuration.getString("my.data.path")
If you want to store it somewhere inside your Play application's directory, you can get its root path via
Play.application().path()
which returns a java.io.File.
For reading files, there is no Play-specific technique. This question has been asked and answered before. In short, to read a small text file, just do this:
val lines = scala.io.Source.fromFile("file.txt").mkString
You can place any resource file in the folder /conf and load it (Programatically) as explained here: Custom configuration files - Play! Framework 2.0
I have answered to a similar question at https://stackoverflow.com/a/37180103/5715934. I think the same answer will be applied for you too.
You can choose a location you prefer other than in dedicated folders for some specific tasks. For an example you can create /resources folder. Don't make any resource folder inside /app folder since it is only a location to store code. Same goes with other specific folders. Then you can use
import import play.Play;
Play.application().getFile("relative_path_from_<Project_Root>);
to access the file inside your code.
Only this will work perfectly on dev environment. But once you put this in production using the dist file it will not work since the entire resources folder you put will not be added to the dist. In order to do that, you have to explicitly ask play to add the /resources folder to your dist also. For that what you have to do is go to your /build.sbt and add these lines
import com.typesafe.sbt.packager.MappingsHelper._
mappings in Universal ++= directory(baseDirectory.value / "resources")
Now if you take and check your dist, you can see it has an additional folder 'resources' inside the dist. Then it will work for the production environment also.

Static Library path nightmare from hell

This is the point. I have a subproject (static library) created. The library compiles well. No errors. When I include this library inside a project and imports a header from that library on the project the library fails to compile because it cannot find a path that belongs to itself.
After following a bunch of tutorials on the web on how to create a static library and embed that in a project, I don't know which one is the correct one, because I have tried all and all failed and some differ.
This is how the library is set:
STATIC LIBRARY
BUILD SETTINGS:
Public header folder path = $(BUILT_PRODUCTS_DIR)
Header search path = $(SRCROOT) (recursive)
BUILD PHASES
COPY FILES = 1 file, myLibrary.h that is basically empty (created by xcode when I used the static library template to start the library.
no ADD COPY HEADERS phase
MAIN PROJECT
BUILD SETTINGS
Header search path = empty
User header search path = $(BUILT_PRODUCTS_DIR) (recursive)
Always search user paths = YES
BUILD PHASES
Yes, myLibrary.a is on target dependencies
What amazes me is that the library compiles fine alone but when put inside a project, is unable to find a header that belongs to the own library.
NOTE: I have also tried to create a copy headers phase on the library making public all .h on that library, but it failed too.
This is an example of one error:
/Users/mike/Library/Developer/Xcode/DerivedData/MyApp-dnaimaovscreasadhmvgttwjnabc/Build/Products/Debug-iphoneos/include/myLibrary/ccTypes.h:39:9:
fatal error: 'Platforms/CCGL.h' file not found
#import "Platforms/CCGL.h"
I have lost two days trying to solve this nightmare.
any thoughts?
I have uploaded a sample project to here and here
After downloading your sample project, I had it working in a few minutes by making the following changes.
First, you need to add an entry for the MyProject target's Build Settings under Header Search Paths, so that the files such as HelloWorldLayer.h, which #import "cocos2d.h", know where to find that file.
Under the Header Search Paths, I entered ../MyStaticLibrary/MyStaticLibrary/libs/** like shown in the image below:
That solved the problem of the inability of the preprocessor to find the necessary source files from the MyStaticLibrary, for the MyProject project, but after compiling, I got an error about missing symbols. I needed to add the built libMyStaticLibrary.a to the Link Binary With Libraries step like shown in the image below:
After that, the project compiles fine.
(Not enough rep to post comment...)
Did you try specifically including the Platforms directory in the header search path? Presumably, Platforms is in the source directory, not in $(BUILT_PRODUCTS_DIR) so may not be searched in your current setting.
Regarding script to show you env variables, here's how I do it (open images at the new tab for better scaling):
Added dummy shell script
Observed its output at Log Navigator
As you can see, BUILT_PRODUCTS_DIR doesn't have any headers copied from the library. Either put headers there manually (strongly not recommended) or add search path to the location that you know the headers must be at:
Now as there were two headers cocos2d.h and MyStaticLibrary.h, cocos2d.h was successfully imported although it will have additional dependency.
The path ../MyStaticLibrary/build/$(BUILD_STYLE)-$(PLATFORM_NAME) will also (recursively) have public headers of the library.
After almost 5 days of a nightmare trying to solve that, I finally found this tutorial: http://www.youtube.com/watch?v=XUhLETxgcoE
This is the only solution that worked for me. The simplest and the best.
Thanks for every one trying to solve this.
Please try this…
step1: right click on the 'projectName.xcodeproj'(static library).Choose 'Get info' and copy the full path from(General->where)
step2: Paste full path to 'Header search paths' for your main project(Both Targets and Project )

How to create Eclipse EFS resources on the fly in a content provider?

I like to write a plugin for Eclipse, which allows to work with archive files as with normal file directories. For instance, if there is a zip file inside a project, the user should be able to view the contents of the zip file just by opening the zip folder. The user should be able e.g., to read text files in that archive.
I already created an EFS wrapper arround a particular archive format. Also, I created a new content-type for this archive format. I have a navigatorContent which is triggered on the content-type. In the content provider, currently I provide objects of type IFileStore. AFAIK there isn't any nice label provider shipped with eclipse for this types so I have to implement it on my own (there is one which is declared as private). However, this seems to be rather huge code duplication effort. What I therefore like to do is not to return IFileStore but IFile or IFolder instead so that the normal project explorer content provider can do its job. Is it possible at all to do something like this? If so, how can this practical be achieved?
Call IFolder.createLink() to create a new resource referencing a folder on your custom filesystem.
http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_efs_resources.htm
This will create a new folder in your project, containing all files from ZIP archive. The problem, however is, that you will need to put it into an existing container, polluting resource tree.
Implementing ILabelProvider is not a huge effort at all, especially when compared to IFile or IFolder. If you extend BaseLabelprobivider you only need to implement 2 methods: getText() and getImage().

Netbeans creating a dist jar with all images etc included

I am trying to distribute a netbeans project however the jar it creates and the contents of the dist folder are dependant on some image files which i included into the project - however these images are not in the dist folder and I cannot workout how to make things work so I can export the project in a distributable format including all the things it needs.
Can somebody please tell me how I can export a project which runs within Netbeans without using the project's /dist folder which includes everything it needs?
Cheers
Andy
One way to achieve this is to add a folder (f.i."resources") in your project's src dir. Then copy the images to that dir. Now the images should get included when you build the project (if I remember correctly). Accessing the files can be accomplished with "getResourceAsStream"...
If whatever resources you are interested in are in the classpath, packaged in the jar, war, or the distribution, you can retrieve them by getting resources.
The convention is indeed to have a directory named 'src/resources' that serves as the root for this. Depending on the amount and scope of the resources you are using you may also want to add a sub-directory hierarchy to keep the organization and state of the resources manageable.
Also, not that a resource can be any file, an image, sound, text, xml, binary, etc. no limitation.
Finally, the call will look like this if you are using an object method:
getClass().getResourceAsStream("resources/myResource") - or - getClass().getResource("resources/myResource")
depends on if you want a stream or just the URI at that point in the code. Typically one would use the URI for delegating the processing of the resource elsewhere and the stream form when you are processing it in-line.
For a class method, you will need to do something more like:
new Object().getClass()...
The think to keep in mind here, is eventually this is resolving to the class loader and it is from that class path that the resource will be fetched.
You can add images the same way:
final Image image0 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/1.png"));