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
Related
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.
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.
I am using a java jar dependency that requires a certain property file to be on the classpath. I can't for the life of me figure out how to add this folder/file to the classpath. I am using play 2.0.
I have added the config.properties file to both the /conf directory and have tried to add it to the root of my app source folder. The file does not seem to be recognized by the dependency.
BTW: play 2.0 uses sbt to compile and run the application so maybe something there could help?
Any ideas?
You should be fine if you put the property file where your class files are. When you use SBT you probably use either:
The project root directory as source directory. In this case just put your property file into the root directory.
Or the maven layout, so your normal classes are under src/main/scala In this case put your property file under src/main/resources
Although the answer of Jens Schauder should solve your issue, you may want to try to add the file to the lib folder.
Play 2.0 won't remove files manually added in there (at least it doesn't at the time I'm writting this!) and that folder should be included into the classpath automatically.
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
I have a small GUI application developed with netbeans.
I used the 'clean and build' option to build an executable jar file. .jar file works in my pc. But when i sent the application to my friend he says that it throws 'cannot find the main class' error.
what could be the reason?
Thanks in advance...
Open project property, select run and set Main-Class (textfield) attribute.
EDIT:
Execute the main class in .jar application,
java -jar Application.jar
If you have used any library, try giving the library jar files along with the jar file. For example if your libraries are present in suppose lib folder then give the complete lib folder along with the jar file.