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:
Related
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.
Can you please tell what is significance of "java.io.tmp" directory?
I noticed this directory is created under webapps folder in my tomcat.
Thanks!
The name itself is a great clue. Its java.IO.TMP, which common sense would tell us is about temporary ios. Since the java.io package is about files then it probably adds up this is a path to store temporary files.
It is not directory, it is property points to a directory to be used as temp folder(directory happens to have same name as property is a tomcat decision). When you want to create temporary file, this property is used as the location for the file. Some example
File tempFile = File.createTempFile("pattern", ".suffix");
tempFile.deleteOnExit();
JVM by default copies the value from TMP/TEMP environment variable. The value can be set when JVM starts. Tomcat sets this for rest of the application to use.
Related : Environment variable to control java.io.tmpdir?
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
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.
I'm writing a program that needs a generic temp folder. I'm trying to find details about the Windows Temp folders. There are two paths that I know about -
In each user directory under AppData\Local\Temp\
This may change depending Windows version?
In the system folder under Temp\ (C:\Windows\Temp)
I'm wondering exactly what Windows does to each of these. If Windows deletes files from either location, when does it do so? How can/should I use these directories for my programming?
EDIT: I have a bigger problem actually - Because of a certain engine I'm running indirectly with my program, which uses files I'm creating in a temp directory, I need a temp directory that doesn't use whitespace characters in the path. Java's System.getProperty("java.io.tmpdir") on Windows gives me the temp that's in the user directory, which on XP is under "Documents and Settings..."
Not good. Any suggestions? This is why I'm wondering about the C:\Windows\Temp\ directory...
This will give you the path to the windows temp directory in Java.
File.createTempFile("temp-file", "tmp").getParent()
Not quite. There is a user and system folder, the default location of which varies according the windows version, system folder name, and indeed in older versions of windows was the same for both the user and system case. However, these defaults can be over-ridden (they are on the system I'm using now, where they aren't on the same drive as the system folder).
The locations are stored in system variables. Some frameworks (.NET, VB6 and no doubt others) give you convient ways to find the paths rather than having to look up the system variable (e.g. System.IO.Path.GetTempPath in .NET).
Windows does not clean up the temporary folder for you (which is why it's worth blasting out old files it every few months on your own machine), it's up to you to play nice. Create a file or files unlikely to step on the names any other software is using (they should take care to do the same, and so any name should do, but it's always good to assume the worse of other code on the system), and delete files when you're done (or on application exit at least).
In .NET System.IO.Path.GetTempFileName() will create a new file in the temp area and return the name of it to you, that is reasonably guaranteed not to conflict with others' so use that or similar methods if you can.
It sounds like you have two programs that need to share temp files and one definitely doesn't want spaces in the path name. Probably the easiest thing to do is:
set the TMP and TEMP variable to a common directory
launch each application (from this modified environment) - which should pick up the temp variable
So at the command prompt you could do this:
set TMP=c:\mytemp
set TEMP=c:\mytemp
java -cp x;y;z my.application.Entry
run other application (hopefully it also reads the environment for temp/tmp)
Hope that helps.
To answer part of your question - if you're using .NET, you can use the Path.GetTempPath() method of the System.IO namespace to get the location of the temporary directory.
// Get the path of the temporary directory
string tempDir = Path.GetTempPath();
// "Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file."
string tempFile = Path.GetTempFileName();
The %TEMP% environment variable that's defined on my PC (XP SP3) uses the DOS-style abcdef~1 directory names - hence, if you can pull that variable, you should end up with a path without spaces.
e.g. Start>Run>%TEMP% takes me to C:\DOCUME~1\<user>\LOCALS~1\Temp
However, if a 'super-user' fiddles around with that variable and points it somewhere else, it's possible that things will fall over. You could look at something like this to retrieve the 8-char-and-no-spaces path.
use this code
try { String s=File.createTempFile("temp-file", "tmp").getParent();
System.out.println(s);
} catch (IOException ex) {
Logger. getLogger(Result.class.getName()).log(Level.SEVERE, null, ex);
}
you can try this way
System.out.println(File.createTempFile("temp-file", "tmp").getParent());
String property = "java.io.tmpdir";
String tempDir = System.getProperty(property);
System.out.println("OS current temporary directory is " + tempDir);