The Jetty gadget on Windows

Source: Internet
Author: User

Do projects often encounter the need to develop Java applications, I like to use jetty for development, deployment, mainly due to the lightweight jetty.

Jetty Project homepage: http://www.eclipse.org/jetty/, the latest version 9.30 has just added support for HTTP/2.

However, Jetty is not easy to deploy under Windows and requires a command line.

Every time to use the command line, it is very troublesome, so I am going to do a jetty gadget, the command line operation package, you can start in the GUI, stop jetty, you can configure common parameters and so on.

After the completion of the interface is as follows:

Test code Download

Compiled executable file:

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

Note You need to install the. NET Framework 4.5.2:

Developer Installs Dev pack:http://www.microsoft.com/en-us/download/details.aspx?id=42637

End-User Installation run-time: http://www.microsoft.com/en-us/download/details.aspx?id=42642

Java Home: A friend who often does Java development knows it is the directory of the JDK.

These directories are saved in the configuration file after clicking Save configuration:

You can also find from environment variables the first time you run:

Environmentutil is an environment variable helper class that facilitates various operations on environment variables, see source code for details.

Jetty Home: Refers to the extracted Jetty directory:

So what is jetty Base? Official Documentation: 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 being stored separately from the jetty dis Tribution, so-upgrades can be do with minimal disruption.

that Jetty Base a directory is a separate storage directory for an app that can be used with Jetty Home the configuration of the home directory is not the same. This provides a significant benefit in the future when upgrading the Jetty version has a small impact on the original application.

Jetty Base is a Jetty 9.1 The version was introduced, very new.

Jetty's official deployment recommendation is to create a new Jetty base deployment instead of putting the war package directly into the WebApps directory of the Jetty home directory.

The local port is the jetty Web port, and the default is 8080. Remote ports are used for remote debugging and can not be turned on.

The General Run command is:java-jar start.jar jetty.http.port=8080

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

Let's tidy up the steps for jetty deployment:

1, select a directory jetty the base directory, enter the directory.

2. Initialize JETTY base directory: Java-jar%jetty_home%/start.jar--add-to-startd=http,deploy

The--ADD-TO-STARTD parameter is responsible for initializing the required JETTY module, JETTY has many modules, located in:%jetty_home%/modules

As needed, I developed it with 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 has a number of commands that you can enter: Java–jar start.jar–help view:

After initialization is complete, generate two directories in the Jetty base directory:

Where START.D saves the module's configuration file:

WebApps used to place the release of the war package, etc.:

3. Run Java–jar Start.jar start jetty

I've integrated these three steps into a single batch process, which is easy to process:

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 perform batch processing when starting jetty:

Note To enable redirection of standard output and standard errors, you can obtain the execution results for the batch:

Startup success:

Open your browser and test it:

Remote debugging can be easily set up in the IDE:

You can edit the contents of the batch directly on the configuration command line and save it when you are finished editing:

The configuration file is saved in the same directory as the gadget:

It is important to note that when you stop jetty, because we use the process to execute a batch-initiated jetty, that is, the Java process that started the jetty with Cmd.exe, the Java process resides as a subprocess of CMD, and cannot be used directly with process. Close () closes.

Here we use the process to execute DOS commands 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 child processes:

So to stop jetty:

Execution Result:

Summary:

This way, we can not operate in a pure command line interface, and the configuration can be saved, customized, you can view the start, stop the log and so on.

Modifying the configuration can also be useful for other Java servers.

The Jetty gadget on Windows

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.