I've been working on my jenkins server off and on for the last few weeks. Right now it runs fine building and outputting the files to a remote location. However, i'm looking to do some pass or fail tests on the files before they are uploaded. This way i avoid releasing broken versions of my work. As well avoid more bug reports that i do not need to be reading.
The files i'm looking to run are actually plugins for another program. So i need to actually start this program as i can configure all the files before hand. The program is a .jar file which i know i can launch using a bat of shell script. The issue is i don't know at this point how to terminate the .jar program after it has been running. All the solutions i've found require me to modify the jar to terminate itself, or kill the JVM. Both i can't due for varies reasons.
It's a heavy hack, but you can make a shell script start a background thread that checks if the JVM is done, then terminate it.
Rudimentary example in bash:
start_jvm_command >>console.log 2>&1 </dev/null &
while ! grep 'done signal' console.log; do sleep 1; done
pkill -f "regexp for start_jvm_command"
Note: I was using pkill to terminate to avoid wrapper shell scripts.
It been a year since i asked this question but i found a much nicer way to solve this question. Its called JUnit and is a testing lib for java. With it i don't need to launch the entire jar but can test peace by peace at a time. As well if require i can write a test to launch the entire .jar file. In the test i can check if files exist, if functions complete correctly, and if any error is thrown during runtime.
Related
I am trying to run a executable jar file I made in Intellij on JDK 11.0.2 that contains a GUI system. I have java 8 and Java SDK 11.0.2 installed. Whenever I double click the jar file I expect the main gui login screen to come up, but nothing happens. I have tried other options such as trying to run it through cmd (it gave me an access error) and the HKEY_CLASSES_ROOT\jarfile has the command: "C:\Program Files\Java\jdk-11.0.2\bin\javaw.exe" -jar "%1" %* already.
Cant comment quite yet on other peoples posts so ill just submit an answer, tho its gonna be more of a swing and miss probably.
Id recommend opening that jar file with a java decompiler (The one i had in mind is jd-gui) and checking the integrity of the code, file system, and, in general, just check arround for common errors when packaging, maybe you included something you shouldnt in the class and hence why the problem, or its crashing on load cause of a missing reference you had linked to with a relative path which got broken upon moving the file, those are the two big ones that come to mind that you should check first upon opening the file, other than that, i cant provide much more insight, godspeed to you!
I have a Java executable (.exe) with a given JRE build in the same folder, which it uses to actually run.
I want to put this executable on Windows Task Scheduler.
I did some tests with some C++ hello world programs, and all went fine. This Java program, running directly (by two clicks or whatever) works all fine too (it is supposed to write to a file and end).
However, when I put the Java program in the Task Scheduler, it exits immediately, with status code 0x0 (success) and nothing is actually performed.
At Windows Task Manager, I see that javaw.exe starts and exits in a glimpse.
What could it be? Something related to Java? Something due to a specific task scheduler flag?
Aditional:
Java executable built with launch4j.
Scheduler set with schtasks /create /tn MyETL /sc hourly /mo 3 /tr C:\ETL\etl.exe
When you run an application with Windows Scheduler, if that application has dependencies to other files via relative path, then you need to set the start in setting for the task. This sets the path from where execution will begin.
Alternatively you can use a command file and have it navigate to the correct directory first.
Just figured out that the problem was that the program was actually being executed in the wrong folder, in order that the output file wasn't where I thought it would.
The output file was being write in the starting folder, not the program's folder.
I have searched all over but found no luck yet, I am using linux ubuntu flavour and need to know that how can I check that whether the java jar file is running at remote end or not using pgrep. As the pgrep -f "someProcess" returns the Process ID.
Note: Both systems are linux based, and I only need to done it through terminal. Any ideas would be appreciated.
I've used Ant to do this.
I can't remember which task I used unfortunately....
But we executed a command or script remotely using an ant task.
I think we used ExecTask.
Notice you can specify an output file.
You can read that to process the output of your command.
Ant is pretty awesome in that anything you can do with an Ant script, you can do with Java.
And it's a lot easier than you'd think.
I believe this is a good starting pont to learn how to do it.
Here is the Javadoc overview page for the Ant classes.
Here are some more links to helpful Javadoc pages:
Project
Task (the base class for all Ant tasks)
SSHExec task (looks like this is what you want)
ExecTask
Copy task (this is a nice simple one for "Hello, World" purposes
FTP task
I'm sure there other ways, but as they say here Ant makes things very easy for you.
I can think of one way to do this.
Assuming you have servers A and B, A performs the process check on B. You can use ssh and setup no-password login from A->B and use command below:
ssh root#12.34.56.78 "pgrep [whatever keyword]"
You'll get the same result as executing the command on B.
You could use plink.exe to do this. You can pass commands to plink in the form of a .txt file input.
so, I've been doing some searching, and i can find somethings on how to run an external application, but i cant get them to work! I've been working on this for a while, and its really annoying.
what i want to do is run a .jar file in the directory
C:\Program Files\AVTECH\NPS\Files\bin\NPS.jar
and I've tried a bunch of different things with the code
Process p = Runtime.getRuntime().exec("dir goes here");.
also
Process p = Runtime.getRuntime().exec("C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar");.
if i'm correct, it uses command prompt to do this? or at least the MS-DOS language. i did some of that kind of thing a few years ago, but i don't remember how one would do this... I've never worked with this kind of thing in java before...
could someone help please? thanks in advance.
Runtime.exec() is working just like if you were typing a command.
Launching a jar file is not working : you have to invoke
java -jar /path/to/my/jar
Check Oracle's documentation on how to execute a jar file.
The actual command should be java -jar C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar. I mean -- if the jar file is indeed executable, this doesn't mean it will run, by just trying to invoke it. You need to tell Java to run it as shown above.
In addition, MS-DOS is not a language -- it stands for Microsoft Disk Operating System. Nowadays, you have this as a Command-line Prompt (Shell) built into Windows.
You need to run the command as a call to the executable and a set of arguments. Check this version of Runtime.exec(String[] cmdarray). If need be, there's also a version of Runtime.exec() that takes a base directory in which to start the executable.
I'm trying to compile a Flex application in Ant (no problems here, I can do it fine). When I try to publish the contents of the project to a Windows network drive (known as "Z:\" on my system), I get the following LAME exception thrown by Java/Ant:
BUILD FAILED
C:\workspace\bkeller\build.xml:42: Failed to copy C:\workspace\bkeller\web\assets\text\biography.html to Z:\web\bkeller\assets\text\biography.html due to java.io.FileNotFoundException Z:\web\bkeller\assets\text\biography.html (The system cannot find the file specified)
Which kind of sucks. I can't find any way to get rid of this problem and it's pretty crucial to my project that I get this working. I know for sure that I have read/write/execute permissions on the network drive, I can create/edit/delete files on the drive just fine through Windows explorer.
Drive Z is a network mount to virtualbox, allowing me to get access to my host OS, Ubuntu. I've double checked that it has write permissions. Any ideas?
Seeing as how Z is a network mount, verifying that it works (e.g. that you can create / write files) through Windows Explorer may not be the same thing as verifying that it works from within Ant:
You may have specified the necessary user / password sometime in the past and Explorer remembered it (so it doesn't ask you again). Ant obviously wouldn't.
Ant may run as a different user, especially if you spawn another process inside the build.
Can you write a simple test in java and see if it can create a file on your Z: drive? Perhaps that'll provide some insight. You can also run ant with -debug switch and see if it provides a more detailed info. At the very least it would print a stack trace and you can download Ant source and see what's happening.
Just experienced the same problem. The copy target was a regular network drive connected to my Windows 7 machine.
I was able to solve the problem by restarting Eclipse.
The cause might have been that Eclipse was running with Administrator privileges because of an Eclipse update I had been performing beforehand.
Does it go without saying that the file actually exists? Regardless, while you may have permission, does the process that is actually running the ant task have permission?
you certainly thought about it, but have you tried
Z:/web/bkeller/assets/text/biography.html
I always use the / instead of \ even on Windows and can't remember having a problem with the Copy target.
It was a problem in VirtualBox's shared folder system. It was fixed a few releases ago by 3.0.X.