javac @<opiton_file> and encoding

有些话、适合烂在心里 提交于 2019-12-11 05:11:12

问题


I'm trying to compile some java files on my computer under Windows 7 in french; and I thing I have some trouble with file endoding...

In a first step, I'm generating a list of the file to compile:

dir src\*.java /B/S > javasrc.tmp~

Which will wrote in the file "javasrc.tmp~" line by line the full path of java file (recursivly) of the directory src. In my case I have :

C:\Users\Alexandre\Développement\Java\src\testA.java
C:\Users\Alexandre\Développement\Java\src\testB.java
[...]

(Note that there is an accentued letter into my full path)

In a second step, I compile all the source file with the following command:

"%JAVA_HOME%\bin\javac.exe" @javasrc.tmp~

And I get this error:

javac: file not found: C:\Users\Alexandre\Développement\Java\src\testA.java

When opening my javasrc.tmp~ file in Notepad++ the file is displayed as:

C:\Users\Alexandre\D,veloppement\Java\src\testA.java
C:\Users\Alexandre\D,veloppement\Java\src\testB.java
[...]

The accentued letter is display as a comma; and I have to select OEM 863 file encoding to display the content of the file correctly.

So how to solve my problem? (I'm using these commands as an automated process in a bat file).

Thank you.


回答1:


The best way would be to change to ant or maven, instead of bat files. It's more standard and also more portable.

A basic ant file would be named build.xml and look something like this:

<project name="My Project Name Here" basedir="." default="main">

<property name="lib.dir" value="lib"/>

<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

<property name="src.dir" value="src"/>

<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>

<property name="main-class" value="My Main Class Name Here"/>

<target name="clean">
<delete dir="${build.dir}"/>
</target>

<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>

<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>

<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
<arg value="RIMM" />
</java>
</target>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>

</project>


来源:https://stackoverflow.com/questions/14217779/javac-opiton-file-and-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!