javac

Run ant task in different jvm

一个人想着一个人 提交于 2019-11-27 21:52:45
问题 Our ant build is run using Java 1.7.0 for JAVA_HOME. This way javac and all other Java dependent targets use the correct Java by default. But 1 ant target from an external supplier does not support (or rather has a bug) using Java 1.7.0. And unlike e.g. javac or a forked junit, this target does not support parameters to switch jvm. Is it possible to run a specific ant target in a different jvm? 回答1: To make Jeanne Boyarsky's suggestion of using the exec Ant task concrete, the following

How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 21:39:06
My usage case is compiling generated source files from a java program using the ToolProvider and JavaCompiler classes provided in JDK 6. The source files contain references to classes in the context classloader (it runs in a J2EE container), but not in the system classloader. My understanding is that by default the ToolProvider will create the JavaCompiler instance with the system classloader. Is there a way to specify a classloader for JavaCompiler to use? I tried this approach, modified from something on IBM DeveloperWorks: FileManagerImpl fm = new FileManagerImpl(compiler

Differences in type inference JDK8 javac/Eclipse Luna?

怎甘沉沦 提交于 2019-11-27 19:21:36
问题 I'm trying to switch a project to Java8, and encounter odd differences between Eclipse Luna and javac's type inference. With JDK 1.7.0_65 javac this code compiles just fine. JDK 1.8.0_11 complains that both toString(char[]) and toString(Throwable) match for the "toString(getKey(code, null));" line. Eclipse Luna 4.4 (I20140606-1215) compiles it happily with either JDK: public class TypeInferenceTest { public static String toString(Object obj) { return ""; } public static String toString(char[]

How do I set -Dfile.encoding within ant's build.xml?

自古美人都是妖i 提交于 2019-11-27 19:15:33
I've got java source files with iso-8859-1 encoding. When I run ant , I get "warning: unmappable character for encoding UTF-8". I can avoid this if I run ant -Dfile.encoding=iso-8859-1 or add encoding="ISO-8859-1" to each javac statement. Is there a way to set the property globally within build.xml? <property name="file.encoding" value="ISO-8859-1"> does not work. I know that I can add a foo=ISO-8859-1 property and set encoding="${foo}" to each javac statement, but I'm trying to avoid that. A few options: add -Dfile.encoding=iso-8859-1 to your ANT_OPTS environment variable use <presetdef> to

How to tell eclipse to add-exports when compiling

房东的猫 提交于 2019-11-27 18:50:35
问题 Is it possible to tell eclipse to add the following command line option: --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED when compiling. I think it may also be needed when running tests. Is it also possible to remove this message: Note that I tried to add those to the VM options of one of my unit tests but that did not work. 回答1: Go to Project > Properties: Java Build Path , tab Libraries Select the JRE > Is modular node and click Edit... Go to the tab Details In the Added

How can I set my Cygwin PATH to find javac?

坚强是说给别人听的谎言 提交于 2019-11-27 18:20:31
I have a Windows 7 system on which I have installed the latest Java compiler. I also have the latest Cygwin. I want to use the Java compiler from Cygwin's shell. I edited the PATH variable in Cygwin as follows: export PATH=$PATH:"/cygdrive/C/Program\ Files/Java/jdk1.6.0_23/bin/" I can see the javac binary in the above directory, however when I try to compile my *.java file I get: javac command not found Am I doing something wrong in setting the PATH variable like this? Do I have to do something else? I am new to Java and not very familiar with cygwin. as you write the it with double-quotes,

Illegal forward reference error for static final fields

北城余情 提交于 2019-11-27 17:48:29
问题 I'm trying to compile a Java class which javac rejects with an illegal forward reference error, where the offending reference is lexically after the referenced field. The following class is stripped down as much as possible while showing the same behavior: java.util.concurrent.Callable and the many uses of Object are just used as placeholders to remove irrelevant pieces of code. public class Test { static final Object foo = method(new java.util.concurrent.Callable<Object>() { @Override public

Java generics compile in Eclipse, but not in javac

余生长醉 提交于 2019-11-27 17:36:02
问题 I had to discover I have Java code in my project, which compiles and runs fine in Eclipse, but throws a compilation error in javac. A self-contained snippet: import java.util.HashSet; import java.util.Set; public class Main { public static void main(String[] args) { Set<Integer> setOfInts = new HashSet<Integer>(); Set<Object> setOfObjects = covariantSet(setOfInts); } public static <S, T extends S> Set<S> covariantSet(Set<T> set) { return new HashSet<S>(set); } } Compilation in javac returns:

How to add -Xlint:unchecked to my Android Gradle based project?

拟墨画扇 提交于 2019-11-27 16:50:01
I tried to add the following to the root build.gradle file: subprojects { gradle.projectsEvaluated { tasks.withType(Compile) { options.compilerArgs << "-Xlint:unchecked -Xlint:deprecation" } } } But I'm getting this: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':Libraries:ActionBarSherlock:compileRelease'. > invalid flag: -Xlint:unchecked -Xlint:deprecation What am I doing wrong? Felipe Lima This is what worked for me: (in your project's build.gradle) allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint

Java generics code compiles with javac, fails with Eclipse Helios

我的未来我决定 提交于 2019-11-27 16:39:25
问题 I have the following test class that uses generics to overload a method. It works when compiled with javac and fails to compile in Eclipse Helios. My java version is 1.6.0_21. All the articles I read indicate that Eclipse is right and this code should not work. However when compiled with javac and run, the right method is selected. How is this possible? Thanks! import java.util.ArrayList; public class Test { public static void main (String [] args) { Test t = new Test(); ArrayList<String> ss