java 包 org.hibernate 不存在 import org.hibernate.*

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26131991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:20:14  来源:igfitidea点击:

package org.hibernate does not exist import org.hibernate.*

javahibernate

提问by user3397694

I have downloaded Hibernate package and copied hibernate3.jarfile and other jars files to my classpath. That is, C:\Program Files\Java\hibernate-distribution-3.6.4.Finalin my computer.

我已经下载了 Hibernate 包并将hibernate3.jar文件和其他jars 文件复制到我的类路径中。也就是说,C:\Program Files\Java\hibernate-distribution-3.6.4.Final在我的电脑中。

My Java code:

我的Java代码:

import org.hibernate.*;    
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class HibernateTestDriver    
{
    public static void main(String[] args)
    {
        Configuration cfg = new Configuration(); 
        cfg.addResource("hello/Message.hbm.xml"); 
        cfg.setProperties( System.getProperties() );
        SessionFactory sessions = cfg.buildSessionFactory();
        // Session session = getSessionFactory().openSession();
        Session session = sessions.openSession();
        Transaction tx = session.beginTransaction();
        Message message = new Message("Hello World");
        session.save(message);
    }
}

When I compile it below error comes:

当我编译它时出现以下错误:

"..: package org.hibernate does not exist import org.hibernate.*;

回答by user12722

When you compile, you need to include the Hibernate jar in your classpath. Just putting the directory is not enough. You can do this by adding arguments to the javac command:

编译时,您需要在类路径中包含 Hibernate jar。仅仅放置目录是不够的。您可以通过向 javac 命令添加参数来完成此操作:

javac -cp "C:\Program Files\Java\hibernate-distribution-3.6.4.Final\hibernate3.jar" HibernateTestDriver.java

You can also set the CLASSPATH environment variable to include it.

您还可以设置 CLASSPATH 环境变量以包含它。

If you are using an IDE, you should set the project so it includes the Hibernate jar in the classpath.

如果您使用的是 IDE,您应该设置项目,使其在类路径中包含 Hibernate jar。

回答by Raj Sharma

if you are using Jboss, add the Jboss lib in classpath.

如果您使用的是 Jboss,请在类路径中添加 Jboss 库。

if using maven include jboss lib in build classpath, else add as dependency in maven with scope provided.

如果使用 maven 在构建类路径中包含 jboss lib,则在提供范围的 maven 中添加为依赖项。

回答by Mike Laren

Try ranaming the file hibernate3.jar to hibernate3.zip and extract the contents. The classes provided by that JAR file will be in the com/hibernate/ folder. If you don't see a com/hibernate folder then you must be using the wrong JAR or you might need to add more JARs to your classpath.

尝试将文件 hibernate3.jar 命名为 hibernate3.zip 并提取内容。该 JAR 文件提供的类将位于 com/hibernate/ 文件夹中。如果您没有看到 com/hibernate 文件夹,那么您一定使用了错误的 JAR,或者您可能需要将更多 JAR 添加到您的类路径中。

回答by Uma Kolandai

I had to add the jars individually to the compile time libraries as jar files not as libraries. Weird. I am using Netbeans.

我不得不将 jars 作为 jar 文件而不是库单独添加到编译时库中。奇怪的。我正在使用 Netbeans。

This method did not resolve the issue.. javac -cp "C:\Program Files\Java\hibernate-distribution-3.6.4.Final\hibernate3.jar" HibernateTestDriver.java

这个方法没有解决问题.. javac -cp "C:\Program Files\Java\hibernate-distribution-3.6.4.Final\hibernate3.jar" HibernateTestDriver.java