[英]IntelliJ: Why can't I use a class from external jar
When I created the jar file I wrote the following java file: 创建jar文件时,我编写了以下Java文件:
package myjar;
public class MyClass {
public static void hello() {
System.out.println("hello");
}
public static void main(String[] args) {
MyClass.hello();
}
}
Now, I took the jar file and added it to Project Structure. 现在,我将jar文件添加到Project Structure中。 The name of the jar is 'myjar':
罐子的名称是“ myjar”:
and in the IDE I wrote "import myjar.MyClass" and the word 'myjar' was marked in red. 在IDE中,我写了“ import myjar.MyClass”,单词“ myjar”标记为红色。
When I use 'MyClass.hello()' in the project, I get an error: 当我在项目中使用'MyClass.hello()'时,出现错误:
no main manifest
没有主要表现
Do you know what I can to to load it successfully ? 你知道我能成功加载它吗?
You can only import some classes from your libraries on classpath into a Java source file, not a contents of a whole Java archive (JAR) file. 您只能将类路径中的库中的某些类导入Java源文件中,而不能导入整个Java归档(JAR)文件的内容。 So if you have inside myjar.jar file class Foo.class inside package (folder) bar, you can do
因此,如果您在包(文件夹)栏中的myjar.jar文件类Foo.class里面,可以
import bar.Foo;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.