Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error compiling Java file with special characters in class name

Tags:

java

javac

I am encountering an issue compiling a source file with a special character in the class name. The class file compiles fine in the Eclipse IDE, but not from javac. I believe I need to leverage the -encoding flag, but haven't hit the right setting yet. I would appreciate any pointers:

File Name: DeptView和SDO.java

Java Source:

public interface DeptView\u548cSDO {

   public int getDeptno();

   public void setDeptno(int value);

}

Error Message:

Running javac *.java results in the following error message:

javac: file not found: DeptView?SDO.java

UPDATE

  • I am currently trying the compile at a Windows XP command prompt
  • Ultimately this compile will need to be part of an ant build, an run on different operating systems
  • I work on the tool that is producing this generated source file.
like image 692
bdoughan Avatar asked May 13 '11 15:05

bdoughan


People also ask

Can Java class names have special characters?

A class name is an identifier—a series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) that does not begin with a digit and does not contain spaces. Some valid identifiers are Welcome1 , $value , _value , m_inputField1 and button7 .

How do I recompile a Java file?

Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\. Type 'javac MyFirstJavaProgram. java' and press enter to compile your code.

What is Javac Javap?

javac : The compiler for the Java programming language. javah : C header and stub generator. Used to write native methods. javap : Class file disassembler.


1 Answers

One solution is to list the file name of each compilation unit in a separate file, say files, and pass @files as a command-line argument to javac. Otherwise, you will have to set the locale of your shell, so that it is using the correct character encoding.

like image 54
Nathan Ryan Avatar answered Oct 15 '22 06:10

Nathan Ryan