I have a batch file that runs a jar with a few parameters, works fine:

@echo off
java -cp bulkconfig.020.0005.jar com.hospira.bulkconfig.LoadConfig %*

I would like to add some more cababilities with powershell, but I cannot even get powershell to run the same command:


$fullname = $name + ".domain.org"

  ##if online, mark that it is online
  if (Test-Connection -ComputerName $fullname -Count 2 -ErrorAction SilentlyContinue){

   $ip = (Test-Connection -ComputerName $fullname -Count 2).IPV4Address.IPAddressToString

   java -cp bulkconfig.020.0005.jar com.hospira.bulkconfig.LoadConfig $ip test.xml DevId $name


Gives this error:

java.lang.NoClassDefFoundError: com/hospira/bulkconfig/LoadConfig
+ CategoryInfo          : NotSpecified: (java.lang.NoCla...nfig/LoadConfig:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName        : localhost
Exception in thread "main" 

Have not been able to find a solution, some searching makes me think it may be an env variable issue but they look right to me?

PS C:\Users\and62219\Desktop\hop> cd env:

PS Env:\> ls

Name                           Value                                                                                        
----                           -----                                                                                                                                              
CLASSPATH                      C:\Program Files (x86)\Java\jdk1.5.0_11\lib                                                                                                                      
JAVA_HOME                      C:\Program Files (x86)\Java\jdk1.5.0_11\                                                                                                                               
Path                           C:\Program Files (x86)\Java\jdk1.5.0_11\bin;C:\Program Files (x86)\CA\SC\CAWIN\;C:\windows...

Any help would be much appreciated!

  • 1
    How can we help if you don't provide a minimalist script that reproduces the error. Why on earth are you using Java 5? – Ramhound May 4 '16 at 19:35
  • Try using Start-Process to start your Java process in PowerShell. E.g. something like: Start-Process -FilePath "java.exe" -ArgumentList "-cp bulkconfig.020.0005.jar com.hospira.bulkconfig.LoadConfig $ip Spectrum_Hospira.xml DevId $name" -Wait -PassThru – Ƭᴇcʜιᴇ007 May 4 '16 at 19:40
  • I did produce a script that reproduces the error... I expanded on it a little for you. The jar file was written for Java 5, does not work in newer versions. – user2085674 May 4 '16 at 19:40
  • 1
    If the batch file work, call that within the PS script, instead of trying of launch a java .jar file incorrecly within the PS environment. You should be using the full path to java exutable, based on the exception, you must have more then just 1.5 installed. – Ramhound May 4 '16 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.