How to run multiple jetty instances - jetty

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.

Related

Finding tomcat installation directory

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.

How to add a folder Jetty will run a site from?

I have Jetty running on an Oracle VBox VM (Win7) Guest. I need Jetty to run a site from a shared folder, so I can edit it on the host. How can I do that?
Edit: The site is HTML/JS, not a war file. I see from the docs I can copy a war to $JETTY_HOME. What I'm wondering is if I can add a path to $JETTY_HOME for Jetty to look in?
The path is \\VBOXSVR\MyCoolSite

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

best way to deploy jetty application--too many options?

I need to deploy a production version of a web application. So far, I've been testing it with mvn jetty:run. I've used actual jetty installations before, but they seem only necessary when you want to serve multiple wars on the same web server. In some ways this is the most staightforward however (mvn package and copy it over).
My other options are to create a runnable jar (mvn assembly:single) that starts a server, but I need to tweak the configuration so that the static content src/main/webapp is served and the web.xml can be found.
I've also read about a "runnable war". This might avoid the src/main/webapp problem since these files are already laid out in the warfile. I don't know how to go about doing this, however.
I could also stick with mvn jetty:run, but this doesn't seem like the best option because then the production deployment is tied to code instead of being a standalone jar.
Any opinions on the best way or pros and cons of these different approaches? Am I missing some options?
The jetty-console-maven-plugin from simplericity is simple to use and works great. When you run mvn package you get two wars--one that is executable. java -jar mywar.war --help gives usage, which allows a bit of configuration (port, etc.).
I'm not that familiar with maven, but this is how we approach deployment using embedded Jetty:
We create a single-file JAR with the embedding jetty app and the necessary lib jars packed.
We deploy the static content in a WAR file (which you can package into the JAR as well). Everything is generated by an ANT file that:
1) Build the static files WAR (this also creates the web.xml)
2) Copies the WAR into the application resources
3) Compiles an executable JAR
To get the embedded Jetty to "find and serve" your static files, add the war with a WebAppContext to the Jetty handlers:
Server jetty = new Server(port);
HandlerList handlers = new HandlerList();
WebAppContext staticContentAsWar = new WebAppContext();
staticContentAsWar.setContextPath("/static/");
staticContentAsWar.setWar(resource_Path_to_WAR);
handlers.addHandler(set);
jetty.setHandlers(handlers);
jetty.start();
HTH

Jetty: Mount to a directory on a different host

I'm looking to map to a directory on a different host using Jetty/Maven when working locally. I've found you can do this w/ Apache using mod_jk (JkMount/JkUnMount), but haven't figured it how to do the same on jetty.
On our dev/q/live servers, we have Apache in front of JBoss and use mod_jk to do this. Locally, we're using jetty
To give you an idea of what I'm talking about, this is how you would configure Apache to accomplish this:
in httpd.conf:
JkMount /images/* host2
JkMount /* host2
JkUnMount /images/* host1
workers.properties:
worker.list=host2,host1
worker.host2.host=host-2.theDomain.com
worker.host2.port=46654
worker.host1.host=host-1.theDomain.com
worker.host1.port=46655
Is there a way to configure Jetty to do the same thing?
Btw, locally, I'm using the Maven plugin for Eclipse if that makes a difference.
thanks!
Update:
I tried going a different route here and just added a folder, then Advanced > Link to a folder in the file system and I pointed to a file on the remote server (I believe we use WebDav). The files show up in project explorer, but they aren't served. I'm going to try setting org.mortbay.util.FileResource.checkAliases to true as specified here:
http://docs.codehaus.org/display/JETTY/How+to+enable+serving+aliased+files
...will let you know if that takes care of it.
Are you using the Spring Framework? If so, another solution here is to use tuckey urlrewrite. You can test for your local domain and only run the rules there.
http://www.tuckey.org/urlrewrite/manual/3.0/introduction.html