Tomcat as service unable to work with system clipboard? - java

I made a password manager as java web application (Tapestry to be precise) and idea is as follows, when you click on button next to password label, the matching password should be copied to system clipboard. It works perfectly when I start tomcat the standard way (run startup.bat), but that's not what I need. I need my tomcat to start as Windows service at startup, but in this case, everything in my application works perfectly except coping to clipboard. No error occurs, nor I get anything wrong in the log, text just doesn't copy.
Can someone tell me why is this the case, and what can cause such behavior? Can it be that service doesn't have right to mess with clipboard and if so, can I make it work?
Any help is welcome

When tomcat runs as a service, it does not run was a user linked to the main windows GUI, so all the awt functionalities are disabled. The only way to get some of them back is to add
-Djava.awt.headless=true
to the tomcat startup parameters - see http://support.sas.com/kb/12/599.html
However, this may be not enough as each user has his own console, so tomcat will copy into its own user console - you should run tomcat with the same user as the local logged in user, making the "run as a .bat" the easiest option.

Related

Using awt.Robot with Tomcat service

I am trying to simulate user input (keyboard) using Robot library from java.awt, and it is working on my development enviroment, but when deploying to Tomcat (installed as a service on a different machine), it wont work at all. My OS is Windows.
Is there any configuration that I am missing? I already tried "let tomcat interact with the desktop" option, changing users to run the service, changing java used by tomcat (from jre/ to jdk/jre/..), but still I can't make it work.
Also, if it is not possible, is there another way to achieve this?
I finally solved this, not in the best way I guess.
I stopped Tomcat Service, and then started it from CMD as the current user.
Steps to open tomcat from cmd:
Open cmd.exe
Path-to-tomcat\bib\tomcat7.exe
And then opened my browser, went to the application, tried the proccess and the robot worked correctly!
I know this is not the best way as it can led to security issues, but I couldn't make it work using it as a Service because the different user sessiones (Session 0).

Windows could not start service, Error 1053: The service did not respond to the start or control request in a timely fashion

I have created a Java program then I need to install it as windows service.
First I run the jar directly from console and it ran as I wish, then I compile the jar to exe and I ran it as Admin ran OK.
But when I run it from windows service I got following error,
Error 1053: The service did not respond to the start or control request in a timely fashion
I also tried to set Account and password on Log On Tab, but not resolved yet.
It's not possible to resolve the actual problem with the information given by you, so I will provide you the steps necessary to debug the problem.
Use logging in your application to see what causes the error: Apache Log4j
You can use the Windows Event Viewer to see what happens when you start your Windows Service. This is very useful if the problem happens before the start of the application itself.
Click on Start / Windows symbol, type Event Viewer and press Enter. In the left hand tree-menu, click Windows Logs and then Application.

Netbeans Tomcat Output Window has no console input

I'm starting Tomcat in Netbeans via the Services tab and see the output window as usual.
The problem is, I have a web application which needs a password to be typed in at runtime to be sent via console to the application.
I found this bug report (a bit old): https://netbeans.org/bugzilla/show_bug.cgi?id=47708&x=17&y=7 but i can't figure out whether it should be solved now or what to configure to get it run.
Any suggestions?

How to run sudo poweroff in java

I am a jsp developer. I need to shut down my slow, unresponsive, laggy, (you get the point) development ubuntu "server" sometimes, when its keyboard stops responding to input. I already have tomcat configured properly, and even when my keyboard stops responding, I can use it as a server (accessing webpages served by tomcat). My idea is to make a jsp page that calls sudo poweroff. But I have no idea how to do that. I have tried
Runtime.getRuntime.exec("sudo poweroff");
but it does not work for me. I have already edited the sudoers file to allow the tomcat user to perform this action without requiring a password. How can I make this happen?
If the user running tomcat has sudo perms (w/o a password), it should be doable - but the call should be something like this:
Runtime.getRuntime().exec(new String[]{"sudo", "poweroff"});
The command and parameters can't all be passed in one big string.
Check out the docs for more info: https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String[])
PS: This is probably a bad idea. :)

How to run external application from a Java EE web application?

I have been working on a Web Application for Intranet use only. I work with Apache 7 and Windows Server 2003.
In one of my page, I need to open an external application that we can locate in C:/Program Files/etc... with some parameters already initialized. Of course, the user has to use the web application on the server to make it work (that will be the case).
To open the application, I use the ProcessBuilder object.
The problem:
When I work locally with Eclipse and run the server by hand, it works perfectly. Any application can open itself from a web page.
But when I use the tomcat windows service (and that's what we want to use on the server), it just never launches. Or to be more specific, it launches and stops the application directly. No java errors thrown and process.waitFor() with an exit value of 0. The fact is that we can run processes via the web application (I tried to run simple batch files), but when there is an UI involved, it will never appear.
Again, on the server this time, if I launch tomcat7.exe (that we can find in the %CATALINA_HOME%/bin directory) with a double click or cmd, the UI in the web application will appear. If I launch it with services.msc or tomcat7w.exe or tomcat7 start via cmd, it will not.
I thought of several things:
use another user to start the service
change the way the service is launched (StartMode: jvm, java. I did not succeed with exe)
I read Tomcat 7 Windows Service How-To many times but didn't find out anything to solve my issue.
Have you any idea of what is happening, and how to solve this issue ?
What is the big difference between running tomcat as a service and from the command line?
Option 1
If you open your service's properties window, go to the Log On tab then check the "Allow service to interact with desktop" check box you will get the behavior you want. Also depending on what app you what to run you may need to change the log on account.
see Launching GUI App from Windows Service - Window Does Not Appear
Option 2
Did you try start a cmd and there use
start /c "c:\path to\exe"
in cmd.exe type
help start
Option 3
You will need a daemon service that is not run as a service. windows puts certain restrictions on service apps.
This sleeping app can be started by tomcat or other your self. it can listen on a port or poll a folder for a new file, and when it gets a job to do it starts the app you want. Via port or text file you can send the parameters.

Categories