I have the following project folder setup for a simple Java undertow HTTP server:
- HelloWorldServer.java
- build
- lib
I downloaded XNIO and JBOSS-Logging into lib. I made sure I downloaded the right distributions by letting Gradle download the dependencies. But I'm trying to understand more by running things manually so I copy the jar files into the lib folder.
My HelloWorldServer.java
looks like this:
import io.undertow.Undertow;
import io.undertow.util.*;
public class HelloWorldServer {
public static void main(final String[] args) {
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(exchange -> {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World");
}).build();
server.start();
}
}
Then I go to my folder root and run the following command:
javac -cp "lib/*" -d build HelloWorldServer.java
Now that I've compiled the application, how do I run it from terminal?
EDIT: the content of my lib
directory is as follows:
hamcrest-core-1.3.jar // i believe thats not needed, but leave it anyway
jboss-logging-3.2.1.Final.jar
undertow-core-2.0.0.Alpha1.jar
xnio-api-3.3.6.Final.jar
xnio-nio-3.3.6.Final.jar
由于使用-d标志,您要求Java编译器在build目录中生成类文件,因此需要像这样运行:
java -cp "build/:lib/*" HelloWorldServer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.