本人特别喜欢在折腾这件事上浪费生命!java
手上有一个基于Maven的Web项目,Web框架用的Nutz,最近不是Nutzmore出了新版,我就看了一下,发现这个Undertow很厉害的样子,就打算试一试。web
那么淌坑的经历就开始了。apache
首先,我用了WebSocket,插件(Nutz-plugins-undertow)并无特别说明用法,看了一下源码,最后在WebLancher的start方法里,本身添加了一个WebSocket的HttpHandler。websocket
-----------小分分--------------框架
//添加WebSocket的Handler PathHandler pathHandler = Handlers.path().addPrefixPath("/myWebsocket", websocket(new WebSocketConnectionCallback() { @Override public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) { channel.getReceiveSetter().set(new AbstractReceiveListener() { @Override protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) { //这就是服务端向客户端发送消息的方法 WebSockets.sendText(message.getData(), channel, null); } }); channel.resumeReceives(); } })).addPrefixPath(contextPath, servletHandler);
------------小分分----------------socket
而后还算顺利,到了打包的时候了,做者提供了一个相关的Pom文件例子和命令,不过由于我项目里还夹杂了一些Kotlin代码(好奇心忒重),我添加了Kotlin的编译相关的配置,不过一直没办法把页面及其相关的东西放进去,尝试过屡次,最后只有本身配置一个webRoot地址了,也能够写死,随你便。 具体的pom文件以下:maven
<build> <sourceDirectory>src/main/org</sourceDirectory> <finalName>ROOT</finalName> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${org.jetbrains.kotlin.kotlin-stdlib-jre8.version}</version> <executions> <execution> <id>compile</id> <phase>process-sources</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>your main class</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
最后执行ide
mvn clean package -U
就能够了 而后ui
java -jar xx.jar "你的web目录"
最后说明一下,这个“你的web目录” 是传递给WebConfig里的setRoot方法的,你能够用你喜欢的方式来插入!插件
还有其余坑,遇到再补充了。