Java Process cannot delete files in use - java

My Java application runs on a Windows service wrapper and the wrapper writes logs into a DEBUG file. The application has a service that backup and delete this DEBUG file at the end of the day. The service uses a script batch file to do this process.
My problem is, when the application try run this batch file and delete the DEBUG file following error occurs,
The process cannot access the file because it is being used by another process.
But if I run the batch file or run the relevant script manually everything works well. Is there a way to solve this problem without stopping the wrapper? (Tried to truncate the file but got the same error)
Script I use : DEL /A /F /Q "C:\MY_APP\logs\DEBUG.DMP"
Thanks!

Related

Running Batch File Using Java ProcessBuilder does not recognized Network drive

I have a java program (jar) that uses ProcessBuilder to execute a dynamic batch file.
Process process = (new ProcessBuilder(commands)).start();
I have a simple batch file like this, Z --> is a network drive. let say my batch file location is in my_batch.bat.
copy Z:\Download\*.csv D:\Download\
if I execute this batch file from the command prompt, it run successfully. But if I execute using the java program, the program does not work (nothing happen). But if I change the batch file like below, it works. E-> is a regular drive (not a network drive).
copy E:\Download\*.csv D:\Download\
I don't know why this can happen, please help.
My Operating System is Windows.
I solved it by putting this line in my batch file.
net use Z: \\Computer\shared /user:DOMAIN\username password
and after the process, use this at the end of my batch file.
net use Z: /d
thanks to the man that help me in the comment section.

Could not open jmx file while running JMeter command line

I have run a thread group in JMeter in GUI mode it is working and getting results, but while running same ThreadGroup.jmx file through terminal(Non GUI] mode,I am getting an error Couldn't load .jmx file.
Can anybody suggest me how to resolve the issue.
In linux using files is case sensitive, so use exact letters(as sampleThreadGroup.jmx)
Also make sure the file is saved in the correct folder
And check your user have permission to execute it (try chmod 777 for jmx file)

Log file not updating when I run my java app as a service

I am not good in Ubuntu and I have the problem. I have my Java+Spring app which works perfect and it writes log file in the app directory when I run it as:
sudo java -jar MyApp.jar &
But I want to run it as a service so I searched the web and did everything like here. The app works fine, but the log file has no update any more.
You need to provide more info on HOW you are running your program "as a service" and HOW you're creating/opening your log file in your program.
If you're creating the log file in the current working folder then probably your start script is starting your program in some other folder you're not looking for or do not have permission to write.

launching java program via batch and php,

php and batch files.
So i'm executing batch files through php
I have no issues launching the batch.
$str = exec('C:\WINDOWS\system32\cmd.exe /c START C:\MInecraft\_restart.bat');
However the issue im having is getting the batch file to work currectly. When the batch is run, it executes this code
taskkill /IM java.exe /F
java -Xmx1024M -jar craftbukkit.jar -o true
batch file successfully runs the taskkill command when launched with php, however it will not run the next line. When ran manually it launches fine, (bear in mind that the cmd.exe does not exit it stays open with this code)
Any ideas on how i can get this to launch from php?
Maybe the reason is the same as given at Error Executing Batch file of BlazeDS, the java executable is not found by Windows on running the batch file from within PHP script.
The current working directory or the directories listed in environment variable PATH can be different when the batch file is executed from within the PHP script in comparison to running the batch file manually.
Do you have ever tried to specify java.exe with full path in double quotes in the batch file?
You could also add at top of the batch file the commands
dir /w
PATH
to see which directory is the current directory and which directories are listed in environment variable PATH on execution of the batch file from within PHP script.
Forgot to post back here, I specified java through windows path command rather than the batch. The problem is because the java process takes the cmd and turns it into a console, it never finishes the batch file. So, the php never returns and continues the code unless the batch is force ably closed on the server.
pclose(popen("start /B C:\MInecraft\_restart.bat &", "r")); die();
I ended up using this command, which i believe makes it launch the batch and not wait for a reply. Just carry on with the php.
Thanks for your kind reply. I did initially try launching java in multiple ways.

adding a java application to system configuration start up menu

I am creating a desktop application. I know how to add program to system tray, that consists of a continuous system process, I need instructions on how to add java code to system configuration startup menu. Like antivirus program which automatically executes on starting the system. would be of great help with example code
Write a batch file(.bat) which executes you java program. Add this batch file into the registry in such a way that it will be executed during system startup.
simply write following into your batch file
java filename
In linux you will hv to create a .sh script(executable) that will execute your java program.
put .sh in /etc/rc0.d using following commands
cp name.sh /etc/rc0.d/
chmod +x /etc/rc0.d/name.sh

Categories

Resources