-1

I would like to delete the 'CATALINA_HOME' using java code. Please let me know if someone know this type of problem.

Suppose already set 'CATALINA_HOME' = C:\Program Files\Apache

While installing the software, my software should use the my customize tomcat7 and that store in different location.

'CATALINA_HOME' = D:\Installer\Apache

while running the software it find the tomcat this location 'CATALINA_HOME' = C:\Program Files\Apache but my location is 'CATALINA_HOME' = D:\Installer\Apache

deepaksharma
  • 281
  • 3
  • 6
  • 12

1 Answers1

1

I would like to delete the 'CATALINA_HOME' using java code.

Sorry, but you can't. A program (at least on Linux / Unix / Solaris) cannot modify the environment of its parent shell. At most, a program only sees a snapshot of its parent's environment variables ... as they were when the parent forks the child process.

(Windows variables work a bit differently, but I think the same restriction applies ...)

The only thing that a Java can do (reliably / portably) is to change the environment variables that a child process of your Java process will inherit. You can do that using ProcessBuilder.


Now in theory, a program could attempt to modify the source of the variables' values:

  • On a Unix like system, they often come from one of the shell's RC files; e.g. $HOME/.profile, $HOME/.bashrc and so on ... depending on the shell. Or the variable may have been set in the "init" script that launches Tomcat.

  • On a Windows system, the may have come from the registry, or a BAT file or ...

The problem is two-fold:

  • It is impossible to be entirely sure where the value really comes from.

  • Even if you can be sure, changing the source of the value won't affect the respective shell's current value for the variable.


Note: this is not a shortcoming of Java. You would have the same problem when coding in C, C++, Python ...

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216