I have a properties (jdbc.properties) file in "D:\UTL" location that needs to be created and defined in the weblogic startup script. Can someone help quickly ?
I have added like this which didn't work.
set UTIL=D:\UTL
Do I need to export this variable ? If yes, I am getting "export is not an internal /external command" error when I'm doing so. Appreciate your help.
If you wanted to export parameters, you can do so in the setDomain.sh. Specify your new variable and set it there in the same format as the previous variables.
You can do it like
NEW_VAR = "${NEW_VAR}"
export NEW_VAR
if you want to use a emote file, export what you need in the file and in the setDomain, run a source /path/to/file/file.sh
If this is application specific and you only want it to load for a particular application startup, please import property file in to application as and when it is required.
Related
im trying to access a property in a .conf file located in the target directory with my jar and its returning null. i followed the spring documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html#deployment-script-customization-conf-file
i believe i should be able to access the properties of the app.conf by simply coding the following:
System.out.println(System.getProperty("dbName"));
System.out.println(System.getProperty("dbUser"));
System.out.println(System.getProperty("dbPassword"));
all three return nulls when i try to run the jar from the terminal. my app.conf file looks like so:
JAVA_OPTS=-DdbName=RandomDb -DdbUser=devUser -DdbPassword=password90210
any recommendations to fix this? i know i can add them to the vm args in the run configs buts i would like to get this to work from a .conf file to avoid exposing sensitive information.
I have never really had the need to use server environment variables before. I am able to set them easily and that is not the issue. I have a program that based on the value of the server environment variable, it will determine the volume and several other folders that the program will write a file to. How can I do this effectively? Once I set the variable in the run config how do I reference it in the actual code?
The program is designed to retrieve a jsonRequest and based on that place a pdf file in an appropriate folder. The path I am referring to is the path that the pdf file is placed in.
You can do so by calling System.getenv()
String yourname = System.getenv("yourkey");
As an alternative you could always use System properties and then them via -Dname=value in your command line starting your app.
As you see here, when starting through eclipse, your system environment might still be in place:
I have a number of Java property files which used to be included in the standard resources directory and the following property holder of Spring works fine.
<context:property-placeholder location="classpath:/project/myproperty.properties/>
For some reason, I need to move them to another location so that they are not included as part of the JAR. The deployment script will handle them and copy them to a specific location called config.
I added the new location to the classpath argument of my java command, however, the above statement always fails, complaining no property file is found. My command is a follows
java -classpath "C:\Deployment\config" ............
And the property file does exist under:
C:\Deployment\config\project\myproperty.properties
Can someone let me know what I did wrong?
You can try to do it like this:
<context:property-placeholder location="file:${my.config.location}\project\myproperty.properties"/>
And to add the property in the environment properties:
java -Dmy.config.location="C:\Deployment\config" ...
Hope this helps.
I am writing an application (basically eclipse plugin), so there are few combo-box, drop-downs etc, which I am getting values for them dynamically via XML file. My doubt is which is the best way to store these files in a particular directory so that it can be read in both Windows as well as Linux.
Initially I tried to create a config path under {eclipse.home.location} like:
String finalPath = System.getProperty("eclipse.home.location") +"/myAppConfig";
and store all of my plugin's configuration there (not only configuration but few helper jars which I programatically read in my plugin). But there is a probabilty that Eclipse installation maybe in shared location and user may not have write access to it.
I also tried to store it in a program files directory using:
System.getenv("ProgramFiles");
But this fails under non-windows environments. So my question is can anyone shed a light on this so that I can store in some common directory where it is valid for both windows and linux?
Kindly let me know if my wordings are confusing. Or is it possible to store my config files under plugins directory and get the path like this /plugins/myConfigDir ?
Try using the getStateLocation() method in Plugin.
That will give you an IPath that points to a user specific workspace location.
Anyone plz let us know what to do when we have some configuration file which is basically xml.I want to for example give the path to save the image(for my java program) in a folder from some config file (xml in my case).In that case where should the config file be kept.Rt now every thing is converted to jar file when i create a java standalone package.But i want to give some setting from xml file.What to do in that case.How is it possible.This article only provides to create a single jar file for java project but talks nothing about the configuration settings that u can provide from some external source.
Regards
Sagar
I'm not sure I fully understand your question, but if it is where to put the XML file with configuration information, you can place your xml file in the same directory as your jar file, and then pass the XML file name and path into the Jar on the command line when calling the Jar. If you're running it in Windows, this is often done using a shortcut. Then you can get the full path string for the Jar from the main method's String[] arg array that accepts the command parameters.
Sagar,
The fact your java program is a standalone package (.jar file) has no bearing on where your configuration file is stored. Your java package is a program and that program can read any file from the file system that it so desires; it does not have to be part of the code inside the IDE i.e. you don't have to write it when you write the program. What you do need is some way, when you start the program, to find and read said configuration file.
Depending on how you expect the program to be configured, you might put that file in a number of locations. For example, /etc/yourimageprogram/config.xml or c:\program files\yourimageprogram\config.xml or perhaps c:\users\Sagar\Application Settings\yourimageprogram\config.xml. Which you choose of those options really depends on what the use case is and that I can't help with.
However, there are some main points to reading any file:
Does it exist?
Are we allowed to open it for reading?
Are we allowed to open it for writing? Might want to know if we want to update the config?
In Java, typically, you would test this with:
File configfile = new File("C:\test.xml");
if ( configfile.exists() && configfile.canRead() )
{
// read the file
}
else
{
// decide what to do if no config exists.
// might be first run of app.
}
The next stage is to parse the file. There are a number of parsers available for XML including sax and org.w3c.dom. What you need to do is to use these to extract the information you require and store that in a class. Probably a singleton class as you're unlikely to have multiple configuration instances per instance of the program.
I suggest you read about XML Parsers and File Handling under Java. Also look at the File object. See all your options for file io in java. These should give you some indication of how to proceed.