i cleaned and built my program in net beans. i want to use jar file but i dont know how can i set -ORBInitialRef ?
java RunServer -ORBInitRef NameService=corbaloc::localhost:777/NameService
Is it some kind of a java VM argument (or System property) specified like
java RunServer -DORBInitRef <value>
because simply passing the values to the java command is passing arguments to the RunServer program.
It doesn't really matter whether it's a command line argument, or a JVM system property that's set, as long as it gets passed into the ORB.init() function. The CORBA Orb init() function is smart enough to parse the arguments and pass the arguments that begin with -ORB along during ORB creation.
Take a look at some java ORB initialisation examples here: http://www.novell.com/documentation/extend52/Docs/help/MP/orb/tutorial/orbInit.html
Related
I want to pass argument to java application so the program can read it as System Variable.
Essentially, the arguments passed should be read through: System.getenv("server.name")
I am aware about spring properties - application.properties but this is not a option for me on current project. The use case is to read from System environment or read those passed as flags/argument to jvm using System.getenv.
Essentially I should be able to read passed arguments through System.getenv("server.name")
Note:
I have tried -Dserver.name=xyz and --server.name=xyz but they were not readable throughSystem.getenv().
I don't have the option of creating system variable on this server. So this is not an option. Only thing i can do is pass arguments to the program.
This question already has answers here:
Why do JVM arguments start with "-D"?
(4 answers)
Closed 2 years ago.
This might be a trivial question I am asking, but I did not get this required info in any docs, may be I am overlooking. Currently I am using OpenJDK 8.
EDIT:
Apologies, specific use case, I am running Spring boot jar.
While passing JVM arguments we options like
-Dspring.profiles.active=local
But lately I have found that instead of -D many places I found --
--spring.profiles.active=local
It would be great to know about both and difference and where to use them.
The syntax for the java command is:
java [options] mainclass [args ...]
There are alternatives where you specify something other than mainclass, but the important part is that options comes before that part and args comes after that part, i.e. they cannot be intermingled.
The java command supports many options, one of which is:
-Dproperty=value
Sets a system property value. The property variable is a string with no spaces that represents the name of the property. The value variable is a string that represents the value of the property. If value is a string with spaces, then enclose it in quotation marks (for example -Dfoo="foo bar").
So that it handled by the Java runtime.
args is a list of program arguments, and is handled by Java code, which means they can be anything. It's up to the code processing them to decide where they mean.
A Spring program uses a SpringApplication method to process those arguments. See your main method:
Register a CommandLinePropertySource to expose command line arguments as Spring properties.
See the javadoc for more detail.
Spring also has a PropertySource for making Java System Properties available as Spring Environment properties, which is why Spring can use properties defined either of these commands:
java -Dfoo=bar mainclass
java mainclass --foo=bar
I've an equinox application and I want get some eventual command line parameters that the user can use. How can I get these parameters?
The list of possible arguments are listed in the EclipseLauncher class as constants. If you want, you can get the constants of the class with reflection. System property names are prefixed with "PROP_".
This might work for one version, but not for other. I would not recommend this.
You can get the system properties via System.getProperties() (I guess this was trivial).
If you want to now if the arguments have been passed in Oracle based JVM with the sun.java.command system property. This will not work with other JVM implementations.
Non of the options above are suggested to use in production :). I would be interested in the use-case you want to implement by getting these arguments programmatically.
I have an external program that I'm running.
for some reason, the code owner didn't give me the code or and good documentation, I know how to run this code but it was written originaly to be executed from command line and not from JAVA.
the effect on me is that this application uses an ENV variable and relay on its value (a path on the computer for the output).
I want to change that value, how can it be done without running it from a batch file?
I assume you are executing this program using one of the Runtime.exec() methods in Java code to create a Process.
Note that some of those methods allows you to pass environment variables to the process you are creating, for example exec(String[] cmd, String[] envp).
Alternatively, the Map returned by ProcessBuilder.environment() can be manipulated for the same effect.
how can it be done without running it from a batch file
Just set global environment variable. All new processes will see it (excluding those inheriting environment from old parent process).
See also How do I set environment variables from Java?.
This answers the question's title. Which doesn't match the question's body, btw. ;)
See this post. It usually helps to first start a search here before posting a question. If you already tried that solution, it really helps the Helpers to let them know that you tried it and what went wrong.
In your command prompt first set the required variable
set FILELOCATION=<PATH TO FILE>
java MyProgram
In this case the FILELOCATION will be available till you close the program.
Not setting variable will be dependent on OS.
For Linux or Solaris you can do :
export FILELOCATION=<PATH TO FILE>
In case you are looking for command line parameters then you can use something like this:
java MyProgram PathToFile
There is a better way of doing this java -DFILELOCATION=<PATH_TO_FILE> MyProgram
Edit: As per comment.
Just use ProcessBuilder to set ENV variable in Java code.
I am executing an application using Java application (Runtime.get...) but now before running the application I have to set temp path.
set tmpdir=%temp%
Is it anyway I can execute above command using Java?
Running set in a separate Runtime.exec() invocation wouldn't help at all: it only ever affects the process that it runs in and each exec() call produces its own process.
What you need to do instead is provide the environment variable to your Runtime.exec() call using this two or three argument variant.
Better yet, scrap Runtime.exec() and use ProcessBuilder instead. With this you can simply use environment().put("tmpdir", "somevalue") to set the environment variable you want (you can even get the value of %temp% from that Map).
Could you execute a .cmd/.bat file rather than the app directly?