NutzCN Logo
精华 按照入门手册的写法,用undertow加载nutz发布可执行jar.
发布于 124天前 作者 qq_eac79c48 156 次浏览 复制 上一个帖子 下一个帖子
标签:

项目使用maven,包含进相关jar包,
重点是在main方法,我的application:


@Encoding(input = "UTF-8", output = "UTF-8") @Modules(scanPackage = true) @IocBy(type = ComboIocProvider.class, args = { "*js", "ioc/", "*anno", "psyduck.me.nutz", "*tx", "*async" }) public class Application { private static final String NUTZ_FILTER = "nutz"; private static final String CONTEXT_PATH = "/"; public static void main(String[] args) throws ServletException { FilterInfo nutzFilter = new FilterInfo(NUTZ_FILTER, NutFilter.class); nutzFilter.addInitParam("modules", "psyduck.me.nutz.Application"); DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(DeploymentInfo.class.getClassLoader()) .setContextPath(CONTEXT_PATH).setDeploymentName("test.war") .addFilter(nutzFilter) .addFilterUrlMapping("nutz", "/*", DispatcherType.REQUEST) .addFilterUrlMapping("nutz", "/*", DispatcherType.FORWARD); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); HttpHandler servletHandler = manager.start(); PathHandler path = Handlers.path(Handlers.redirect(CONTEXT_PATH)).addPrefixPath(CONTEXT_PATH, servletHandler); Undertow server = Undertow.builder().addHttpListener(9999, "localhost").setHandler(path).build(); server.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> server.stop())); } }

相关的import就不贴了.
这只是最基本的配置,全都是默认配置,需要修改的自己查一下文档吧.
然后是maven配置:

<build>
		<resources>
			<!-- 控制资源文件的拷贝 -->
			<resource>
				<directory>src/main/resources</directory>
				<targetPath>${project.build.directory}/classes</targetPath>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<appendAssemblyId>false</appendAssemblyId>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<archive>
						<manifest>
							<mainClass>psyduck.me.nutz.Application</mainClass>
						</manifest>
					</archive>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>assembly</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

修改mainClass 为你的主类,然后打包运行一下试试吧.
ps:还是从springboot过来的,还是用嵌入式容器比较舒服

4 回复

要不你弄个 nutz-plugins-undertow 固化下来吧?

强!
undertow比jetty性能好不少

额.因为undertow并不支持jsp..我还在看怎么替换一个模板框架.freemarker或者thymeleaf.

添加回复
请先登陆
回到顶部