I want to develop a Java based Webservice on my laptop. This webservice will take one input parameter, query my SQL Server database and will fetch information and will return it back.
I know, I do not need a webservice here. But, right now, I am just testing my android application which will call this webservice and will show return data on my device.
So, I have developed a java program which connects my SQL Server Database (which is present on my laptop) and returns a value against the parameter passed. I have made it a webservice by creating endpoints and publishing it from another class.
For reference, something like answer on this thread
So, when I run it from my Eclipse, I can go to a browser and run my webservice, pass parameter and get result.
But, once I close my eclipse, its no more accessible. I am new to this and after studying I am guessing that I will need IIS to host it on my laptop.
I want to ask, whether it is possible to run/publish it locally on my laptop as a background process so that I can test my android app by calling the same?
Future scope -
I am going to deploy this webservice in my company which will connect my database. Both webservice and sql server will be on same machine. I am going to call this webservice remotely over internet from my android device to show the results.
I guess, I will need IIS in future right? Is there any other way to fulfill this requirement? Please provide some ideas.
If, within Eclipse, you can get your web application deployed so that it is accessible via a browser, then you definately can do it without eclipse.
Eclipse uses plugins like Tomcat or Glassfish to run your webserver. These programs are available outside of Eclipse as standalone services. You can install these and run them as background processes at the command line.
Just figure out which one you are using in eclipse (or which one you want to use) and look for a standalone copy on the web.
Here's Tomcat, btw.
I am done with this.
What I did is, I went to Eclipse, selected my Project-> Right Click -> Export -> Under General -> Ant Buildfiles
This created, Build.xml in my Project directory.
I deleted all the class files and recompiled them using ant command.
In my case, target name was build-project which compiles all the java files.
So, I did ant build-project
Note - This was done as Eclipse was using different JDK version.
Now, I called my publish class to publish my webservice with
ant publish
This was half done as this was running in interactive mode.
Then I created a bat file with following command -
"path_for_ant_bin_directory\ant" -buildfile "path_to_build_file\build.xml" publish
This was opening up the command box. So, I created a vb script to run the bat file in background
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c path_to_bat_file\my_bat.bat"
oShell.Run strArgs, 0, false
And, now it nicely runs in background and I can access my webservice.
Hope it helps someone with similar requirement.
Related
So, I have this client-server app which is written in 4th Dimension Language, that runs as a service so it restarts automatically if something happens to the server. This language has a built in function which allows you to run cmd commands and I have another java app in the same folder, that is in charge of sending emails, something my server side app cant handle. We use a command for running this jar from cmd and send the parameters from there, creating and xml for it to create an html from that and send it via email. The thing is when I run this command with the app running as a service, the command simply does not run, but, if I run the app normally, it works like charm, with no problems whatsoever.
At first I thought it could be the paths, so I got all the paths to be absolute, using the full route, yet it doesnt work still. Also I tried exporting the command as a bat and running it by hand, in the exact same path were the server is, and it works just fine. I thought that maybe the service needs some sort of admin privileges, so I started it as Admin from the service, but it changed nothing.
Is there any chance the service has some sort of limitation which doesnt allow the app to execute external commands? If so, is there anyway to bypass this limitation?
Well, I couldn't make it work when it was running by service, so I made a bat with the command the service uses and pasted it in the Windows Startup Folder, so it "opens manually" when windows starts. It's not the real answer, but is workaround for needing to use the service.
I have built a web app which runs with simply java -jar app.jar. It looks at the environment variable PORT to decide which port to listen on. now I want to deploy it to Azure with a Windows app service plan, this is called This is called "Java SE deployment" in Azure.
On a Linux app service plan, I can simply deploy the app.jar file (using vs code plugin, zipdeploy, or whatever), set the environment variable PORT, and everything is fine.
With a Windows app service plan, attempting to access the app gives a 500 error with the body "The web server failed to respond within the specified time". I've turned on all the logging I can, and I can see the request gets into IIS but no indication that it's attempted to send the request to my app.
However I can access my app directly from the Azure console using curl http://localhost:<port>. so I know it has started up.
I've done this tutorial https://learn.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-windows which works fine, but I'm not using maven or spring boot - I need to build the jar file myself.
I've read https://learn.microsoft.com/en-us/azure/app-service/deploy-zip and https://learn.microsoft.com/en-us/azure/app-service/configure-language-java?pivots=platform-windows but they doesn't seem to be telling me anything I don't already know.
By dumping out the environment in my app, I discovered that Azure sets the environment variable SERVER_PORT to a number and that if you listen on that number, the requests are forwarded correctly. It actually sets quite a few environment variables to the same port number, but I chose SERVER_PORT because it looks like the most meaningful name, and there are some references to it in various blogs etc. HTTP_PLATFORM_PORT is also set.
I'd still be grateful for any references to official Microsoft documentation, so at least I know whether there's a "proper" way to do this.
I have a signed java web start app that has been running on a server for many years. I have a need to create a version that I can run on a local machine. I have setup WAMP and the database and confirmed that these work by accessing through php scripts via localhost. My java program is also launching but there is a problem when it tries to access a local php file through locahost. Nothing is returned. I call php scripts that access the database from within the java app. Am i missing something fundamental here? ANy help appreciated. Thanks
Thanks for the responses. The problem has been solved. I forgot to turn off deprecation and other warnings so what I was getting back from the php scripts was not what I expected. Once I turned off the warnings everything functioned as expected. To sum up, I am serving up a java web start app through localhost, executing php scripts from within the java app that manipulate an sql database, and return the results to the java app.
Thanks again,
greg
Well are you using Quercus ? It would have been easier to suggest a solution if you had mentioned how you are running php scripts in java app.
Basic thing here is you should always call your php file using classpath or path associated within the project
PHP php = new PHP("classpath:/com/demo/phpfile.php");
or sometimes you could use(os path if set up correctly) path of file as accessed by you operating system.
C:\websites\www\myproject\phpfile.php(example windows path)
if you are accessing files like http://localhost/myproject/phpfile.php
then the php file is executed by the wamp server and html output returned. so you do not get the php script.
If you are trying to run java inside php then you could call php files in the manner http://localhost/myproject/phpfile.php to see the end result.
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.
I have a server, and Client that are working fine, they transfer file to each other and handle commands with success. The thing is that once connected to the server, the server can ask the Client to update itself.
Since I did everything using sockets with a TCP connection, and I am NOT able to use java web start, I am looking for a way I can update the software.
One thing I thought was:
Making the java call another java software and close itself. Then the other java software, would connect to the server again and waits for the update request, so it could replace all files from the current version (lib directory and the jar main file - Im using Netbeans).
Maybe I could just send the connection Object to the Software that would update, but the main only accpets String.
So I ask two questions here:
Is this a good solution? Or is there a better one?
If I do that, how can I send the Client Object of my proto from one application to another?
I would suggest keep a property file on server having latest version of app.
Each time you start the app compare version if its updatable then download all new updates in a temp dir
After SUCCESSFUL download invoke another small application to copy those files to your lib file in order to update your app actually
At the end prompt user that app has been updated and launch the newly updated app. i would say.