Finding tomcat installation directory - c++

I have installed tomcat in my PC (Windows 10). Is there anyway that I can find the installation path of tomcat? I thought of making use of the command line with which java used to call the startup.bat file but then I realized that the command line keeps changing depending on how it is called. I have to find the installation path of tomcat programmatically using c++.
Updated : I need to find the installation path only if tomcat is running

You could execute jps -lv and parse the results.
A Tomcat Java process would look like
12345 org.apache.catalina.startup.Bootstrap ... -Dcatalina.base=<some_path> ...
Where 12345 is the PID and <some_path> is the home of Tomcat.
Beware that there could be multiple instances of Tomcat running.

Related

How to add a second web app with jetty alongside with geoserver?

I deployed the Platform Independent Binary of GeoServer on ubuntu. To launch geoserver, I would just run this script /usr/share/geoserver/bin/startup.sh
So no jetty is actually installed. Geoserver web app can be accessbile via http://localhost:8080/geoserver/web
I wonder how I can configure a second web app which takes this path http://localhost:8080/upload/index.html
Ideally, I would like python and perhaps PHP are supported.
Any tips is appreciated. Thanks.
You can add any other war files to geoserver_dir/webaps/ and Jetty will unpack and run them like any other servlet.
I have no idea how you would add python and PHP to that set up. Maybe you would be better off looking at running tomcat and apache and using the GeoServer war file there.

How to run multiple jetty instances

How do you run multiple jetty instances without maven? I am using jetty jetty-9.2.15.v20160210. I did some google search for this and found
https://sagarkarnati.wordpress.com/2012/09/18/run-multiple-instances-of-jetty-on-the-same-machine-with-different-ports/
But the version of jetty is 6 and the file structure in that version is totally different from 9.2.15. Does anyone have any idea?
I want to run two jetty instances on two different ports.
In jetty 9, you will deal with $jetty.home and $jetty.base directory. Jetty advises to run jetty from $jetty.base directory.
E.g. C:/jetty = $jetty.home directory and C:/jetty/demo-base = $jetty.base directory.
You can specify which $jetty.base directory to use while running each jetty instance on the same machine.
To solve this issue, I copied $jetty.base directory in $jetty.home directory and renamed it as C:/jetty/demo-base-A.
Before we can run two instances of jetty, make sure to change the port used otherwise we can run into port conflict issue.
Go to $jetty.base/start.d/ directory and change https.ini and http.ini for port.

Webserver not working on OSX Mavericks

I was running a webserver and also Coldfusion just fine until I upgraded to Mountain Lion, then it stopped working. I got it working again by turning everything back on that the upgrade disabled, but now I have upgraded to Mavericks nothing is working. I have followed all the steps in various web articles but it won't work. PHP is enabled, everything that was enabled before is set up, including virtual hosts, and all the folders are in the same place.
I get the error: Firefox can't establish a connection to the server at 127.0.0.1. [or localhost, or any of my virtual hosts]
I've gone over everything time after time and I can't figure out why it won't work. I have started, stopped, restarted the webserver numerous times, it is set to start on bootup too. I couldn't even complete the Coldfusion install because I couldn't load the administrator in a browser.
What could the problem be? Where should I look?
This is not a complete answer, but this should help get things started
Try using the command line start. It will probably be complaining about Java 7 not being installed. I recently needed to install Java 7 JDK (not JRE to get things running)
I know to get the rest of it running, I need to point ColdFusion at the proper JVM. You can find the JVM settings at /Applications/ColdFusion10/cfusion/bin/jvm.xml. You should have some setting like
# VM configuration
#
# Where to find JVM, if {java.home}/jre exists then that JVM is used
# if not then it must be the path to the JRE itself
java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
application.home=/Applications/ColdFusion10/cfusion
When you install Java 7, the JRE is at
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Backup, and edit the jvm.config file to
#
# VM configuration
#
# Where to find JVM, if {java.home}/jre exists then that JVM is used
# if not then it must be the path to the JRE itself
java.home=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
# java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
application.home=/Applications/ColdFusion10/cfusion
If all goes well, you should be able to start ColdFusion
Some additional help
Installing Java on OS X 10.9 (Mavericks)
When you install Java 7
Just saw this thread. ColdFusion 10 is now supported on OS X 10.9 Maverick with the release of CF10 Update 13.
This should work for you now.

Find the jetty home directory from inside a java web application when running as a linux service

I have a jetty 9 installed on CentOS in /srv/jetty, and I have a webapp deployed inside jetty.
When I start jetty with java -jar start.jar & then inside the web application I can do this:
File base = new File(".");
System.out.println("Base Dir: " + base.getAbsolutePath());
And it returns me the correct directory of the jetty installation.
But then I add jetty as a linux service, to run with a user called jetty, and start with service jetty start then calling the above code, will allways give me back the home directory of the user, who is running jetty in this case /home/jetty/ or if I run as root then /root/
How can I set up jetty to find the correct directory? I tried with jetty.home in the config files, but nothing seems to work.
You have a few things to worry about.
The noteworthy paths for a WebApp on Jetty:
ServletContext Real Path
Jetty Home
Jetty Base (starting in Jetty 9.1)
ServletContext Real Path
All WebApps that are deployed and started, will occupy either a work directory, or a temp directory (on the whim of the container). The servlet spec mandates that this path should be discoverable via the ServletContext for that webapp. You can find out where your WebApp is, by calling ServletContext.getRealPath("/")
See my prior answer for 5 different ways you can configure this work/temp directory:
https://stackoverflow.com/a/19232771/775715
Jetty Home
By default, all Jetty Distribution instances will have a System Property called jetty.home that will be the path to the Jetty Home location on disk. This is to be assumed to be where the Jetty Binaries and Distribution configurations are found.
Jetty Base
Starting in Jetty 9.1, there is also a mandatory System Property called jetty.base that is where your specific instance of jetty's configuration + libraries + webapps are housed. This is often a different directory than jetty.home.
This separation of binaries vs configuration is a core concept of Jetty 9.1, adopting a clear separation will making upgrading the Jetty binaries easy.
See http://www.eclipse.org/jetty/documentation/current/startup-base-and-home.html
I thing I have found the easy answer:
usermod -m -d /srv/jetty jetty
As it was advised in many places on the internet I created a user jetty to run the jetty service. So whatever I did -even if I set JETTY_LOGS- the log files allways ended up in the users home directory. By modifying the jetty users home directory the File(".") and the logs all end up where I wanted to

How to stop jetty runner from executing

Am using jettyrunner for executing my war files.I am using command java -jar jetty runner ex.war.But am running this jetty server from my java application by executing this commands from java.My problem is at first time its working good,but the second time if i am again executing another war file with the same code its executing the older war.i have found the reason that the older jetty server is keep on running.How could i stop this server from java in order to start the jetty server for another war.
One option should be:
http://wiki.eclipse.org/Jetty/Howto/Secure_Termination
Another would be to use the ShutdownHandler:
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java
Or don't use the jetty-runner directly like that from java code and just write a small embedded usage:
http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
Turned out, jetty-runner.jar doesn't have a feature to stop existing jetty process ran with stop-port and stop-key.
I found the answer in https://github.com/jetty-project/jetty-documentation/blob/master/src/docbkx/administration/runner/jetty-runner.xml
Then, to stop jetty from a different terminal, you need to
supply the same port and key information. For this you'll either
need a local installation of jetty, the jetty-maven-plugin jetty-ant plugin, or write a custom class
Fortunately, I was implementing gradle build, so jetty-ant satisfied my needs.