我知道关于这个问题还有其他问题,但没有一个解决方案对我有用.我正在使用maven在eclipse中构建一个java项目,我在src/main/resource/META_INF文件夹中有我的persistence.xml文件.但是当我尝试安装mvn时,我总是得到这个错误:
No Persistence provider for EntityManager named plasma.persistence
Run Code Online (Sandbox Code Playgroud)
通过控制台输出查看它似乎是由此引起的:
[org.hibernate.jpa.boot.internal.PersistenceXmlParser] - HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Run Code Online (Sandbox Code Playgroud)
这是我的persistence.xml文件:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="plasma.persistence" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432:xxxxx"/>
<property name="hibernate.connection.username" value="xxxxx"/>
<property name="hibernate.connection.password" value="xxxxx"/>
<property name="hibernate.connection.pool_size" value="5"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.max_fetch_depth" value="5"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
我试图右键单击项目并将META_INF文件夹添加到构建路径,但它仍然无效.有任何想法吗?
这是一个普遍的问题,但我有一些类,我想定义一些二进制"操作",并有几种不同的方法这样做.例如,假设我有一个Vector我想要实现添加操作的类.一方面,我可能只是重载'+'操作符,但我从一些消息来源读到这不是一个非常好的做法(这就要求人们问为什么这是一个语言特性).在很多情况下,我可以看到为什么方法比操作符重载更可取,但是向量添加被广泛认同,因此使用'+'应该是非常自然的.
另一方面,我可以add()在类中定义一个方法.我可以将它定义为普通方法并用于x.add(y)执行x + y,但它不会将自己展示为二元运算符,因此我不确定这是否应该是首选.我也可以将它定义为静态方法Vector.add(x, y).最后,我还可以定义add()为类的朋友函数,它非常(数学上)自然,但在我看来有点违背哲学OOP.我希望能够深入了解哪种方法更适合(以及为什么).
我在 shell 脚本中有一行如下所示:
java -jar "$dir/"*.jar
Run Code Online (Sandbox Code Playgroud)
,因为我只想执行该文件夹中碰巧命名的任何 jar 文件。但这并不像我预期的那样工作。我收到错误消息:
Error: Unable to access jarfile [folder-name]/*.jar
Run Code Online (Sandbox Code Playgroud)
它按字面意思使用“*”字符,而不是进行我想要的替换。我该如何解决?
编辑:它现在正在工作。我只是有错误的文件夹前缀:/对于任何想知道的人,这是正确的方法。