Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何设置可移植的persistence.xml文件?_Java_Maven_Jpa_H2 - Fatal编程技术网

Java 如何设置可移植的persistence.xml文件?

Java 如何设置可移植的persistence.xml文件?,java,maven,jpa,h2,Java,Maven,Jpa,H2,我正在构建一个使用h2数据库的应用程序,我的persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jc

我正在构建一个使用
h2
数据库的应用程序,我的
persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="taskUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.github.tarrsalah.jersey.todo.app.model.Task</class>
        <properties>          
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:/home/tarrsalah/src/github.com/tarrsalah/jaxrs-todo-app/target/todo"/>
            <property name="javax.persistence.jdbc.user" value=""/>
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.password" value=""/>
        </properties>
    </persistence-unit>
</persistence>

org.eclipse.persistence.jpa.PersistenceProvider
com.github.tarrsalah.jersey.todo.app.model.Task
如您所见,我在
javax.persistence.jdbc.url
属性中有一个指向本地
h2
数据库的硬链接,我想在github上共享我的代码

如何在不更改
persistence.xml
配置文件的情况下使代码的克隆版本正常工作


PS:我正在使用flyway进行数据库迁移)

要与其他人共享此代码,您可以尝试使用内存h2数据库

<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=1000"/>


flyway迁移如何?AFAIK flyway迁移在h2内存数据库中工作。请看这里@Shailendar迁移使用maven flyway插件成功,但eclipseLink似乎找不到它(我使用的是相同的URL)。我必须使用java API进行迁移,感谢您建议使用内存选项。