请问有人解释使用javac时出了什么问题。因为这个类是用Eclipse编译成功的。我给出了以下CLI命令:
pardus@adige:/mylinuz/pocws/src/test/swing/component$ javac -verbose SortButtonRenderer.java
[parsing started SortButtonRenderer.java]
[parsing completed 12ms]
[search path for source files: .]
[search path for class files: /usr/lib/jvm/java-6-oracle/jre/lib/resources.jar,/usr/lib/jvm/java-6-oracle/jre/lib/rt.jar,/usr/lib/jvm/java-6-oracle/jre/lib/sunrsasign.jar,/usr/lib/jvm/java-6-oracle/jre/lib/jsse.jar,/usr/lib/jvm/java-6-oracle/jre/lib/jce.jar,/usr/lib/jvm/java-6-oracle/jre/lib/charsets.jar,/usr/lib/jvm/java-6-oracle/jre/lib/modules/jdk.boot.jar,/usr/lib/jvm/java-6-oracle/jre/classes,/usr/lib/jvm/java-6-oracle/jre/lib/ext/dnsns.jar,/usr/lib/jvm/java-6-oracle/jre/lib/ext/sunpkcs11.jar,/usr/lib/jvm/java-6-oracle/jre/lib/ext/localedata.jar,/usr/lib/jvm/java-6-oracle/jre/lib/ext/sunjce_provider.jar,.]
[loading java/awt/Component.class(java/awt:Component.class)]
[loading javax/swing/JLabel.class(javax/swing:JLabel.class)]
[loading javax/swing/JTable.class(javax/swing:JTable.class)]
SortButtonRenderer.java:8: package sun.swing.table does not exist
import sun.swing.table.DefaultTableCellHeaderRenderer;
^
SortButtonRenderer.java:10: cannot find symbol
symbol: class DefaultTableCellHeaderRenderer
public class SortButtonRenderer extends DefaultTableCellHeaderRenderer {
^
[loading java/lang/Object.class(java/lang:Object.class)]
[checking test.swing.component.SortButtonRenderer]
SortButtonRenderer.java:17: cannot find symbol
symbol : variable super
location: class test.swing.component.SortButtonRenderer
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
^
[loading javax/swing/JComponent.class(javax/swing:JComponent.class)]
[loading java/awt/Container.class(java/awt:Container.class)]
[loading java/awt/image/ImageObserver.class(java/awt/image:ImageObserver.class)]
[loading java/awt/MenuContainer.class(java/awt:MenuContainer.class)]
[loading java/io/Serializable.class(java/io:Serializable.class)]
[loading javax/swing/TransferHandler.class(javax/swing:TransferHandler.class)]
[loading javax/swing/TransferHandler$HasGetTransferHandler.class(javax/swing:TransferHandler$HasGetTransferHandler.class)]
[loading javax/swing/SwingConstants.class(javax/swing:SwingConstants.class)]
[loading javax/accessibility/Accessible.class(javax/accessibility:Accessible.class)]
SortButtonRenderer.java:19: cannot find symbol
symbol : method setHorizontalAlignment(int)
location: class test.swing.component.SortButtonRenderer
setHorizontalAlignment(JLabel.CENTER);
^
[loading java/lang/String.class(java/lang:String.class)]
SortButtonRenderer.java:20: cannot find symbol
symbol : method setText(java.lang.String)
location: class test.swing.component.SortButtonRenderer
setText((value == null) ? "" : value.toString());
^
SortButtonRenderer.java:21: incompatible types
found : test.swing.component.SortButtonRenderer
required: java.awt.Component
return this;
^
[total 297ms]
6 errors
有趣的是,rt.jar
中提供了缺少的类 sun.swing.table.DefaultTableCellHeaderRenderer ,并且编译器可以加载其他类,例如 java / awt / Color来自rt.jar
的.class 。
package test.swing.component;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import sun.swing.table.DefaultTableCellHeaderRenderer;
public class SortButtonRenderer extends DefaultTableCellHeaderRenderer {
private static final long serialVersionUID = 1L;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
return this;
}
//other methods removed
}
请注意:当我运行java8时,javac仍然会发生错误。但java8的javac与" endorseddirs / usr / lib / jvm / java-6-oracle / jre / lib"没关系。
答案 0 :(得分:0)
您确定命令行和eclipse javac运行相同的版本吗? (关闭内存但选项 - >搜索javac应该显示哪个编译器)和javac -version将在命令行上为您提供正确的版本。
编辑:是的,绝对摆脱了太阳。*进口!它们只会导致更多痛苦。答案 1 :(得分:0)
如果你需要保留一个 sun.* 类并且正在使用 maven 打包,请将此配置添加到 maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>