我正在尝试将实际运行java语句的.bat文件转换为PowerShell脚本,主要是因为.bat文件的用户/密码是硬编码的,而且
set /p password="Enter password: " %=%
没有从命令提示符中隐藏密码。
java命令在我从.bat文件或直接从dos提示符运行时以及从.bat文件运行时运行正常。
我确保所有环境变量都在批处理文件中设置。
我的问题在于以下内容:
当我从命令行或直接从命令提示符运行它时,java工作正常,
当我尝试运行使用cmd.exe / c直接运行该行时不起作用,如果我从powershell调用.bat文件它不起作用并给出以下错误。
cmd : java.lang.NoClassDefFoundError
我不明白...为什么手动我可以运行并通过PowerShell脚本它不起作用?
这是我的.BAT文件,运行正常:
@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"
这是我的PowerShell代码
$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
任何提示?
======================= 快速更新......
我在cmd windows提示符中手动设置变量并进入PS Cmd提示符。
当我运行没有参数的java命令时,我得到了以下内容
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
但是当我尝试在PS命令行中运行时,我得到了以下内容:
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.
答案 0 :(得分:0)
应该使用的命令是
java -cp .\identityiq.jar sailpoint.launch.Launcher
-cp选项负责在Powershell命令行中设置CLASSPATH。