java - Write into a properties file from a maven project -
i want write properties file. read properties file. here path properties file in maven
public void setproperty(string coll, string bez) throws urisyntaxexception { file file =null; properties properties = getproperties(); url url = thread.currentthread().getcontextclassloader().getresource("/jsfatwork/messages/test.properties"); url url2 = pageservicebean.class.getresource("/jsfatwork/messages/test.properties"); try { file = new file(url.touri().getpath()); properties.setproperty(bez, coll); system.out.println("ich habe einen wert gesetzt"); properties.store(new fileoutputstream(file), null); system.out.println("die datei wurde gespeichert"); } catch (ioexception ex) { logger.getlogger(pageservicebean.class.getname()).log(level.severe, null, ex); } }
the console output is:
ich habe einen wert gesetzt die datei wurde gespeichert
so think works, after < 5 seconds execption:
warnung: cannot serialize session attribute pageservicebean session 143cd5de1c101e6a30515c585c32c02b java.io.notserializableexception: com.mongodb.dbapilayer @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1183) @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1547) @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1508) @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1431) @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1177) @ java.io.objectoutputstream.writeobject(objectoutputstream.java:347) @ org.apache.catalina.session.standardsession.writeobject(standardsession.java:1671) @ org.apache.catalina.session.standardsession.writeobjectdata(standardsession.java:1077) @ org.apache.catalina.session.standardmanager.dounload(standardmanager.java:432) @ org.apache.catalina.session.standardmanager.unload(standardmanager.java:353) @ org.apache.catalina.session.standardmanager.stopinternal(standardmanager.java:518) @ org.apache.catalina.util.lifecyclebase.stop(lifecyclebase.java:232) @ org.apache.catalina.core.standardcontext.stopinternal(standardcontext.java:5622) @ org.apache.catalina.util.lifecyclebase.stop(lifecyclebase.java:232) @ org.apache.catalina.core.standardcontext.reload(standardcontext.java:3947) @ org.apache.catalina.loader.webapploader.backgroundprocess(webapploader.java:426) @ org.apache.catalina.core.containerbase.backgroundprocess(containerbase.java:1345) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1530) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1540) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1540) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.run(containerbase.java:1519) @ java.lang.thread.run(thread.java:744) ... schwerwiegend: ioexception while loading persisted sessions: java.io.writeabortedexception: writing aborted; java.io.notserializableexception: com.mongodb.dbapilayer java.io.writeabortedexception: writing aborted; java.io.notserializableexception: com.mongodb.dbapilayer @ java.io.objectinputstream.readobject0(objectinputstream.java:1354) @ java.io.objectinputstream.defaultreadfields(objectinputstream.java:1990) @ java.io.objectinputstream.readserialdata(objectinputstream.java:1915) @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1798) @ java.io.objectinputstream.readobject0(objectinputstream.java:1350) @ java.io.objectinputstream.readobject(objectinputstream.java:370) @ org.apache.catalina.session.standardsession.readobject(standardsession.java:1595) @ org.apache.catalina.session.standardsession.readobjectdata(standardsession.java:1060) @ org.apache.catalina.session.standardmanager.doload(standardmanager.java:284) @ org.apache.catalina.session.standardmanager.load(standardmanager.java:204) @ org.apache.catalina.session.standardmanager.startinternal(standardmanager.java:491) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5443) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.standardcontext.reload(standardcontext.java:3954) @ org.apache.catalina.loader.webapploader.backgroundprocess(webapploader.java:426) @ org.apache.catalina.core.containerbase.backgroundprocess(containerbase.java:1345) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1530) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1540) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1540) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.run(containerbase.java:1519) @ java.lang.thread.run(thread.java:744) caused by: java.io.notserializableexception: com.mongodb.dbapilayer @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1183) @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1547) @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1508) @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1431) @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1177) @ java.io.objectoutputstream.writeobject(objectoutputstream.java:347) @ org.apache.catalina.session.standardsession.writeobject(standardsession.java:1671) @ org.apache.catalina.session.standardsession.writeobjectdata(standardsession.java:1077) @ org.apache.catalina.session.standardmanager.dounload(standardmanager.java:432) @ org.apache.catalina.session.standardmanager.unload(standardmanager.java:353) @ org.apache.catalina.session.standardmanager.stopinternal(standardmanager.java:518) @ org.apache.catalina.util.lifecyclebase.stop(lifecyclebase.java:232) @ org.apache.catalina.core.standardcontext.stopinternal(standardcontext.java:5622) @ org.apache.catalina.util.lifecyclebase.stop(lifecyclebase.java:232) @ org.apache.catalina.core.standardcontext.reload(standardcontext.java:3947) ... 7 more
i use mongodb database. @ case write properties file , not database. don't know why java.io.notserializableexception: com.mongodb.dbapilayer
error.
and properties in files not there, once open file after exception.
any idea?
i resolved problem. can't write in propertie file in class path, because in classpath part of war-file on server. , after write data not consistent more. error. solution put propertie file out of classpath. used fileoutputstream
write propertie file , use eclipse home path
path. solution or should use diffrent way write in propertie file?
Comments
Post a Comment