I have created a batch file to set the path of a jar file whenever i need to use that jar file.But even after executing the file,the system is unable to recognize the jar file and when i compile my java program which uses that jar file,it gives compile time error(i.e the path is not set).
And when i simply use the classpath command in command prompt which i wrote inside the batch file,it works.
But i want to make a batch file so that whenever i need to set classpath,i can use that batch file.
Help will be appreciated.
Following is the batch file.
set classpath=jsoup.jar;.;%classpath%
Solution found by OP:
Thanks,I solved the problem.I just made a .cmd file containing the command.Now whenever i will need to set the path i will run that cmd file in command prompt.
Related
Currently, there is bat file that calls the main class in a jar file. Now I want to run it using eclipse. How do I configure the eclipse to run it?
I have tried the Run > External tools > External tools configuration. But I don't know what to type in...
#echo off
set MODULE2_HOME=%~dp0..
set JAVA_HOME=C:/Program Files/Java/jdk1.6.0_71
set CLASSPATH="%MODULE2_HOME%/classes;%MODULE2_HOME%/lib/*;%MODULE2_HOME%/lib/oracle/*;%MODULE2_HOME%/lib/aspose/*;%MODULE_HOME%/aspose/*"
set SETUP_PROPERTIES="%MODULE2_HOME%\conf\setup.properties"
set PATH=%JAVA_HOME%\bin;%PATH%
java -cp %CLASSPATH% -Dsetup.properties=%SETUP_PROPERTIES% com.module.fast.main.Module2Main %*
How do I configure eclipse to run exactly like this command?
Since it is a batch file which will run in Windows. You can go to the command prompt and run the batch file using .bat. You do not need Eclipse. You can run the java class in eclipse. Still if you want to run, you can check the following screenshot.
While configuring, make sure to give the complete path of batch file. If the bat file needs extra commandline params, you can give the batch file location with space and the command line parameters separated with spaces.
It does not work to run the jar file which contains main class, you have to give the working directory location.
I need to create .jar using .bat. When I run this command from cmd it is ok:
jar -cMf ../sp.jar META-INF/MANIFEST.MF *class
but when I run batch file (.bat) with this command inside i says:
'jar' is not recognized as an internal or external command, operable program or batch file.
What should I do? When I try in cmd run javac or jar it is ok.
The command you give is a little confusing; by giving "M" as parameter you specify that you want to create a jar without a Manifest. By using "m" it means that you want to create a jar and then specify the manifest.
Please see http://www.dummies.com/programming/java/how-to-use-the-jar-command/
Also, I would use "jar cmf" instead of "jar -cMf" (whithout the "-").
In the end, try using the full path to where you have your jdk, something like: "c:\Program Files\Java\jdk1.your.version\bin"
I'm developing a project in Java. When I export the project in .jar, I need to start mysqld to run my database. I start mysqld using a .bat file which this file is needed to be opened every time user opens the main file to access to database. The batch file content is:
.\data\bin\mysqld.exe --no-defaults --console --port=3306 --collation-server=utf8_persian_ci --character-set-server=utf8 --socket=mysql.sock --basedir=.\data --datadir=.\data\data --pid-file=".\data\data\MysqldResource.pid
pause
The data folder contains database files and is placed in the same folder with .jar and .bat files.
I don't know how to open the .bat file from the Java code.
The code of executing .bat file is written under the one of the project packages.
Please help me.
Thanks.
You must use the Runtime.exec() method:
Process batch = Runtime.getRuntime().exec("cmd /c D:\\Projects\\Terminal\\project Deployment\\run_server.bat");
Check the path for correctness; it's advisable to use an absolute path, otherwise keep in mind that the starting path is going possibly to be your user home, depending on how Java is run.
I need to run my Selenium(Java) script in different machine. So I'm exporting the script to a jar and executing it from a batch file. I would like to know if there is anyway I can create a log for my script while executing it from a batch file and store it somewhere.
While running the script in my local(using Eclipse) I'm able to do that with the help of log4j but I'm not sure how to do the same while executing the script in a different machine. (Note: It would be great if there is any way I can do this, by using log4j itself.)
yourcommand &>filename
where yourcommand is executing the batch file from command line, something like
file.bat &>logfile.log
(redirects both stdout and stderr to filename).
If you use log4j that means that you have a properties file. When you create the executable jar it should also include that file.
In the properties file, for your logs you should have a line like this:
log4j.appender.dest1.File=C:\\Users\\Your_User\\workspace\\Manual.logs
Edit the line to be like:
log4j.appender.dest1.File=Manual.logs
Add the "Manual.logs" (or the name that you defined) file next to the jar executable. This way, as long as both files are in the same folder, your logs are going to be generated.
I have a Java jar file which takes two csv files as an input. I tried to run this jar via Linux command line and it works fine.
Here is what i tried on Linux command line:
java -jar /home/test/Download.jar
I am trying to do the same via Jenkins in Execute shell but I am getting error:
Couldn't load file: test1.csv
Couldn't load file: test2.csv
information possible empty
These are the csv files that Jar takes as input.
I have given chmod 777 permission to all files.
Probably that's because of the location of the test[12].csv files. Try printing out the getAbsolutePath() for those File entries that you want to load: I'm sure they will point to a non-existing location.
I suppose those files are "next to" your Download.jar file. Now when you're executing a Jenkins job, the actual working directory is the workspace of the job (check the console log of the job on the web interface for the details). Either copy the files there or use absolute references.