gpt4 book ai didi

java - Maven hibernate

转载 作者:行者123 更新时间:2023-11-30 04:51:57 25 4
gpt4 key购买 nike

您好,我正在关注本教程:http://www.mastertheboss.com/hibernate/182-hibernate-tutorial.html

我已经完成了所有代码,因此我添加了以下运行配置:包 -e -DgroupId=it.michelepierri -DartifactId=FirstExampleHibernate

这是我的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.michele</groupId>
<artifactId>FirstExampleHibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FirstExampleHibernate</name>
<description>Primo esempio di utilizzo Hibernate</description>

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core<!--or hibernate-core--></artifactId>
<version>3.3.2.GA</version>
<type>pom</type>
<!--hibernate-dependencies is a pom, not needed for hibernate-core -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.4.GA</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>it.michele.TestPerson</mainClass>
<packageName>it.michele</packageName>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

所以我运行它,控制台告诉我:

    -------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ FirstExampleHibernate ---
[INFO] Building jar: C:\Users\Michele\workspace\FirstExampleHibernate\target\FirstExampleHibernate-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.707s
[INFO] Finished at: Sun Mar 11 14:59:50 CET 2012
[INFO] Final Memory: 5M/77M
[INFO] ------------------------------------------------------------------------

当我尝试启动我返回的 jar 时:

C:\Users\Michele\workspace\FirstExampleHibernate\target>java -jar 

FirstExampleHibernate-0.0.1-SNAPSH
OT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/Session
Caused by: java.lang.ClassNotFoundException: org.hibernate.Session
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: it.michelepierri.TestPerson. Program will exit.

我做错了什么??????在 TestPerson.java 类中有 public static void main(String[] args) 方法。

谢谢。

最佳答案

您遇到问题是因为类路径中未指定所有支持 jar(hibernate 等)。

尝试

mvn exec:java -Dexec.mainClass=it.michelepierri.TestPerson

这是一个 Maven 命令,它将在内部调用 java,并将所有依赖的 jar 添加到类路径中。

你也可以尝试

mvn assembly:single

这会将所有 jar 合并成一个,然后您可以按照现在的方式运行它。

关于java - Maven hibernate ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9655590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com