Got a classic batch script to launch a jar, where I set up my classpath
set CP=%CP%;some.property
set CP=%CP%;some.jar
And when launching my jar
start java.exe -cp %CP% my.class.main args
It doesn't read the property file I've passed in the classpath and tries to read the one in the main .jar
What could be wrong here? The path is correct, I've double checked it.
I was adding the file and not the folder of the file in the classpath.
Don't:
set CP=%CP%;folder/conf/file.properties
Do:
set CP=%CP%;folder/conf/
Related
I'm setting up an external hard drive with portable apps, and there are some CLI tools that I'd like to easily access.
I've done it before but I forgot how; basically, I have a file which sets the PATH variable for all the required CLI programs, and then allows me to use the command prompt normally.
How do I do this without having to run the file from another command prompt, but by double clicking the Batch file?
If your command line tools are in a folder named CLiTools next to the batch-file, then you could have 2 lines as the batch-file content.
#set "path=%path%;%~dp0CLiTools"
#cmd
You can double click the batch-file, it will open cmd with the modified setting of %path% and you can enter commands as you would normally do. If you have i.e. xyz.exe in the CLiTools folder, then you can type xyz at the current command prompt and will be recognized as a command.
The changed environment applies to the current child cmd session that inherited the environment.
%~dp0 is the drive and path of argument 0 which is the drive and path to the batch-file in this case.
In my demo project's build event, (a class library project), to copy the build result .dll to a specific folder, (auto-created if it doesn't exist), I added following command line in Post-build event command line section:
xcopy /Y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)DemoApp\bin\$(ConfigurationName)\Packages\"
It works perfectly.
Then I tried to replace that command line with a call to a new batch file called CopyPackage.bat located in $(SolutionDir). The content of the batch file is exactly the command line above:
call $(SolutionDir)CopyPackage.bat
Then I rebuild the project and get following error:
Severity Code Description Project File Line Suppression State
Error The command "call C:\TestProjects\DemoApp\CopyPackage.bat" exited with code 4. DemoApp
Do I miss something?
The solution after getting some hints from you all:
In post-build event command line I put: (see the params)
$(SolutionDir)CopyPackage.bat "$(TargetDir)$(TargetFileName)" "$(SolutionDir)DemoApp\bin\$(ConfigurationName)\Packages\"
In batch file CopyPackage.bat :
set targetfile=%~1
set targetdir=%~2
echo %targetfile%
echo %targetdir%
xcopy /Y %targetfile% %targetdir%
No need to use call you can simply invoke the batch script directly.
I do have to caution you, since the post-build targets have no way of knowing the inputs and outputs of the task, it will always have to execute the script, even if nothing has changed.
Instead, if you convert this to a msbuild target and you implement the input/output signalling correctly, you'll gain a lot of time by being able to leverage the incremental build features of MsBuild.
For example:
<Target Name="CopyOutputs"
Inputs="#(BuiltAssemblies)"
Outputs="#(BuiltAssemblies -> '$(OutputPath)%(Filename)%(Extension)')">
<Copy
SourceFiles="#(BuiltAssemblies)"
DestinationFolder="$(OutputPath)"/>
</Target>
More information on incremental builds and input/output signalling can be found:
MsBuild: transforms
MsBuild How-To: build incrementally
Extend the build process
call is an internal command of cmd.exe you should use
cmd.exe /c "$(SolutionDir)CopyPackage.bat"
instead.
Edit:
The content of the batch file is exactly the command line above
VS variables will not be properly resolved inside of the .bat file. You should pass them as parameters to batch file.
Changing the path in your CopyPackage.bat to absolute path can help resolve this.
Properties like these: $(TargetDir),$(SolutionDir) are recognized by msbuild.exe tool since they are part of msbuild properties and are defined or imported into current environment.
When using xcopy /Y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)DemoApp\bin\$(ConfigurationName)\Packages\" in post-build-event,the msbuild tool can recognize them.So for the first time, it succeeds.
However, for the second time. The msbuild engine can recognize properties in post-build-event, so it calls the .bat successfully. But since the .bat can't recognize the Msbuild property(These properties can only be recognized by MSbuild.exe, not .bat or cmd.exe), the build will fail for not finding the path.
I want to run a bat file located in a specific location with some parameters.
If i cd to that location and then run the bat file with arguments, it works in command prompt. But how do i run it with absolute path in Jenkins?
I want to do something like this
call "C:\Program Files (x86)\SmartBear\soapUI-4.5.2\bin\testrunner.bat C:\Dev\COM\B2B\Vishal\SOAPUIGIT\B2bSoapUI.xml -s"Amend Order New Framework" -M"
however this gives an error saying
"The filename, directory name, or volume label syntax is incorrect."
Solved it.
The issue was with the double quotes.
Changing it to this worked
call "C:\Program Files (x86)\SmartBear\soapUI-4.5.2\bin\testrunner.bat" C:\Dev\COM\B2B\Vishal\SOAPUIGIT\B2bSoapUI.xml -s"Amend Order New Framework" -M
I have a batch script that is in version control and can be checked out into any directory, but it should only work on the current directory:
#echo off
zip -9 Setup.zip Setup.exe SetupGuide.pdf
Now the batch file should retrieve from Setup.exe the version, check a network drive whether the file Setup.<versionstring>.zip exists and throw an error if it does, or else copy the Setup.zip to the network drive as Setup.<versionstring>.zip.
I found that I can get the version string using WMIC, but it seems to only take the full path name and furthermore needs double backslashes. How can I tell WMIC that I want a file from the current directory?
T:\Installer\SetupFiles>wmic datafile where name='.\\Setup.exe' get version
Keine Instanzen verfügbar.
I think you need to provide the full path to the executable:
wmic datafile where name="T:\\Installer\\SetupFiles\\Setup.exe" get version
i want to call the java class in batch file.
how can i call. can tell me any commands which call the class file
Thanks
Krishna
#ECHO OFF
java -jar "Path/To/The/Jar/Whatever.jar"
I would recommend first jaring up your class(es) and providing a link to the jar.
if you are having a class Myclass with package name com.mycomp.util then you have to go to the parent dir of "com" for example "c:\src" is the folder that contains com package then
your command should be in the batch file
cd c:\src
java -cp jar1;jar2; com.mycomp.util.Myclass
now call the batch file.
If you have compiled your .java file, and have the .class file, containing bytecode for your main function, then just run:
java myclass
where myclass is the module name (file has to be myclass.class).
Just use this in ur .bat file
java -classpath folderName/example.jar; com.example.package.ExampleProgram
if you are placing the .bat file in the same folder with the jar, then its not necessary to mention the folderName
#echo off
java -jar "C:\path_to_jar_directory\test.jar" "C:\path_to_arguments\property.properties"
You can do the following:
Open a new Text File in Notepad.
Write the following lines of code, then saves it as "MyFile.bat" (Note we are saving as BAT File.
#ECHO OFF
javac YourClass.java
java YourClass
Now double click the BAT file to run, it should execute your java program.
Note: The BAT file and Java Class should be in the same directory.