shortcut to find out the references of the properties file - java

I am writing a java project in which I am making changes in one of the properties files. I am using eclipse juno for my development, now I want an eclipse shortcut from which I can know that the properites file is being used internally in which different java files.
I know that one way is to press ctrl + h and in file search typing the name of the file and in type selecting the .java extension. My query is that is there any other shortcut to know that where this properties file is called internally in different java files
.

There isn't such a built-in command for getting the references of an entry in a property file. The type hierarchy and the "Control + Click"-thing works because the java sources can be interpreted to get actual calls. For accesses to .property files this is not as easy as there are several ways to access them for example.
That's why there sometimes a pattern is used where the properties are only accessed by exactly one Java class. This class then provides the properties as static fields for example. Doing this the compiler helps you in getting the references.

Related

How to use file associations with jpackage?

I am using jpackage to pack my Java application and want to use it to create file associations. I see that the utility supports this via the --file-associations command. Using this, you can point it to a file that includes file association information.
Does anyone know of documentation that gives a better description of how to create this file-association file? The help documentation in the utility itself describes keys that must appear in it, but there's no hint at how it needs to be formatted.
Here is what the packager lists in its own help:
--file-associations — Path to a Properties file that contains list of key, value pairs (absolute path or relative to the current directory). The keys "extension", "mime-type", "icon", and "description" can be used to describe the association. This option can be used multiple times.
Does anyone here know where I might be able to find an example of this that is written correctly or more detailed documentation on exactly how the feature is used? Would be much appreciated if someone could just point me in the right direction.
You need to write each key-value on each line separated by an equal sign without any quote and save as a text file with .properties extension for example
extension=<Your file extension without leading dot e.g. docx>
mime-type=<Your mimetype e.g. application/msword>
icon=<Path to the icon file e.g. word.ico (Windows) or word.icns (macOS)>
description=<Some description e.g. Microsoft Word Open XML Format Document>
I could not find any official documents either. However, this is how I created my properties file which works on the release version of Java 14.

get two input files from CompareEditorInput

My requirement is to use a new external compare tool for certain type of file extensions in eclipse RCP product.
For other files eclipse default compare editor should be used.
In order to achieve this , I am using ASPECTJ to hook to eclipse default compare editor method . In my aspect method I am validating the file which is selected, If the file is a particular type I am trying to call my external compare tool or else continue with using eclipse default editor.
I am not able to get two files( that is left and right input file) from the compareEditorInput Object which is a parameter.
Is there any way to get two input files so that i can pass to my external compare tool??
The compare editor itself does not require that the input comes from files, nor does the base CompareEditorInput class.
Subclasses of CompareEditorInput such as ResourceCompareInput do work from files so you may be able to get the input from them. But these are internal classes and not part of the API.

What are filesystem dot attributes or filesystem.attributes files?

I got a Java project from another developer and I found several files with these two names strewn around the source folder:
vssver.scc
filesystem.attributes
I know the first one is from Visual SourceSafe but what about the second? Are these files from Visual SourceSafe too?
It's difficult to search this as Google simply ignores the dot character in between, even if I put the whole thing in quotes.
Edit: File contents are binary but mostly have references to classes from Java and libraries:
After some digging, it looks to be a (presumably obsolete) Netbeans thing. The only real reference I could find is this Netbeans mailing list post from August 2000, which says it was used to store various IDE metadata about each file.
It is created automatically when you modify some attributes of a file
using the IDE itself. [...] Every file (including directories) stores its
attributes in a filesystem.attributes located alongside it (in the
same containing directory). FileUtil.extractJar specially recognizes
filesystem.attributes in a JAR, so if you jar up your directory then
when it is extracted the jarred attributes will be applied to the
extraction folder.
The post mentions a "future reimplementation" using an XML-based filesystem, which I think has happened by now. This later post mentions using the name .nbattrs to replace the old filesystem.attributes. I'm not a NetBeans user, but this seems to be what happened; for instance, I found an example in this gist.

How to build JAR files dynamically

I'm making a program that needs to be able to let Clients change a setting, and using what I'm calling a "Builder", create a .jar that replaces some constants in a class with their settings.
In other words, I have a GUI that has a few textfields so that when they press the JButton labeled Build, it creates a new Runnable Jar that in a Constants class whose settings are changed with what was in the textfields.
Is this possible? I've heard about ANT Scripts, but I'm not really sure if that's what I'm looking for here.
Thanks
have you considered using a .properties files or something similar instead? You can use ant scripts for what you are describing (check out http://ant.apache.org/manual/Tasks/replaceregexp.html, you could use this task in your build.xml to dynamically change the .java files but it seems a little kludgy) but it might not be the best solution.
Check this page: http://www.mkyong.com/java/java-properties-file-examples/ which has some detail about saving to/loading from a properties file. You could set up your constants class to load it's state variables from this file, and set up the Build JButton to create that properties file.
I'm trying to think of a use case where you would want to modify the class source itself rather than use a properties file, but to be honest I can't. So I suppose you may have some special circumstance where this is not a tenable solution for you, but 99% of the time this is how I would suggest you go about it.

Create dynamic control file in java from template

I need to create a control-file (for SQLLoader) depending on some variables (filename, bad-filename, table to load into, etc).
Right now I have a method in java that creates the file and works fine. My problem comes when I have to modify the structure of that control file. I need to change that in java source code, compile, undeploy previous app, deploy the new one, just to change that control's file structure.
I was wondering if there is a way to make a template where I just pass the variables (mentioned above) but outside java, let's say some kind of xml or something, so I just change that "template" and voilà my app just fill in the variables.
In one of our applications we generate the control file from code (in our case C#, but that doesn't matter)
Create the file from a template (outside of your app), fill in the variables and have your application copy it to the place where SQLLoader expects it.
Only thing you need is for your java app to have permission to write to that directory.
If it is a Java web application this is a little tricky, as writing files from the webapp can introduce a security risk

Categories

Resources