NutzCN Logo
问答 关于打包运行的资源加载路径问题
发布于 2689天前 作者 shuxinyun 1924 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

在linux上,非打包的情况下运行正常,打包后,系统加载配置文件出现错误提示如下,请帮忙看下!

[DEBUG] 2017-08-12 19:58:53,200 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/open/ueditor/bd/index 10ms
[WARN ] 2017-08-12 19:58:53,201 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/open/ueditor/bd/index :
java.lang.RuntimeException: Can not find file '/home/zrzc/git/shuxin.java/dst/tmp/webinf/assets/plugins/ueditor/nutz/config.json'
	at org.nutz.lang.Lang.makeThrow(Lang.java:132)
	at org.nutz.lang.Files.read(Files.java:47)
	at cn.wizzer.app.web.modules.controllers.open.ueditor.BdController.index(BdController.java:29)
	at cn.wizzer.app.web.modules.controllers.open.ueditor.BdController$FM$index$b3953300b3d44119ad01c7c499fb9380.invoke(BdController.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:44)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Unknown Source)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:28)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Unknown Source)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Unknown Source)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(Unknown Source)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(Unknown Source)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(Unknown Source)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(Unknown Source)
	at org.eclipse.jetty.security.SecurityHandler.handle(Unknown Source)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(Unknown Source)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(Unknown Source)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(Unknown Source)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(Unknown Source)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(Unknown Source)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(Unknown Source)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(Unknown Source)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(Unknown Source)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(Unknown Source)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(Unknown Source)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(Unknown Source)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(Unknown Source)
	at org.eclipse.jetty.server.Server.handle(Unknown Source)
	at org.eclipse.jetty.server.HttpChannel.handle(Unknown Source)
	at org.eclipse.jetty.server.HttpConnection.onFillable(Unknown Source)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(Unknown Source)
	at org.eclipse.jetty.io.FillInterest.fillable(Unknown Source)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(Unknown Source)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(Unknown Source)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:748)
[DEBUG] 2017-08-12 19:58:58,265 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) - ClusterManager: Check-in complete.


24 回复

上述路径存在吗?看上去在WEB-INF下,可以考虑换成ServletContext相关api来读取

这是nutzwk原有的类吧?看来要 @Wizzercn

上面路径在包里的吧,实际上是不存在的,是原生类!

分析了下代码,觉得改变这个配置文件的所在位置为资源文件夹下应该可以!但不清楚@Wizzercn 这么部署是否有特别的需求!

非常谢谢,上面问题解决!
还有第二个问题,还是打包运行的问题。
打包后,运行起来后,在系统内上传文件,上传的文件放到了dst/tmp/webinf/upload下面,关闭运行包后,重新运行包,整个tmp目录被删除重建了,upload文件夹就没有了,导致上传的文件不存在了!

也就是网站根目录是在webinf下面,但是每次运行起网站后,这个目录会被删除后重建,导致上传的文件在应用重启后丢失!

这个可以配置的

cn.wizzer.app.web.commons.base.Globals.initSysConfig(Dao)

目前上传目录默认配置是“/upload”我修改调整这个后,上传不成功。如果要把上传目录放到打包jar的所在目录下,不知道应该如何设置这个路径!

写一个绝对路径

我在linux下这样写 /home/zrzc/git/shuxin.java/dst/upload,不对的,也在webinf下面建立了这些目录!
如果window上带上盘符是否可以,还么有测试!

/home/zrzc/upload/

不可,目录还是在/home/zrzc/git/shuxin.java/dst/tmp/webinf/下

你是怎么设置的???

系统参数设置:
AppUploadPath=/home/zrzc/upload/

保存后,然后上传文件后,会在/home/zrzc/git/shuxin.java/dst/tmp/webinf/下建立home/zrzc/upload

/home/zrzc/git/shuxin.java/dst/tmp/webinf/是网站根目录,不论如何设置,所有目录都在这个目录下!

public Object uploadimage(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
        NutMap nutMap = new NutMap();
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return nutMap.addv("state", "FAIL");
            } else if (tf == null) {
                return nutMap.addv("state", "FAIL");
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                nutMap.addv("state", "SUCCESS");
                nutMap.addv("url", Globals.AppBase + f);
                nutMap.addv("original", tf.getSubmittedFileName());
                nutMap.addv("type", tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf(".") + 1));
                nutMap.addv("size", tf.getSize());
                return nutMap;
            }
        } catch (Exception e) {
            return nutMap.addv("state", "FAIL");
        } catch (Throwable e) {
            return nutMap.addv("state", "FAIL");
        }
    }

服务重启了!

你本地debug一下呗, 不就一个变量, 总能把它的值改了

我主要是想通过网站url能直接访问到上传的文件,如果不是在网站下就必须重开一个文件网站!

你需要一个nginx

恩,我研究一下nginx

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