Java:openjdk: error: Student is abstract; cannot be instantiated;java编译环境
文章目录
- 编译环境
- jdk
- openjdk
- 错误代码
- 小心
- javac -verbos
编译环境
jdk
需要安装的javac 在java-devel 包里
[root@10 ~]# rpm -qf /usr/bin/javac
file /usr/bin/javac is not owned by any package
[root@10 ~]# ll /usr/bin/javac
lrwxrwxrwx. 1 root root 23 Jun 15 09:52 /usr/bin/javac -> /etc/alternatives/javac
[root@10 ~]# ll /etc/alternatives/javac
lrwxrwxrwx. 1 root root 32 Jun 15 16:51 /etc/alternatives/javac -> /usr/java/jdk-18.0.1.1/bin/javac
[root@10 ~]# rpm -qf /usr/java/jdk-18.0.1.1/bin/javac
jdk-18-18.0.1.1-ga.x86_64
[root@10 ~]# rpm -qi jdk-18-18.0.1.1-ga.x86_64
Name : jdk-18
Epoch : 2000
Version : 18.0.1.1
Release : ga
Architecture: x86_64
Install Date: Wed 15 Jun 2022 04:51:53 PM EDT
Group : Development/Tools
Size : 318287114
License : https://java.com/freeuselicense
Signature : RSA/SHA256, Mon 25 Apr 2022 04:56:36 PM EDT, Key ID 72f97b74ec551f03
Source RPM : jdk-18-18.0.1.1-ga.src.rpm
Build Date : Mon 25 Apr 2022 04:55:52 PM EDT
Build Host : java.com
Relocations : /usr/java
Vendor : Oracle Corporation
URL : http://www.oracle.com/technetwork/java/javase/overview/index.html
Summary : Java Platform Standard Edition Development Kit
Description :
The Java Platform Standard Edition Development Kit (JDK) includes both
the runtime environment (Java virtual machine, the Java platform classes
and supporting files) and development tools (compilers, debuggers,
tool libraries and other tools).
[root@10 ~]#
openjdk
[root@10 ~]# rpm -ql grep java-1.8.0-openjdk-devel-1.8.0.332.b09-2.el8_6.x86_64 | grep javac
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/bin/javac
[root@10 ~]# rpm -qa | grep java
tzdata-java-2022a-1.el8.noarch
java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64
java-1.8.0-openjdk-headless-1.8.0.332.b09-2.el8_6.x86_64
javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch
java-1.8.0-openjdk-devel-1.8.0.332.b09-2.el8_6.x86_64
[root@10 ~]# rpm -qi java-1.8.0-openjdk-devel-1.8.0.332.b09-2.el8_6.x86_64
Name : java-1.8.0-openjdk-devel
Epoch : 1
Version : 1.8.0.332.b09
Release : 2.el8_6
Architecture: x86_64
Install Date: Wed 15 Jun 2022 09:52:45 AM EDT
Group : Development/Tools
Size : 42599147
License : ASL 1.1 and ASL 2.0 and BSD and BSD with advertising and GPL+ and GPLv2 and GPLv2 with exceptions and IJG and LGPLv2+ and MIT and MPLv2.0 and Publ ic Domain and W3C and zlib
Signature : RSA/SHA256, Sun 15 May 2022 01:38:09 PM EDT, Key ID 15af5dac6d745a 60
Source RPM : java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.src.rpm
Build Date : Sun 15 May 2022 01:03:19 PM EDT
Build Host : ord1-prod-x86build002.svc.aws.rockylinux.org
Relocations : (not relocatable)
Packager : infrastructure@rockylinux.org
Vendor : Rocky
URL : http://openjdk.java.net/
Summary : OpenJDK 8 Development Environment
Description :
The OpenJDK 8 development tools.
错误代码
这个抽象的类,或者接口类不能实例化。
[root@10 ~]# cat b.java
// Your First Programabstract class Student{
}class HelloWorld {public static void main(String[] args) {System.out.println("Hello, World!");Student a = new Student();}
}
src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
90 # 0: symbol
91 compiler.err.abstract.cant.be.instantiated=
92 {0} is abstract; cannot be instantiated
小心
如果当前目录之前编译过 student类,就会生成Student.class 文件。
即使当你删除了 java文件里的Student类定义,javac还是会去找 Student.class文件来不足符号找不到的问题。
javac -verbos
显示编译过程信息
[root@10 ~]# javac -verbose b.java
[parsing started RegularFileObject[b.java]]
[parsing completed 114ms]
[search path for source files: .]
[search path for class files: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/resources.jar,/usr/li
b/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/rt.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8
6.x86_64/jre/lib/sunrsasign.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/jsse.jar,/usr/lib/
jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/jce.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8
6.x86_64/jre/lib/charsets.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/jfr.jar,/usr/lib/jvm/
java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/classes,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64
/jre/lib/ext/cldrdata.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/ext/dnsns.jar,/usr/lib/jv
m/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/ext/jaccess.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-
2.el8_6.x86_64/jre/lib/ext/localedata.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/ext/nasho
rn.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/ext/sunec.jar,/usr/lib/jvm/java-1.8.0-openjd
k-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/ext/sunjce_provider.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86
_64/jre/lib/ext/sunpkcs11.jar,/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/lib/ext/zipfs.jar,.]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/String.class)]]
[checking HelloWorld]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/io/Serializable.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/AutoCloseable.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Byte.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Character.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Short.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Long.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Float.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Integer.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Double.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Boolean.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Void.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/System.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/io/PrintStream.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Appendable.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/io/Closeable.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/io/FilterOutputStream.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/io/OutputStream.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/io/Flushable.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/Comparable.class)]]
[loading ZipFileIndexFileObject[/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/lib/ct.sym(META-INF/sym/rt.
jar/java/lang/CharSequence.class)]]
[loading RegularFileObject[./Student.class]]
b.java:4: error: Student is abstract; cannot be instantiated
Student a = new Student();
^
[total 739ms]