You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@juddi.apache.org by Alex O'Ree <sp...@gmail.com> on 2013/04/07 13:58:37 UTC

Writing to a file from a web app in tomcat

I'm using the following code to read a file in META-INF
  URL prop = application.getResource("/META-INF/config.properties");
        if (prop == null) {
            throw new Exception("Cannot locate the configuration file.");
        }
        session = _session;
        propertiesurl = prop;
        InputStream in = prop.openStream();
        Properties p = new Properties();
        p.load(in);
        in.close();

This works in both tomcat and jboss.

Then later one, I want to be able to save the changes. Using code
similar to this

FileOutputStream fos = new FileOutputStream(new File(propertiesurl.toString()));
        String msg="Edited at " + System.currentTimeMillis() + " by "
+ request.getRemoteUser();
             p.store(fos, msg);
        fos.close();

The propertiesurl.toString() method in tomcat returns a JNDI URL,
which cannot be used using the file io api's. In Jboss, this code
works just fine. Application.getResource returns a file:/// url.

So the question is, how can get the same type of setup in Tomcat?
(write to a file in META-INF)

Re: Writing to a file from a web app in tomcat

Posted by Alex O'Ree <sp...@gmail.com>.
Well adding a database just for the gui is probably excessive. There's
only like 10 settings anyhow. I'll give commons a try

On Sun, Apr 7, 2013 at 8:38 AM, Kurt Stam <ku...@gmail.com> wrote:
> I don't know the answer to that but we are already using commons configuration, which lets you write back to a properties file. So you could try that for your properties file too.
>
> Or use the db?
>
> --K
>
> On Apr 7, 2013, at 7:58, "Alex O'Ree" <sp...@gmail.com> wrote:
>
>> I'm using the following code to read a file in META-INF
>>  URL prop = application.getResource("/META-INF/config.properties");
>>        if (prop == null) {
>>            throw new Exception("Cannot locate the configuration file.");
>>        }
>>        session = _session;
>>        propertiesurl = prop;
>>        InputStream in = prop.openStream();
>>        Properties p = new Properties();
>>        p.load(in);
>>        in.close();
>>
>> This works in both tomcat and jboss.
>>
>> Then later one, I want to be able to save the changes. Using code
>> similar to this
>>
>> FileOutputStream fos = new FileOutputStream(new File(propertiesurl.toString()));
>>        String msg="Edited at " + System.currentTimeMillis() + " by "
>> + request.getRemoteUser();
>>             p.store(fos, msg);
>>        fos.close();
>>
>> The propertiesurl.toString() method in tomcat returns a JNDI URL,
>> which cannot be used using the file io api's. In Jboss, this code
>> works just fine. Application.getResource returns a file:/// url.
>>
>> So the question is, how can get the same type of setup in Tomcat?
>> (write to a file in META-INF)

Re: Writing to a file from a web app in tomcat

Posted by Kurt Stam <ku...@gmail.com>.
I don't know the answer to that but we are already using commons configuration, which lets you write back to a properties file. So you could try that for your properties file too. 

Or use the db?

--K

On Apr 7, 2013, at 7:58, "Alex O'Ree" <sp...@gmail.com> wrote:

> I'm using the following code to read a file in META-INF
>  URL prop = application.getResource("/META-INF/config.properties");
>        if (prop == null) {
>            throw new Exception("Cannot locate the configuration file.");
>        }
>        session = _session;
>        propertiesurl = prop;
>        InputStream in = prop.openStream();
>        Properties p = new Properties();
>        p.load(in);
>        in.close();
> 
> This works in both tomcat and jboss.
> 
> Then later one, I want to be able to save the changes. Using code
> similar to this
> 
> FileOutputStream fos = new FileOutputStream(new File(propertiesurl.toString()));
>        String msg="Edited at " + System.currentTimeMillis() + " by "
> + request.getRemoteUser();
>             p.store(fos, msg);
>        fos.close();
> 
> The propertiesurl.toString() method in tomcat returns a JNDI URL,
> which cannot be used using the file io api's. In Jboss, this code
> works just fine. Application.getResource returns a file:/// url.
> 
> So the question is, how can get the same type of setup in Tomcat?
> (write to a file in META-INF)