debug application by running .sh file using eclipse - java

I have a .sh file which runs independently on Linux server to sync some data but now there is some problem with the sync so I wanted to run this .sh file in debug mode in eclipse so that I can check my java code where the problem is?
Is there any plugin or options available in eclipse to do this.
Please let me know if you need any further information.

If you want to debug your java code which your shell script invokes, just write a wrapper java code which invokes your main java code, and you can easily debug using eclipse.

What is the content of this .sh file? Is it running a JAR?
If so, you can remotely debug a java code. The following blog explains using screenshots: http://javarevisited.blogspot.co.uk/2011/02/how-to-setup-remote-debugging-in.html

I don’t think we can use shell script debugger in the Java debugger session. i.e you need to debug java code and shell script code separately in separate debug sessions.
You can use basheclipse to debug shell script, this will only work with shell script editor ShellEd.
Also check the open tickets for debugging in ShellEd.
Note
Outside eclipse you can try http://bashdb.sourceforge.net/

Related

How to run Java application on startup of Ubuntu Linux

I have a requirement where I need to develop application that reads TCP/IP Socket. I successfully made the program as Java program with No GUI means as soon as program runs it starts listening to the Socket and gets the response with the help of Netbeans IDE. Now as per my requirement i have to start execution of this program as soon as Linux system Booted.
Actually I am very novice in Java and Linux Platform, so have few doubts..
Is my Socket Program with no GUI is fine to be run as per my requirement.
How can I write script to run jar on Linux Boot up, I got to know. init.d is meant for this.
Ideally you should create a service wrapper for your java application and then make this service run on startup example here.
Use
sudo update-rc.d mytestserv defaults to run your service wrapper on startup on Ubuntu
So two things you'll need to do:
First create a small shell script to start your java program from a terminal. As you have packaged as a jar have a look at this, specifically the JAR Files as Applications section.
This may be sufficient: (although you'll want to use the full path to Java)
#!/bin/bash
java -jar path_to_jar_file
You should be able to run your script and successfully start your program.
Once you've got it starting from a script you can use standard linux tools to start the script. Either putting it in /etc/rc.local, or as you're using Ubuntu, use update-rc.d to start it on boot. See here for a very simple example of using update-rc.d
Hope this helps,
Will

How to see sikuli logs during execution?

I'm trying to output some debug info in a Sikuli script using print but I can see this info only after the script has finished execution because the IDE hides itself while the script is running. Is there a way to see those logs during execution? Like outputting this info to console or (better) not hiding IDE during execution?
(1) You could use a pop-up:
popup("Hello World")
(2) You can use Jython's File IO
f = open("myLogfile.txt", 'a')
f.write("Log Message")
f.close()
Now if you open the log file in a text editor that warns about changes made to the file (ie NOT Notepad.exe), you can then see your print statements every time the file is appended by your script.
You cannot hide the IDE in background during script execution.
However,there's an alternative to view the logs.
You can install the package which launches your sikuli via command prompt(sikuli-script.jar),
refer to https://launchpad.net/raiman/+download
you won't need the IDE to launch your scripts this way.
Now after changing necessary environment settings you can type-in simple path like "java -jar %Sikuli_Home%\sikuli-script.jar -r %Sikuli_Scripts%\main.sikuli" in cmd and get started.
here 'main' is my driver script where I have imported my modules under single .sikuli folder (main.sikuli) you can have any file name like abc.sikuli
(here you need to store your path in a variable like ,path = os.environ['Sikuli_Scripts'])
Also ,it is a good practice to launch applications creating batch files and accessing files using relative path.

Debug java product without eclipse etc

I faced strange problem in Sonar (code analysis tool) and do not understand why it is faile. It is started using command line:
%JAVA_EXEC% %SONAR_OPTIONS% -cp "%SONAR_RUNNER_HOME%\lib\sonar-runner-dist-2.3.jar" "-Drunner.home=%SONAR_RUNNER_HOME%" "-Dproject.home=%PROJECT_HOME%" org.sonar.runner.Main %*
I am not Java programmer, but I would like to debug this process somehow. I know that error appears inside one of loaded plugins, not inside sonar itself.
Question: is there way to start java application with debugging availability without eclipse and any other special and very massive editor? Something command line'ed with ability to set breakpoint, inspect variable value and stepping forward/stepping over is enough for me.
There's JDB, the Java Debugger from the official SDK.
Simply add this parameter to invoked command and connect to this process with prefered debugger (Eclipse, IntelliJ or what you want)
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
You can debug this remotelly!

How to debug Java and Perl code in Eclipse in same debug session?

Setup:
I am working on a Java project which invokes some Perl scripts.
Problem:
If I run the Perl script from terminal, it works fine. But when I invoke the same Perl script with same arguments from Java code, it fails. It is an extremely strange and annoying bug.
I am able to debug Perl in Eclipse using EPIC plugin. And of course, I can debug Java code. It would be helpful to debug Java and Perl code in the same debug session in Eclipse, so that I can see whats different happening when the script is invoked via Java code.
Not sure if this is even possible, but if anyone has any idea, please share.
Thanks.
Perl has some remote debugging capabilities, so you can get what you need, I think. I don't use EPIC, so I don't know if you'll be able to do it all within Eclipse.
Set the environment variable named PERLDB_OPTS to have the value RemotePort=<host>:<port>. Then, start Perl with the -d flag. Instead of the debugger trying to interact with standard IO on the invoking terminal, it will attempt to connection to host:port.
Here's a Unix-y example. I've got a Perl script hello.pm and two terminal windows open.
First terminal
$ nc -l 12345
That's started NetCat as a dumb server listening on port 12345. If you don't have a server listening before Perl starts, it won't work.
Second terminal
$ export PERLDB_OPTS=RemotePort=localhost:12345 # set the env variable
$ perl -d hello.pm
Now the script is running. Back on the first terminal, I see
First terminal
main::(hello.pm:1): print "hello\n";
DB<1>
I'm in the Perl debugger and ready to go!
I know that at least the Komodo IDE has support for remote debugging, and there's a Perl Monks post on doing it with Emacs, so you can get something more than the command line even if it's not Eclipse. Good bug hunting!
If I run the Perl script from terminal, it works fine. But when I invoke the same Perl script with same arguments from Java code, it fails.
I suggest that you check that you are running the same version of Perl in the two "contexts"; i.e. when the Perl app is run from the command line and from Java.
If that's not the problem, check the environment variables.
The other approach to solving this problem would be to focus on why the program is going wrong, not on how / why the contexts are different. Look at the evidence that you have, and look at ways to gather more evidence ...
The potential problem with trying to do this using a Perl a debugger (in an IDE or stand-alone) is that you are actually running Perl in third "context" which might be different from either or both of the existing ones.
Using a debugger may work ... or it may leave you even more confused.

Wrapping a jar file in a Windows service

Have you had experience with running a jar file using a command line, wrapped in a Windows service?
I'm trying to find a way to run a jar file without being logged into the machine, and since it allows command shell, I was wondering if it's a good idea.
Thanks!
Original Post:
I'm trying to run Associated Press's Web Feeds Manager, which is basically a jar file that can be run when logged in by double clicking it.
I'd like to run the same file but without being logged in to the machine. In their manual (http://wfm.ap.org/admin/content/help/Running_Agent_on_a_Remote_Server.htm) they write how to do that, using a commandline parameter.
Basically I'd like the jar to run as a Windows service, regardless of who's logged in, but Googling it showed it was problematic.
Have you had experience with remotely running jar files? What are the pitfalls?
Thanks!
On a google search, I came across this article -
Running Jar Applications as a Windows Service
It mentions about open source Java Service Wrapper project from Tanukisoftware.org for accomplishing this task.
Note: I've not used this personally.
If you are not interested in having the service started/stopped at boot/shutdown, but you just want the program to be started manually and keep running after logout, here is what you do:
$ nohup java -jar foobar.jar > foobar.log 2>&1 &
which means: start my foobar.jar (java -jar) and keep it running after I logout (nohup) redirect stdout to foobar.log (>) and also the stderr (2>&1), and make it running in background (& at the end).
Instead, if you are interested in installing a "service" in your linux box, there are many options, depending on what distribution you are using.
The most common are upstart (for ubuntu) and System V init scripts (Redhat or others). Also cron can be used to start/stop services at startup/shutdown.
You can find an example of installing a java app (hudson) on an init system here, or doing the same thing with upstart. Or, as I said, cron could be an option.
On Windows, there is Java Service Wrapper. And not much more.
For windows Java Service Wrapper is a better choice
My favourite is the upstart on linux, but it is Ubuntu only.
On Windows I see many alternatives according to this forum.

Categories