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.
Related
I need to export/import my spk file via windows Batch script.
For which I have been referring this document
But this document does not mention how to save the file (I mean with which extension .bat or .sas)
My command:
ExportPackage -profile "SAS_MW_TEST" -package "F:\mypath\Package4.spk" -objects "/_Applications/_05_MW/_01_SAS_MW/_20_Processes/savedesk(Folder)" -subprop -types "Condition,BusinessRuleFlow,ExternalFile,Cube,SearchFolder,Table,GeneratedTransform,OLAPSchema,InformationMap.OLAP,Measure,Column,Job.CubeBuild,Action,Library,MiningResults,DeployedJob,CalculatedMeasure,Hierarchy,InformationMap.Relational,RootFolder,Prompt,Document,ConditionActionSet,DecisionLogic,Dimension,Note,StoredProcess,PromptGroup,Job,OrchestrationJob,MessageQueue,Service.SoapGenerated,Level,SharedDimension,DeployedFlow"
ExportPackage is an executable program that you can run out of a batch file.
Use Notepad or any other text editor (which includes any SAS code editor), place the ExportPackage program command in the editor and use the File/Save As feature to save the file as something like myPackageExporter.bat
If the items in the package are say stored processes whose metadata says the source code is in an file system folder (aka source code repository), you will probably also want to zip up the folder.
This macro can help you prepare the batch script, ready for export: https://core.sasjs.io/mm__spkexport_8sas.html
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/
I have an internal software that generates folders with batch files. The batch file is supposed to run a matlab file in the same folder, but in fact it just runs Matlab and the previous Matlab script (not the one in its folder).
I need a command in my batch file to recognize its own location(folder) and run the matlab file from the same folder.
Thank you in advance
use the %0 parameter. This on is an implicit parameter that you do not pass to the scrip
try this and see if it helps you get going:
#echo %~dp0
the ~dp sequence strips the name and extension from the full path to the script.
note that this works only from within a script, not from the command prompt
References: for-command
I have some java executable program initialized from cmd. My problem is as following: I would like to read all files from some directory. Next, I would like to run the program as many times as many files I have in my folder. The required inputs are the path to the file with data and the name of the file where the results will be written. Now my question is, how can I write a simple batch file which will do it for me?
For example:
I have a list of files in my folder
file_1.xls
file_2.xls
file_3.xls
I want to run a loop and for each file initialize line specified below:
java -jar -Xmx1000M Program.jar pathToInputFile PathToOutputfile
For example for file file_1.xls I want to write the result to the file with the same name but different extension and at the begining of this file add some constant prefix. In case of file_1.xls the results I would like to write as Output_file_1.txt
for file_2.xls -> Output_file_2.txt
for file_3.xls -> Output_file_3.txt
and so on...
Can anyone help me?
pushd "c:\excel_files"
for %%F in (*.xls) do (
java -jar -Xmx1000M Program.jar "%%~nxF" "Output_%%~nF.txt"
)
Though I'll recommend you to use -classpath and direct call of the entry point class instead of direct call of the .jar .
In an application folder, there are n number of files. The application exe name "ClearMongoDb.exe" take some parameter like dbname.
ex: clearMongoDb.exe -db "SynchoMeshDB"
I am stuck with below :
I want to execute the exe from a batch file with same parameters
the batch file will be placed in the same application folder.
user can copy the application folder to any location
If user double clicks on the .bat file the exe should start working.
User should not be required to make any changes in .bat file
If the batch file is in the same folder as the executable, then you can do like this:
clearMongoDb.exe -db "SynchoMeshDB"
Just add this line in your batch file. Now the refference is in the same folder as the executable, no matter where the ENTIRE folder is moved (or at least the executable and batch file).
update:
As foxidrive mentioned, in order to see the output, place a PAUSE command at the end. So, your batch file should be like this:
clearMongoDb.exe -db "SynchoMeshDB"
PAUSE
If you just want to pass all the parameters given to a batch file to an EXE called from that batch file, use %*.
foo.exe %*
How do I pass command line parameters to a batch file?
You can just use a shortcut to the file and add the parameters on the path. no need for an extra batch file.
edit: unless you want to pass the batch file parameters to the .exe, as some people read this. what do you want to do? execute a .exe with the same parameters each time, or pass the .bat parameters to the .exe?