I'm trying to convert a .bat file that actually run a java statement into a PowerShell script, mainly because the .bat file have the user/password hardcoded and a
set /p password="Enter password: " %=%
did not hide the password from the command prompt.
The java command that works fine when I run that from a .bat file or directly from dos prompt and also when I run that from the .bat file.
I ensure that all environment variables are in place as they are set in the batch file.
My problem reside on the following:
When I run it from the command line or directly from the command prompt the java works fine,
when I try run that using the cmd.exe /c to run the line directly doesn't work and if I call the .bat file from the powershell it doesn't work and give the following error.
cmd : java.lang.NoClassDefFoundError
I don't get it... why manually I can run and through the PowerShell script it doesn't work?
Here is my .BAT file that works fine:
@rem ###################################
set IIQPATH=C:\IIQ\IIQ
set exportpath=C:\EXPORT
set /p userid="Enter ID: " %=%
set /p password="Enter password: " %=%
@rem ##################################
echo %exportpath%
set CLASSPATH=%CLASSPATH%;%IIQPATH%\WEB-INF\classes
set CLASSPATH=%CLASSPATH%;%IIQPATH%\WEB-INF\lib\identityiq.jar
set CLASSPATH=%CLASSPATH%;%IIQPATH%\WEB-INF\lib\sqljdbc4.jar
set CLASSPATH=%CLASSPATH%;./split
@rem Export the objects
java sailpoint.launch.Launcher console iiqBeans -u %userid% -p %password% -c "export -clean %exportpath%\Application.xml Application"
Here is my PowerShell code
$iiquser = Read-Host 'Provide User for'$target2' environment'
$iiqpass = Read-Host 'Provide Password?' -AsSecureString
$actualdate=Get-Date -format MM_dd_yyyy
$iiquser
$iiqpass
Push-Location C:\EXPORT
$env:IIQPATH="C:\IIQ\IIQ"
$env:exportpath="C:\EXPORT"
Remove-Item env:CLASSPATH
$env:CLASSPATH="$env:CLASSPATH;$env:IIQPATH\WEB-INF\classes"
$env:CLASSPATH="$env:CLASSPATH;$env:IIQPATH\WEB-INF\lib\identityiq.jar`$time"
$env:CLASSPATH="$env:CLASSPATH;$env:IIQPATH\WEB-INF\lib\sqljdbc4.jar"
$env:CLASSPATH="$env:CLASSPATH;./split"
$commandline="java sailpoint.launch.Launcher console iiqBeans -u $iiquser -p $iiqpass -c "+[char]34+"export -clean $env:exportpath\Application.xml Application"+[char]34
$commandline
cmd /c $commandline
Any hints?
======================= Quick update...
I manually set the variables in cmd windows prompt and into PS Cmd prompt.
when I run my java command without parameters I got the following
C:\>java sailpoint.launch.Launcher
Usage: sailpoint.launch.Launcher [ -d ] [<application> | <class>] <arguments>...
Applications:
setup Bootstrap configuration utility
schema Schema file generator
upgrade Perform data upgrades between releases
patch Perform data upgrades post release
console Administrative console
encrypt Administrative console
integration Integration console
oim OIM Integration console
exportschema Data Export console
exportviews View Export console
keystore Key Store console
parse XML file parser
But when I try run that in PS Command line I got the following:
PS C:\> java sailpoint.launch.Launcher
Exception in thread "main" java.lang.NoClassDefFoundError: sailpoint/launch/Launcher
Caused by: java.lang.ClassNotFoundException: sailpoint.launch.Launcher
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: sailpoint.launch.Launcher. Program will exit.