1

I have executable jar file and want to run from command line along with the environment variable path as a parameter. In eclipse the code is running well by setting up the path variable in eclipse configuration.Please help.The command that i am trying is given below

java -jar jar_name

  • 3
    Possible duplicate of [How to run a JAR file](http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file) – Vivek Singh Jan 14 '16 at 08:48
  • Hi, the question needs to be clarified firstly. It *does* look like a duplicate according to the incomplete title. But it asks for something *more* - probably how to get to the environment PATH in the jar's code. It's very simple then: just call `System.getenv("PATH")` in your code. No need to pass the PATH explicitly in command line, which is dependent on the OS where you run it. – Petr Bodnár Nov 12 '19 at 18:54

5 Answers5

4
java -jar jar_name.jar -DsystemVariableName=value

Access this value in the code as System.getProperty("systemVariableName");

Environment variable can be directly accessed in the code as System.getEnv("EnvVarName");

Refer : https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getenv()

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
Amal
  • 154
  • 4
  • 1
    This is surely not the correct answer, because provided that the OP really asked for setting a system variable, the `-DsystemVariableName=value` needs to go *before* the `-jar` option - see [documentation for java](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html). Moreover, I think the question needs to be clarified first - see my comment. – Petr Bodnár Nov 12 '19 at 19:00
1

you need to do:

java -jar <jar-file-name>.jar
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
1

java -jar jarfile.jar is the shortest answer possible but note that there are multiple things that maybe need to be set for the jar to run correctly as you may need to specify the Main class or the classpath.

This Oracle tutorials will help.

Davide Spataro
  • 7,319
  • 1
  • 24
  • 36
1

Please see the below link. It has all the information you need http://www.wikihow.com/Run-a-.Jar-Java-File.

asb
  • 11
  • 2
0
java -jar <jar.file> <parameter> 

you can define multiple parameters.

daryal
  • 14,643
  • 4
  • 38
  • 54