Properties file not found in classpath: a_little_config.txt JFinal的路径配置问题

在搭建JFinal项目的时候,采用maven+jetty+JFinal的方式,ide为myeclipse。

用jetty启动项目的时候控制台报了如下错误:

WARN 2018-07-13 15:30:27,468 main org.eclipse.jetty.util.component.AbstractLifeCycle - FAILED jfinal: java.lang.IllegalArgumentException: Properties file not found in classpath: a_little_config.txt
java.lang.IllegalArgumentException: Properties file not found in classpath: a_little_config.txt
	at com.jfinal.kit.Prop.<init>(Prop.java:60)
	at com.jfinal.kit.PropKit.use(PropKit.java:61)
	at com.jfinal.kit.PropKit.use(PropKit.java:38)
	at ygkj.wpcm.config.MainConfig.configConstant(MainConfig.java:121)
	at com.jfinal.core.Config.configJFinal(Config.java:50)
	at com.jfinal.core.JFinal.init(JFinal.java:63)
	at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)
	at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
	at org.eclipse.jetty.server.Server.doStart(Server.java:277)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at com.jfinal.server.JettyServer.doStart(JettyServer.java:131)
	at com.jfinal.server.JettyServer.start(JettyServer.java:70)
	at com.jfinal.core.JFinal.start(JFinal.java:157)
	at ygkj.wpcm.config.MainConfig.main(MainConfig.java:64)

观察控制台输出信息后发现时数据库配置的txt文件没有被成功加载,即编译后的配置文件没有被成功加入到编译后的目录,由于笔者的项目是搭载了maven的web项目,所以项目路径会跟传统web项目不大一样,使用的是maven的目录,具体如下:


这里需要确认maven项目编译后的目录为target/classes,在myeclipse的工程树栏里是看不到classes文件夹的,右击target文件夹---myeclipse---open in Explorer,会看到target文件夹下的确存在classes,打开classes文件夹查看编译目录。




然而打开classes文件夹发现下图在resources目录下标记的五个配置文件都没被加载。


这说明在编译的时候出现了问题,具体为resources下的配置文件没有被加入编译后的目录,解决方法:复制这五个配置文件到classes文件夹下并重启项目。

启动成功,结果如下面控制台代码:

Starting JFinal 3.2
Starting scanner at interval of 5 seconds.
Starting web server on port: 80
Pushlet[INFO] Config: loading pushlet.properties from classpath
Pushlet[INFO] Config: loaded values={pull.refresh.wait.max.millis=6000, subscriber.class=nl.justobjects.pushlet.core.Subscriber, session.timeout.mins=5, log.level=4, config.version=1.0.2, sessionmanager.class=nl.justobjects.pushlet.core.SessionManager, queue.size=24, listen.force.pull.all=false, queue.read.timeout.millis=20000, poll.refresh.wait.max.millis=10000, listen.force.pull.agents=safari, pull.refresh.timeout.millis=60000, subscription.class=nl.justobjects.pushlet.core.Subscription, queue.write.timeout.millis=20, logger.class=nl.justobjects.pushlet.util.Log4jLogger, session.class=nl.justobjects.pushlet.core.Session, session.id.generation=randomstring, dispatcher.class=nl.justobjects.pushlet.core.Dispatcher, poll.refresh.wait.min.millis=6000, poll.refresh.timeout.millis=60000, pull.refresh.wait.min.millis=2000, session.id.size=10, controller.class=nl.justobjects.pushlet.core.Controller, sources.activate=true}

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: Logging intialized logger class=class nl.justobjects.pushlet.util.Log4jLogger

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: init() Pushlet Webapp - version=null built=null

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: SessionManager created className=class nl.justobjects.pushlet.core.SessionManager

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: SessionManager: Fri Jul 13 15:44:33 CST 2018 started; interval=60000ms

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: Dispatcher created className=class nl.justobjects.pushlet.core.Dispatcher

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: Dispatcher started

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: EventSourceManager: start

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: Activating 0 EventSources

2018-07-13 15:44:33
[INFO]-[Thread: main]-[nl.justobjects.pushlet.util.Log4jLogger.info()]: EventSources activated
Starting Complete. Welcome To The JFinal World :)
另外,使用了JFinal的传统web项目(未搭载maven,使用tomcat启动),编译后的路径默认为项目根路径下的WebRoot\WEB-INF\classes,对应编译前项目根目录,出现上述问题只需将配置文件复制进WebRoot\WEB-INF\classes目录下即可。


猜你喜欢

转载自blog.csdn.net/weixin_38808487/article/details/81032409