How to time Java program execution using Intellij Idea? - java

In Intellij IDEA it is possible to create run configurations. When I run a Java program and it completes execution then Intellij IDEA console shows something like this at the end
Process finished with exit code 0/1
We have a unix command time which can be used for timing something. If I want to time a java command execution via command line then I can do something like
time java -version
We have a option of adding external tools in Intellij's run configuration. By default it has make for compiling configured
Now I was thinking that I can possibly add the timing part to my run configurations. But the problem is that the external tools run before the actual execution.
I tried and added external tool time but it gave an error that no arguments were given.
Is it possible to wrap the java command's execution into the time like the example given above via Intellij's run configurations? Finally I want to time the java command's execution without changing the code itself. I am open to solutions other than linux time subject to they can be used with IDEA's run configurations.

Related

Maven builds in Jenkins failing, succeeding on command line

We are customizing the site generation in maven and one of the things that it does is call Visio to have it translate some charts into png. We use a vbs script which calls Visio and that is called from a java class by calling Process proc = Runtime.getRuntime().exec(command); where command is cmd /c "cd "C:\Path\To\Module\site\target\staging"&&exportVisioSvg.vbs "C:\Path\To\inFile.vsd" "C:\Path\To\outFile.png""
Now this code executes on my own machine just fine. Visio is called up and generates a file. When I run it on the server hosting our Jenkins instance it works as well. When I run the command by itself it works just fine. Finally when I goto the Jenkins\workspace and execute the maven build there it works just fine.
However when I run the build in jenkins with exactly the same command (I copied and pasted it) it does not generate the Visio charts. Everything else runs fine and there is no stack trace outside of our own thrown error that goes off when the image is not where it is supposed to be. The exit code from the process is 0 as well and there is no output to either stdout or stderr (the windows equivalent) generated by the process and it has to complete or the exit code would be -1. Timeout isn't a problem as it has 50000 ms to run but always returns within a sec or less (you can see the error get thrown right after the call to the script).
I switched Jenkins to run under the admin account where everything is installed (moving it from SYSTEM) so it should have access to the PATH.
I have no idea what to do at this point.
This sounds like one of the Jenkins FAQs. Check https://wiki.jenkins-ci.org/display/JENKINS/My+software+builds+on+my+computer+but+not+on+Jenkins especially under the section "Desktop access (Windows)"
You're probably hitting http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6468220 and since it can't be fixed in the JDK, you need to finetune it in your code.
The problem is when Visio is started it is started as a child of the Jenkins service which is running without desktop interaction. Microsoft restricts its office product actions where a prompt might be generated which cannot be seen by a user. Even if you add allow interaction with desktop it will not work and in my case returned the following error value 2032466051. The solution was to only run it as a user and manually start the Jenkins instance every time we needed to restart the server.

ANT returns build success on Java Run Time errors

we run a given task using ANT which creates some configuration files and then run a sw for us.
We are experiencing some run time error inside the virtual machine and it seems ANT is not able to catch it: it simply gives me BUILD_SUCCESS.
Is there any way to avoid this?
Thanks in advance.
Ant can only check the exit code of a Java process it launches. If the exit code is zero, then it will dispaly BUILD_SUCCESS, otherwise it will display a build failure. Therefore, you software needs to call System.exit(1) (or any non-zero value) at some point, for Ant to be aware that it was not successful.

Internal error in eclipse when running java program

Eclipse froze on me earlier today, so I typed "top" into the command prompt and killed it. Now when I try to run a java application, I get this error:
eclipse\plugins\org.eclipse.jdt.debug_3.7.0.v20110509
That's all that shows up under details.
None of my previously working programs run, and I have no clue what this is. I have Eclipse 1.5.0 running 1.6 and 1.7 Java, depending on what program. Thanks for any help.
It is possible that you killed part of the process but not all of it. It is possible that a java process is running with a reference to this job. I would try restarting your computer to see if it will stop whatever process is referencing that jar.
Aside from a restart, then another option would be to use (in linux) pstree, filtered for your user to see if any other jobs are referencing that jar and/or java.
EDIT:
Another path is to look at log files. On linux they are in /var/log. Here's a link in that direction: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/felog.html

Cron job for a Java Program

I am using a java program which sends email after finishing up some file transfers.I am using Eclipse to code up the program. How do I set up a cron job to execute this java program for a particular time. Also I have various jar files inside the project. Please suggest
Write a shell script to invoke your java program with the necessary
arguments.
Make sure that the classpath argument points to the jars that you need.
Make sure that the shell script has necessary unix
permissions.
Schedule the script to be invoked by setting up a cron
job.
For more info about cronjob look here http://en.wikipedia.org/wiki/Cron
just my 2 cents...
r0ast3d has a quick, clear answer - I did have to do some more searching to get each step done so I'll elaborate on his steps:
Write a shell script to invoke your java program with the necessary arguments.
Example:
!/bin/bash
echo "Running script."
cd ~/your/classpath/to/java
java -classpath .:somejar.jar path/to/your/Program
Separate your necessary classpaths with colons (:) rather than semicolons (;)
The path to your program should start with your package (find this at the top of the java program)
Make sure that the classpath argument points to the jars that you need.
You can check your import statements in your java program to make sure you are specifying all the necessary classpaths. You have to run this script from your java directory, and can use a single period (.) as your first classpath argument.
Make sure that the shell script has necessary unix permissions.
Run from a terminal: sudo chmod ### yourScript.sh
Where ### are numbers representing the correct permissions for your system setup.
Schedule the script to be invoked by setting up a cron job.
Run from a terminal: crontab -e
This will open your crontab editor. You can add a job in this way:
*/5 * * * * bash /home/scripts/yourScript.sh
Replace the path to the script with the correct location of your script. This job is set to run every 5 minutes. See http://www.adminschoice.com/crontab-quick-reference/ for a good reference on crontab.
Hope this helps someone out!
use quartz for more complex need or Timer for a simpler task
There is the cron4j library http://www.sauronsoftware.it/projects/cron4j/. I have used it before to schedule a java program to run weekly. The scheduling syntax is the same as a crontab. The thing is, it needs to be constantly running as a background process to work. I ended up just using normal cron, but it could be useful if you're not on an Unix-like system, and you don't have cron.

Java programme works perfectly in NetBeans, but exits unexpectedly when trying to run

I've run into a weird problem today. I'll try to describe the steps I'm making as detailed as possible.
I've created a Java application in NetBeans. The application runs without exceptions when running within NetBeans by clicking Run Main Project. The total duration of a complete run is about 1min.
When building the project I see the following option in the output window of NetBeans:
To run this application from the command line without Ant, try:
java -jar "C:\java_libraries\PrxJobCommunicator\dist\PrxJobCommunicator.jar"
So i open the command prompt (Windows 7), enter this command + supply a mandatory integer argument and press enter
The application starts running, runs for a couple of seconds and exits without any message whatsoever.
the application writes to a text file at different points in the code, so I'm able to trace the output up to the point when it stops running. I've deliberately put some extra calls to the file writer method in order to find where the programme continues/exits but to no avail. Seemingly the programme simply stops running on a certain line and that's it.
I really don't know what the problem can be: the application runs fine in NetBeans and fails without any message whatsoever when starting from the command line.
Shall I check anything special in NetBeans? Do you know of any special technique to debug a jar file if it's started from the command line?
Any clues are welcome.
Thanks, Andras
I suspect that there is a difference in the classpath when the app is run from NetBeans, and when it is run from the command line.
There must be some kind of exception that is being thrown, have you got an outermost
catch (Exception ) block in the main method?
You could try to debug the application using "remote debugging", although you won't be debugging over a network, you can still use this method to catch the breakpoint started at the command line in NetBeans.
Here's an article that explains how to do remote debugging with NetBeans http://manikandanmv.wordpress.com/2009/09/24/debugging-java-applications-with-netbeans/
Netbeans by default uses your project folder as the working folder. It means when you run your program from console you have to CD C:\java_libraries\PrxJobCommunicator
then run java -jar "C:\java_libraries\PrxJobCommunicator\dist\PrxJobCommunicator.jar"
If above fails check the java version used in your command prompt. java -version
It has to be same as the one used by netbeans.
Finally the library path. Are all the dependent jars placed in the dist folder?

Categories

Resources