自己配了一个,发现不行:
Tomcat tomcat = new Tomcat(); String baseDir = "src/main/webapp/";//"src/main/webapp/"; String webPort = "8089"; tomcat.setPort(Integer.valueOf(webPort)); tomcat.addWebapp("/", new File(baseDir).getAbsolutePath()); tomcat.start(); tomcat.getServer().await();
上面代码放在main中在eclipse是可以正常使用, 打包之后命令行下面报错:
( java -Djava.ext.dirs=WEB-INF/lib -cp WEB-INF/classes jf.RunInTomcat)
Dec 27, 2016 10:53:31 AM org.apache.catalina.startup.ContextConfig webConfig 信息: No global web.xml found Dec 27, 2016 10:53:31 AM org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter jfinal java.lang.RuntimeException: Can not create instance of class: jf.DemoConfig at com.jfinal.core.JFinalFilter.createJFinalConfig(JFinalFilter.java:98) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:47) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:269) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:250) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:368) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4193) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4801) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:771) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:275) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:427) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:649) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:302) at jf.RunInTomcat.main(RunInTomcat.java:49) Caused by: java.lang.ClassNotFoundException: jf.DemoConfig at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:260) at com.jfinal.core.JFinalFilter.createJFinalConfig(JFinalFilter.java:96) ... 20 more
项目:JFinal