Ask Your Question
0

Remove java from path - Windows

asked 2014-08-13 12:40:26 -0500

tek0011 gravatar image

updated 2014-09-15 10:33:29 -0500

We are having an issue with some modules. They are adding the correct path, but they do not remove the old path:

C:\Windows\system32>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IBM\RationalSDLC\common;;C:\Program Files (x86)\NTP\bin;C:\Program Files (x86)\Puppet Labs\Puppet\bin;C:\Program Files\Java\jdk1.7.0_50\bin;C:\PROGRA~1\apache-maven\bin;C:\Program Files\Java\jdk1.7.0_55\bin

You can see that it added the correct path at the end, but the original version jdk1.7_50\bin still exists. How can we make sure that it removes the old version every time it installs a newer version?

Edit: More importantly what we need to do is have it search for the JAVA_HOME path variable, compare that against Path variable, delete any java directory that doesnt belong, and copy the JAVA_HOME to Path. Hope that makes sense.

edit retag flag offensive close merge delete

Comments

It appears the main java manifest does not remove old java directories from the path variable. Anyone been able to edit it so that it does?

tek0011 gravatar imagetek0011 ( 2014-08-14 07:09:44 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-09-15 10:46:09 -0500

updated 2014-09-15 10:46:25 -0500

This appears more to be the actual JDK install not cleaning up its old path. Can you post the manifests/module you are using?

edit flag offensive delete link more
0

answered 2014-09-15 11:11:28 -0500

tek0011 gravatar image

I was able to resolve this by doing the following:

Specifically:

**define obsolete_java {
    windows_path {
       $name:
           ensure => absent,
           directory => "C:\\Program Files\\Java\\$name\\bin";**

and

    # Atttempts to remove multiple directories containing Java from PATH
    obsolete_java {['jdk1.7.0_67','jdk1.7.0_65','jdk1.7.0_60','jdk1.7.0_55','jdk1.7.0_51','jdk1.7.0_45','jdk1.7.0_40','jdk1.7.0_25','jdk1.7.0_21']:}

    # Adds %JAVA_HOME%\bin to beginning of PATH
    windows_env { 'addjavatopath':
      ensure      => present,
      mergemode   => prepend,
      variable    => 'PATH',
      value       => '%JAVA_HOME%\bin',
    }

We decided to prepend it to PATH and then we would never have to worry about removing anything. In its entirety, ya it needs to be cleaned up.

#
# Installs and manages Java on Windows machines.
# $source should be set to the name of the .exe that will be copied over.
# $package should be the name of the installed program. Easiest way to figure this out is to install manually, then look at installed program list.
# $file should be equal to the name of the files that get created by the install, such as 'jdk1.7.0_55'. Used to set the path.
#
define obsolete_java {
    windows_path {
       $name:
           ensure => absent,
           directory => "C:\\Program Files\\Java\\$name\\bin";
    }
}

define windows_java::setup (
  $ensure        = 'present',
  $source        = undef,
  $file          = undef,
  $package       = undef ) {

  case $::osfamily {
    Windows  : { $supported = true }
    default : { fail("The ${module_name} module is not supported on ${::osfamily} based systems") }
  }

  # Validate parameters
  if ($source == undef) {
    fail('source parameter must be set')
  }

  if ($file == undef) {
    fail('file parameter must be set')
  }

  if ($package == undef) {
    fail('package parameter must be set')
  }

  # Validate input values for $ensure
  if !($ensure in ['present', 'absent']) {
    fail('ensure must either be present or absent')
  }

  if ($caller_module_name == undef) {
    $mod_name = $module_name
  } else {
    $mod_name = $caller_module_name
  }

  if ($ensure == 'present'){
    # ensures main directory exists
    file {'C:\Program Files\Java':
      ensure => directory,
    }

    # copies source executable over
    file { "C:\\Program Files\\Java\\$source":
      ensure             => present,
      source             => "puppet:///extra_files/java/windows/$source",
      before             => Package["$package"],
      source_permissions => ignore,
    }

    # Name of package must match name when installed
    package { "$package":
      ensure             => installed,
      source             => "C:\\Program Files\\java\\$source",
      install_options    => '/s',
    }

    # sets JAVA_HOME. If already existant, replaces it.
    windows_env { "JAVA_HOME=C:\\PROGRA~1\\Java\\$file":
      mergemode => clobber,
    }

    # Atttempts to remove multiple directories containing Java from PATH
    obsolete_java {['jdk1.7.0_67','jdk1.7.0_65','jdk1.7.0_60','jdk1.7.0_55','jdk1.7.0_51','jdk1.7.0_45','jdk1.7.0_40','jdk1.7.0_25','jdk1.7.0_21']:}

    # Adds %JAVA_HOME%\bin to beginning of PATH
    windows_env { 'addjavatopath':
      ensure      => present,
      mergemode   => prepend,
      variable    => 'PATH',
      value       => '%JAVA_HOME%\bin',
    }

    # LEGACY - Adds java to the path.
    # windows_path {'javaPath':
    #  ensure      => present,
    #  directory   => "%JAVA_HOME%\\bin",
    # }
  } else {

    package { 'remove-package':
      name   => "$package",
      ensure => absent,
    }

    windows_env { 'JAVA_HOME':
      ensure    => 'absent',
      mergemode => clobber,
    }

    # LEGACY - windows_path {'remove_java_path':
    # ensure    => absent,
    # directory => "C:\\Program Files\\Java\\$file\\bin",
    #}

    windows_env {'removejavapath':
     ensure    => absent,
     variable  => 'PATH',
     value     => '%JAVA_HOME%\bin',
    }
  }
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-08-13 12:40:26 -0500

Seen: 595 times

Last updated: Sep 15 '14