<分区>
我创建了一个 java 库程序并将其作为 .jar 文件用于另一个 java 程序。我的 IDE 是 NetBeans。我通过命令行尝试了相同的概念,但出现以下错误:
class file has wrong version 52.0, should be 50.0 Please remove or make sure it appears in the correct sub directory of the class path. import Demo1_Lib.Test1; ^
这是我的步骤。
第 1 步:在 NetBeans IDE 中创建了以下类库。
package Demo1_Lib;
/**
*
* @author tveluppillai
*/
public class Test1
{
public void print()
{
System.out.println("hello");
}
}
第 2 步: 在 netbeans 上创建一个 java 项目并添加 jar 文件。 (Test1.jar) 并使用类库函数。
package test2;
import Demo1_Lib.Test1;
/**
*
* @author tveluppillai
*/
public class Test2
{
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
Test1 obj = new Test1();
obj.print();
}
}
这编译得很好,当我运行时,它在 NetBeans 中为我提供了正确的输出
但是,当我使用命令提示符做同样的事情时,我得到了错误。
我使用下面的命令来编译和运行它。
javac -cp C:\\Demo_Lib\\Test\\Test1.jar Test2.java
我收到以下错误:
class file has wrong version 52.0, should be 50.0 Please remove or make sure it appears in the correct sub directory of the class path. import Demo1_Lib.Test1; ^
我错过了什么?