NutzCN Logo
问答 web环境中,nutz有没有提供获取项目名的api?
发布于 2576天前 作者 蛋蛋的忧伤 1932 次浏览 复制 上一个帖子 下一个帖子
标签:

我想在类中获取到当前项目名,nutz有没有提供相关方法?

8 回复

你指centent path吧?

我指的事我的项目在webapps下的目录名字....

所以就是content path咯

String path = Mvcs.getServletContext().getContextPath();
String projectName = path.length() > 0 ? path.subString(1) : "ROOT";

大叔溜溜溜,好手法!摸摸大哦

如果是项目初始化想拿到值 赋值呢
main init 初始化
如何获取path呢

上面的代码在init里面能跑呀

[ERROR] 16:28:03.465 org.nutz.boot.NbApp.execute(NbApp.java:224) - something happen!!
org.nutz.ioc.IocException: IocBean[mainLauncher] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at org.nutz.boot.NbApp.execute(NbApp.java:214)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.contextInitialized(NbServletContextListener.java:79)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4770)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5236)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:980)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1852)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
	at io.nutz.nutzsite.MainLauncher.init(MainLauncher.java:105)
	at io.nutz.nutzsite.MainLauncher$FM$init$03c3ea108be5279726a1b85aa30183e2.invoke(MainLauncher.java)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:181)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
	... 18 more

打包成了war 运行不行

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