Jetty tool on Windows and windowsjetty Tool

Source: Internet
Author: User

Jetty tool on Windows and windowsjetty Tool

Java applications often need to be developed for projects. I like to use Jetty for development and deployment, mainly because Jetty is lightweight.

Jetty project home page: http://www.eclipse.org/jetty/, the latest version 9.30 just added support for HTTP/2.

However, it is not convenient to deploy Jetty in Windows. You need to use the command line.

Every time I use the command line, it is very troublesome. So I plan to make a Jetty tool and encapsulate the command line operation to start and stop Jetty in the GUI, common parameters can be configured.

Download test code

Compiled executable files:

JettyMonitor-v0.1-alpha-x64.7z JettyMonitor-v0.1-alpha-x86.7z


Note that you need to install. NET Framework 4.5.2,

Install Dev Pack: http://www.microsoft.com/en-us/download/details.aspx? Id = 42637

End user install runtime: http://www.microsoft.com/en-us/download/details.aspx? Id = 42642

 

 Java Home: A friend who often works in Java Development knows that it is the JDK directory.

These directories are saved in the configuration file after you click Save Configuration.

During the first running, you can also find the following environment variables.

EnvironmentUtil is an environment variable help class that facilitates various operations on environment variables. For details, see the source code.

 

Jetty Home: the decompressed Jetty directory:

So what is Jetty Base? On the official documents are introduced: http://www.eclipse.org/jetty/documentation/current/quickstart-running-jetty.html

A jetty base allows the configuration and web applications of a server instance to be stored separately from the jetty distribution, so that upgrades can be done with minimal disruption.

That is, the Jetty Base directory is a separate storage directory of an application, which can be different from the configuration of the main directory of Jetty Home. This brings a significant benefit, and will have little impact on the original application when the Jetty version is upgraded in the future.

Jetty Base is introduced in Jetty 9.1 and is very new.

Jetty's official deployment suggestion is to create a new Jetty Base deployment, instead of directly putting the war package into the webapps directory of the Jetty Home directory.

The local port is the Web port of Jetty. The default port is 8080 ,. The remote port is used for remote debugging and cannot be enabled.

The general running command is: java-jar start. jar jetty. http. port = 8080

The command for remote debugging with JVM is: java-Xdebug-agentlib: jdwp = transport = dt_socket, address = 9000, server = y, suspend = n-jar start. jar jetty. http. port = 8080

 

Let's sort out the Jetty deployment steps:

1. Select a Jetty Base directory to enter the directory.

2. initialize the Jetty Base Directory: java-jar % JETTY_HOME %/start. jar -- add-to-startd = http, deploy

-- Add-to-startd parameter is used to initialize the Jetty module. Jetty has many modules at: % JETTY_HOME %/modules


Add as needed. I developed it using Spring MVC and added these modules: -- add-to-startd = http, deploy, spring, servlet, servlets, webapp, jsp, jstl, server

In addition to the -- add-to-startd command, Jetty also has many commands, which can be viewed by entering: java-jar start. jar-help

After initialization, the Jetty Base Directory generates two directories;

Here, start. d saves the configuration file of the module;

Webapps are used to place published war packages;


3. run java-jar start. jar to start Jetty.

I have integrated these three steps into a batch to facilitate processing in a program:

Cd/d "D: \ Publish \ JettyBase"

"C: \ Program Files \ Java \ JDK8 \ bin \ java.exe"-jar "D: \ Developer \ Server \ Application \ Jetty \ Jetty9 \ start. jar "-- add-to-startd = http, deploy, spring, servlet, servlets, webapp, jsp, jstl, server

"C: \ Program Files \ Java \ JDK8 \ bin \ java.exe"-Xdebug-agentlib: jdwp = transport = dt_socket, address = 9000, server = y, suspend = n-jar "D: \ Developer \ Server \ Application \ Jetty \ Jetty9 \ start. jar "jetty. http. port = 8080

 

Use Process to execute batch processing when starting Jetty.

Note that you must enable the redirection standard output and standard error to get the batch processing result;

Started successfully;

Open the browser and test;

In IDE, you can easily set remote debugging;

You can directly edit the batch content in the configuration command line and save it after editing;

The configuration file is saved in the same directory of the gadgets;


When jettyis stopped, the Java process of Jetty is started with cmd.exe because we use the jettywhose process execution is started. The Java process acts as the sub-process of cmd and cannot be directly closed with process. Close.

Here we use Process to execute the doscommand to kill all Jetty processes: TASKKILL/F/PID xxx/T

/F is forced to kill,/PID specifies the process ID,/T is to kill all sub-processes,

So stop Jetty 


 

Summary:

In this way, you do not need to operate on the command line interface, and the configuration can be saved, customized, and can view the startup and stop logs.

The modified configuration can also be applied to other Java servers.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.