NutzCN Logo
问答 使用hotplug建项目时遇到的几个问题
发布于 2807天前 作者 老司机 2249 次浏览 复制 上一个帖子 下一个帖子
标签:

RT,在做一个热插拔的demo,遇到各种问题
首先起不来,这是webapp的mainmodule

@LoadingBy(Hotplug.class)
@Modules(scanPackage = false)
@IocBy(args = {"*async", "*tx", "*slog"})
@SetupBy(MainSetup.class)
public class MainModule {
}

启动报错

17-03-09 17:14:14.130 ERROR [RMI TCP Connection(4)-127.0.0.1] Error happend during start serivce!
java.lang.ClassNotFoundException: slog
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at org.nutz.lang.Lang.loadClass(Lang.java:2022)
	at org.nutz.ioc.loader.combo.ComboIocLoader.createIocLoader(ComboIocLoader.java:124)
	at org.nutz.ioc.loader.combo.ComboIocLoader.<init>(ComboIocLoader.java:80)
	at org.nutz.plugins.hotplug.Hotplug.createIoc(Hotplug.java:134)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:103)
	at org.nutz.plugins.hotplug.Hotplug.load(Hotplug.java:110)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4563)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5205)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
09-Mar-2017 17:14:14.136 严重 [RMI TCP Connection(4)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
09-Mar-2017 17:14:14.136 严重 [RMI TCP Connection(4)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/webapp] startup failed due to previous errors
27 回复

在父项目的pom里面添加了

org.nutz
nutz-plugins-hotplug
1.r.60.r3

@ wendal刚才是我二逼了,不应该加slog的,然后现在启来后日志

17-03-09 17:27:59.919 WARN [RMI TCP Connection(4)-127.0.0.1] None module classes found!!!
17-03-09 17:27:59.919 WARN [RMI TCP Connection(4)-127.0.0.1] None @At found in any modules class!!

我再另一个module里面写了一个@At啊

@qq_c1bab051 我的办法就是在该MainModule写个入口方法

@Ok("http:200")
@At 
public void test(){}

@wendal 然并卵

public class YvrMainModule {
    @Ok("http:200")
    @At
    public void test(){}
}

还是报nofind

不是插件的MainModule,是真正的那个MainModule

@wendal 试了webapp的module,ok插件的module还是不行

@qq_c1bab051 啥?

我指的真正的MainModule,是web.xml里面写的那个.

@wendal 我以nutz-book为例啊,里面的webapp是web模块,这里面有MainModule,有web.xml,现在的情况是webapp里面MainModule可以@At test,但是平级的插件yvr里面的Module@At不到!

hotplug没找到插件? hotplug.yvr.json 写了没

如果已经写了, 那么, 看看webapp这个项目是否依赖了yvr模块, 通过直接依赖, 或者profile依赖

如果是profile依赖,那么,还需要右键webapp项目, maven, select profiles, 选上yvr模块

@wendal 百度了没看懂,这个profile依赖怎么写,而且我用idea没找到select profiles

看nutzcn的pom.xml

写好之后, idea会自动识别的, 然后执行maven命令的地方可以选.

@wendal webapp的pom

 <profiles>
        <profile>
            <id>yvr</id>
            <dependencies>
                <dependency>
                    <groupId>shawn_xiao</groupId>
                    <artifactId>yvr</artifactId>
                    <version>1.0.0</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>

yvr的pom

<modelVersion>4.0.0</modelVersion>
    <artifactId>yvr</artifactId>
    <packaging>war</packaging>
    <name>yvr Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <version>1.0.0</version>

还是没有扫到module

勾选profile了吗?

@wendal idea可以运行了,然后是打包mvn clean package assembly:single是在插件目录下用的,那parent目录下面用什么???怎么能把parent打成war(不含yvr之类插件)

parent不需要打包哦,要打包的是webapp,用

mvn package 就好了

@wendal 我在yvr的pom里面添加了

 <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>cn.outofmemory.MainClass</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>

打包出来的jar里面有nutz的包一兆多,我就想能不能不要包呢,毕竟主项目里面有包,插件又有包,让项目变得很大

scope设置为provided就不会打包进去.

@wendal 哦哦,然后webapp打成war扔到tomcat里面了,把yvr的jar扔到webapp的lib里面并没有用啊,需要重启tomcat吗?

@qq_c1bab051 看nutzcn的HotplugModule,需要触发的. add 然后 enable

调用add 之后,默认存放到/var/lib/hotplug,并处于未启用状态

调用enable启用之. 启用状态会通过标记文件进行记录. 下次启动tomcat时,也会读取并加载/var/lib/hotplug下已经启用的插件.

如果你希望手工放进去就生效, 可以考虑开个线程,监视该文件夹的变化, 识别出新增的jar及其".enable"文件后,调用Hotplug.enable方法进行启用.

@wendal 嗯嗯,刚才试了下,直接扔到项目的lib里面然后重启tomcat就好

来自炫酷的 NutzCN

嗯嗯,添加到lib的话,相当与选了maven profile嘛

@wendal 能不能不重启tomcat直接扫描加载yvr

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