I have a .property file in my Java project. In that property file have more than 20 values. Now I want to parse that property file and change the specific property value at run time(that is when run the install file). I have used following code
Section
${ConfigWrite} "C:resource\conf.properties" SET WEBSERVICE.URL=http://localhost:8080 $R0
;$R0=CHANGED
SectionEnd
After running exe file ,the property added in property file like this
SETSERVER.URL=http://localhost:8080
I don't know why the SET words comes before this variable?
My requirements:
I need to give value for SERVER.URL property at run time (while installing the exe file)?
I need to replace the value of SERVER.URL property.but Using above added one more new property in that file.
I have used NSIS plugin in Eclipse on Windows platform.
You are missing some quotes when calling the macro, also there is no need to specify SET (in the example from help, SET is actually part of a command in a DOS batch file), and I guess that it is better to add a backslash to the path after the disk drive.
The doc states that the syntax is:
${ConfigWrite} "[File]" "[Entry]" "[Value]" $var
Therefore your call must be:
${ConfigWrite} "C:\resource\conf.properties" "WEBSERVICE.URL" "=http://localhost:8080" $0
Note how the parameters are splitted between the parameter name WEBSERVICE.URL and the value =http://localhost:8080 (note the equal sign at the beginning).
You can make the directories dynamic too:
${ConfigWrite} "$INSTDIR\resource\conf.properties" "WEBSERVICE.URL" "=http://localhost:8080" $0
Related
My code has three property file and I want to give input through maven. How to give input for three files in VM agrument.
How to pass the -D System properties while testing on Eclipse?
I am following this link. But this link shows only for one property file. I want to give for three property file at once. Please suggest how to do it
You can use the mentioned approach multiple times like :
-Dkey=value -Dkey2=value2 -Dkey3=value3
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:
How to make program i made by java know certain file types and make windows open that certain extension by it ?
How i can put a picture to put it for that extension when it's the default program ?
As example when i setup a FOX-IT reader it terns all PDFs files into FOX-IT reader & the FOX-IT picture putted on the PDFs files also ?
if there is a class that access a certain file in windows ?
You're talking about changing Windows settings, rather than anything to do with your program itself.
This is a question about Windows, not about Java.
Normally, you would hold shift while right-clicking on the file, select "Open With" and then pick the program that you want to use to open the file type.
However, since you are talking about a Java program, you probably don't have an executable to run.
In this case, you will need to create the association in the registry yourself.
As always when dealing with the registry, don't change things there unless you know what you are doing, as you can break your system.
Under HKEY_CLASSES_ROOT, create a new key for your file type. I'll use the ".abc" extension for this example, so first create a new key with the name ".abc".
Set the (Default) value of your key to "abcfile"
Now, create another key (again under HKEY_CLASSES_ROOT) named "abcfile". The (Default) value here is the name you will see in the Type column.
Add the following tree of keys underneath abcfile:
abcfile
| shell
+-| open
--+--| command
In the (Default) value of "command", put in the command that you wish to run when opening the file. Use quotes for paths with spaces, and "%1" in place of the filename.
For example:
"C:\Program Files\Java\jre7\bin\java.exe" -jar "C:\path\to\jar\MyJar.jar" "%1"
To change the icon, you will need to make another key under "abcfile" named "DefaultIcon".
Set the (Default) value of this key to the path to your icon file.
To open an application associated with the file extension you'll need to use the java.awt.Desktop class. Oracle has a tutorial with sample code.
Getting the icon for an application is more difficult. Your best course of action is to include standard icons as resources in your application; that should cover most scenarios.
I have property file in windows containing a absolute file path like following:
[PRAXIS]
PVS=CDP_Z1
PXID=94773
[SENDEN]
PVS=CDP_Z1
DATEI=C:\imex_workspace\1535_1297160840340.1247
VERSION=2.5
[STATUS]
ERRORLEVEL=0
ERRORTEXT=
READY=0
This A file contains a file path of B file. I would like to use Java Properties class to write the READY property to 1, the others remain the same.
Properties p = new Properties();
String upload = "a.ini";
p.load(new FileInputStream(upload));
if(p.get("READY") != null && "0".equals(p.get("READY")))
{
p.setProperty("READY","1");
p.store(new FileOutputStream(new File(upload)),null);
}
somehow the file path inside a.ini is broken after a.ini has been updated.
Someone help to find out the best way to write a property inside a file (might not be ini,could be txt file).
The reason behind your problem is that for Java Properties files, the backslash character is used as escape character as in C or in Java language.
This file you posted in your question, is not a valid Java properties file, it's a Windows INI file. Windows INI file differ from Java properties file since they have "sections" (praxis senden status in your example), and also because paths are specified in DOS format, which means that backslash (\) is used as path separator. In Java path separator can be used as backslash (\)in Windows, but most commonly the unix slash is preferred (/). The thing is that, if you want to use the backslash you need to "escape" it, so your path should be specified with double backslashes:
DATEI=C:\\imex_workspace\\1535_1297160840340.1247
or otherwise:
DATEI=C:/imex_workspace/1535_1297160840340.1247
in this way the path is compatible with the Java properties files format. But this can have side effects with the Windows application that uses this .ini file.
To solve this problem, I think you'd better to use an appropriate library to deal with Windows .ini configuration files, which will guarantee to cover this case, but also other possibilities that you may not have considered, since Java properties files follow a different specification than the Windows .ini format.
Here you find a couple of libraries you may want to consider:
Ini4J
Apache commons configuration
JIniFile
Is there a way of accessing the current script's absolute physical path via a variable/property? There doesn't appear to be anything listed via a Debug Sampler.
It's incredibly annoying that actions like loading CSV files and JMX Includes uses the current working directory as its relative path.
I used the answer provided by haridsv. It worked great except that I needed to put the directory to the JMX file in a variable. I made a "User Defined Variables" component and used BeanShell in the variable's "Value" field like this:
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}
The first BeanShell section calls the Java class that gets the directory in question. The second appends a file separator to the path, which is of course optional.
Include Controller
As per component's reference:
This element does not support variables/functions in the filename
field.
However, if the property includecontroller.prefix is
defined, the contents are used to prefix the pathname. If the file
cannot be found at the location given by prefix+filename, then the
controller attempts to open the fileName relative to the JMX launch
directory (versions of JMeter after 2.3.4).
You can pass JMeter a java property named includecontroller.prefix
which can be used to prepend a directory to the JMX file you're
including.
1) In case of console launch use:
-Jincludecontroller.prefix=/full/path/to/jmx/scripts/dir/
2) in case of GUI - add the same to .sh/.cmd/.bat file or write a wrapper file;
3) in case of Jmeter Ant Task usage - set as separate property:
<jmeter
jmeterhome="${jmeter.home}"
testplan="..."
resultlog="...">
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="includecontroller.prefix" value="..."/>
</jmeter>
CSV Data Set Config
As per component's reference:
Relative file names are resolved with respect to the path of the
active test plan.
Absolute file names are also supported, but note
that they are unlikely to work in remote mode, unless the remote
server has the same directory structure. If the same physical file is
referenced in two different ways - e.g. csvdata.txt and ./csvdata.txt - then these are > > treated as different files. If the OS does not distinguish between upper
and lower case, csvData.TXT would also be opened separately.
You can declare a test plan variable that retrieves parameter value with the folder containing csv data files:
e.g.csv.path | ${__P(csv.path, ${__property(user.dir)}${__BeanShell(File.separator,)})}
CSV Data Set Config
Filename = ${csv.path}${__P(users-list,)}
Setting from console:
-Jcsv.path=/full/path/to/csv/data/dir/
Setting for distributed testing setup:
-Gcsv.path=/full/path/to/csv/data/dir/
By saying "current script's absolute physical path", I am guessing OP is referring to the location where the testplan (jmx file) is loaded from. I needed exactly this to generate a CSV file from BeanShell script at the beginning of the run, which is subsequently used in a CSV Data Set Config to read back, so I wanted the script to work just like how the later works when no path is specified. I went through the JMeter source and found this working solution:
import org.apache.jmeter.services.FileServer;
log.info(FileServer.getFileServer().getBaseDir());
I tested this and saw the correct path in the jmeter.log.
My particular issue was that my relative Include Controller path included a backslash which broke on Linux and OSX.
The solution was to use a forward slash in relative paths, which works on all platforms.