• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jar file executed from script is not working as expected  RSS feed

 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a shell script that runs a jar file. The jar I run is a client and it deals with some file transfer and screenshot transfer. As stated in my previous question here, I tried inserting the script to /usr/bin and I added a .desktop file to /etc/xdg/autostart and but that did not run. So I tried inserting the script in /etc/init.d and used update-rc.d scriptname defaults. The jar file runs fine and files are transferred but not the screenshots. I am using the Rectangle class in Java to obtain the screenshots and I transfer it using ObjectOutputStream.

Script:



I also tried running the same script without '&' and also the same script with a different jar named Test.jar.

Same script with different jar file:



This jar just displays a JOptionPane message dialog with "Success". I tried removing '&' for the Test.jar too. Both ways it did not work.

I know that '&', does nothing but run the process in background but it had effect on some results when I was working with /etc/xdg/autostart directory.

I also included the below given lines in both the scripts and tried with and without '&'. Still same results.

Script lines:


and


When I run those jar from normal terminal, it works fine and when I run ready.jar from Netbeans and connect it to my server jar, I get the screenshots without any problem.

One thing I noticed when running from Netbeans,(I used top and ps -A to view the running process) my file ran after X-org and lightdm with a PID of near 3000 to 4000.
But when I ran it from script, I ran before X-org and lightdm with PID around 800-900. Does this have anything to do with the problem I am dealing here.

I am not able to access the terminal running behind display manager (sorry I don't know the name of terminal, I am a newbie and I am searching for it). I think if I access it, I would able to give you something, regarding exceptions and errors.
Any ideas?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be a permissions problem. Under what user is the script / Java program running? Does that user have the necessary rights? Is there logging somewhere, where you might find a message that says access is denied to the program?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper,
Thanks for the reply
I run them as root when I manually run. But how can I determine under what user it's running when it runs from init.d ? I think there is no logging but my jar file prints some lines when run. As I said earlier I am not able to access the CLI running behind the desktop manager. What do they call it and how can we access it when we are using a graphical interface?

Edit:

If it is permission problem, the jar file shouldn't run right? But my jar file runs only the graphical display I am fetching is not displayed. Correct me if I am wrong. I tried changing the ownership too. chown root /etc/init.d/scriptname, chown root /etc/ready/ready.jar and chown root /etc/ready. This too didn't work.
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are attempting to run a GUI application as a startup - and that sounds like what you want to do, there's a major problem.

Linux CAN run a GUI (X Window) system, but out of the 6 available runlevels, only 1 has a GUI. The others are all command-line based or system halt states. Well, except level 4, which isn't used.

If you are attempting to run an X-based graphical application (that includes stuff based on AWT, Swing, and SWT), then you don't want a system startup, you want the X system to startup, and THEN launch the GUI app.

Normally, X starts up with a user login screen. However, it's also possible to have X bring up one or more X apps when it starts, instead. To make all that work, however, you're going to have to research how and when X starts on your system and adjust it as needed.

X itself would normally be running as root, but that's something else you might want to modify.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

Thanks for the reply. My jar is just a background process, it doesn't have any AWT, Swing or SWT components. All it does is take a screenshot and send it to my server jar. I fetch system information like OS, Hard disk size and RAM size using terminal commands. For that I need root or sudo access. I tried running the script from /etc/xdg/autostart but it didn't run as stated here. I changed the script as shown above but jar didn't start. I used top and ps -A to check this.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given this:
it doesn't have any AWT, Swing or SWT components
,
how does it do this:
All it does is take a screenshot

?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

Screenshots are taken using Rectangle class in Java. I transfer them using Object IO streams.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And after considering the package the Rectangle class is in, do you still think it uses no AWT?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

I know Rectangle class is in AWT package. I meant there is no GUI components in my application. It runs as a background process, that is why I tried running the script from a desktop file in /etc/xdg/autostart but the jar did not run from there.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What matters is not what components your code allocates, what matters it that it obviously does use AWT, and so what Tim said about that applies to your situation.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

Ok. From what I researched, I go to know that .desktop files should be added to run after login and I have done it for a couple of applications in Ubuntu like Thunderbird,etc. But when I write a .desktop file and run the script, the jar file doesn't run. What do you think will be the problem?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea. But it has been my experience that Unix-like OSes generally write logging output if something goes wrong at the system level. Maybe this ".desktop" mechanism does that as well.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

These .desktop files are placed in /etc/xdg/autostart when we add startup applications. That is why I tried that.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said, I have no idea about whether that is supposed to work the way you're trying it. Time to hit the documentation, I would say, and also, as I mentioned before, to check whether any error messages it might potentially generate are logged somewhere.
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are running using graphic services but no actual GUI, that's known as "headless mode". The graphic services actually employ the video card in the machine to do their work, so a certain amount of graphics infrastrucure MUST be present even if you aren't actually doing any on-screen graphics. There's a JVM parameter that should allow you to run headless, but I don't remember what it is, so I'll let you google for it.

You would not use the ".desktop" facility if you are running a headless application at startup. That's for when you want to run when you log in via X.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

Thanks for the reply. I will search for headless parameter. For headless, if we shouldn't use .desktop files, from where should I run my script?
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not so much because it's headless, but because you want to run it on startup, you'd typically put the run command in /etc/rc.local (assuming that your linux distro uses sysV init). Use the "su" command if you want to run in under a non-privileged user ID. For example:



That will run the MySystemApp application under user ID "appuser".
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

On un-installation, i should be able to remove it right? I must be able to do the insertion and deletion automatically from my program. That is my biggest problem. When I run the jar first time, startup files should be added and during un- installation, I should be able to remove it. Uninstall is done using server but if I edit rc.local, I wont be able to erase it from the script during un-installation. How can I achieve this?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, Ulf & Jesper,

Thanks for the help guys. I wasn't able to run the file from autostart as my jar needed administrative privileges. Now I solved it Thanks again for your help
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:Tim,

On un-installation, i should be able to remove it right? I must be able to do the insertion and deletion automatically from my program. That is my biggest problem. When I run the jar first time, startup files should be added and during un- installation, I should be able to remove it. Uninstall is done using server but if I edit rc.local, I wont be able to erase it from the script during un-installation. How can I achieve this?


I didn't really follow that.

I run Red Hat flavors of Linux, and software packages for that architecture are RPMs. Almost everything I install is an RPM, even J2EE webapps (since often there are files external to the WAR that have to be managed). One of the advantages of an RPM (or a Debian deb or whatever) is that it not only contains the files to install, it contains a manifest of the files so that the package manager can cleanly un-install as well.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

Say I edit rc.local with java -jar /etc/ready/ready.jar and say after 2 or 3 days I want to uninstall it. How do I do it? I cannot do it manually, I have to use java program to edit and delete the lines from the rc.local file. How can I do it?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!