context.xml中SQLite DB的相对路径 [英] Relative path to SQLite DB in context.xml

查看:276
本文介绍了context.xml中SQLite DB的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java Web应用程序的context.xml文件中使用SQLite数据库文件的相对路径?

Is it possible to use a relative path to an SQLite database file in the context.xml file of a Java web application?

目前,我有:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/mywebapp">
    <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000"
        username="myusername" password="mypassword" driverClassName="org.sqlite.JDBC"
        url="jdbc:sqlite://Users/me/NetBeansProjects/MyApp/web/my.db"/>
</Context>

如您所见,Resource标记的url属性当前指定了绝对值my.db的路径但是,我正在与一个小型开发团队一起开展这个项目。我们通过Subversion共享代码,目前,每当我们中的一个人更新我们的项目时,我们都必须手动将上述路径替换为我们计算机的正确路径。

As you can see, the url attribute of the Resource tag currently specifies an absolute path to my.db. However, I am working on this project with a small team of developers as a class project. We are sharing the code through Subversion and currently, every time one of us updates our project, we have to manually replace the above path with the correct path for our computer.

提前致谢。

更新:相对路径似乎与context.xml文件,但是CATALINA_HOME。不幸的是,该目录(Tomcat所在的位置)位于另一个用户的主文件夹(1)中,我可以访问该文件夹:

UPDATE: It appears that relative paths are not relative to the context.xml file, but to CATALINA_HOME. Unfortunately that directory (where Tomcat is located) is in another user's home folder (1) to which I have ony read access:

(1)/ home / myprof / Tomcat / bin /

(2)/home/me/NetBeansProjects/MyApp/web/my.db

(1) /home/myprof/Tomcat/bin/
(2) /home/me/NetBeansProjects/MyApp/web/my.db

我不能包含/我在相对路径,因为,如上所述,此项目将通过svn存储库在多台计算机上运行,​​并且包含项目文件的目录(2)将更改。但是,由于所有帐户都在共享虚拟网络上,因此CATALINA_HOME(1)不会更改。

I cannot include /me in the relative path because, as stated above, this project will run on multiple computers via a svn repository and the directory in which the project files are contained (2) will change. However, since all of the accounts are on a shared virtual network, CATALINA_HOME (1) will not change.

,如何从servlet中的context.xml文件中获取数据库文件my.db的路径?

Also, how can I get the path to the database file my.db from the context.xml file above inside a servlet?

推荐答案

我在此处找到了我的问题的答案。解决方案是获取资源而不是尝试从context.xml文件中解析数据库URL。

I found the answer to my question here. The solution is to get the resource rather than try to parse the database URL out of the context.xml file.

这篇关于context.xml中SQLite DB的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆