javac

Why do lambdas in Java 8 disallow forward reference to member variables where anonymous classes don't?

情到浓时终转凉″ 提交于 2019-11-27 04:25:19
问题 The following class contains a member variable runnable which is initialized with an instance of an anonymous inner class. The inner class references the same member: class Example { Runnable runnable = new Runnable() { @Override public void run() { System.out.println(runnable); } }; } This is not a problem as long as the method is not executed before the member has been assigned and the JLS allows such a reference. The declaration of the member variable could theoretically be converted to a

How can I set my Cygwin PATH to find javac?

半世苍凉 提交于 2019-11-27 04:16:17
问题 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

ToolProvider.getSystemJavaCompiler() returns null - usable with only JRE installed?

蹲街弑〆低调 提交于 2019-11-27 03:46:31
问题 I am trying to use the JavaCompiler class: http://docs.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html When I call ToolProvider.getSystemJavaCompiler() it returns null. I think this is because I'm using a JRE instead of a JDK. The problem is I want it to run on all platforms regardless of weather the user is using a JRE or a JDK. If anyone knows how to fix this, or an alternative method to use please comment. Any help would be appreciated. 回答1: ToolProvider.getSystemJavaCompiler()

javac “cannot find symbol” error with command line

蓝咒 提交于 2019-11-27 03:17:29
问题 I have two classes Owning and OwningAccessor. The files are in the same directory. public class Owning { String _name = ""; public void printBanner() { } public void printOwning(double amount) { printBanner(); //print details System.out.println("name:" + _name); System.out.println("amount:" + amount); } } public class OwningAccessor { public void access() { Owning o = new Owning(); o.printOwning(500); } } When I tried to compile OwningAccessor with javac -cp . OwningAccessor.java , I got

How do I compile a java file that has jar dependencies?

早过忘川 提交于 2019-11-27 03:10:00
问题 I have a helper lib that I wrote to sit on top of Apache Commons, and when I try to javac it (so that I can make it into a jar) it complains, quite reasonably, that it has no idea what I'm talking about when I make reference to the stuff that's in the commons.jar. How does one include a jar so as that javac can compile? 回答1: For windows: javac -cp ".;/dir/commons.jar;/dir/more_jar_files.jar" MyClass.java For unix or mac (thanks for the tip Dawood): javac -cp ".:/dir/commons.jar:/dir/more_jar

Workaround for javac compilation order bug in maven

廉价感情. 提交于 2019-11-27 02:36:52
问题 I'm encountering a bug in the Java compiler where the order of files submitted for compilation can cause code not to compile. I've drilled down the code to isolate the smallest amount of code I could to reproduce the problem, resulting in three source files (1 class each). public interface ActionSpec { public abstract int run(String param); } public enum Actions implements ActionSpec { SKIP { public int run(String d) { return 0; } }; } public class Program { public static void main(String[]

Error:java: invalid source release: 8 in Intellij. What does it mean?

狂风中的少年 提交于 2019-11-27 02:33:18
Im trying to compile some code in I'm using Intellij Ultimate 13.1.4, but I get the following error and I have no idea what it means: Information:Using javac 1.7.0_55 to compile java sources Information:java: Errors occurred while compiling module 'Example' Information:Compilation completed with 1 error and 0 warnings in 3 sec Information:1 error Information:0 warnings Error:java: invalid source release: 8 My guess is that its something related to Java 8 vs Java 7, but I have no idea what specifically. I've tried to Google around for this message, but they either talk about javac or target

try with resources introduce unreachable bytecode

自古美人都是妖i 提交于 2019-11-27 02:04:18
Is it possible that javac generates unreachable bytecode for the following procedure? public void ex06(String name) throws Exception { File config = new File(name); try (FileOutputStream fos = new FileOutputStream(config); PrintWriter writer = new PrintWriter(new OutputStreamWriter( fos , "rw"))) { bar(); } } When I look into the exception table of the bytecode (javap -v) there are the following entries that look strange: 43 48 86 Class java/lang/Throwable 43 48 95 any and 21 135 170 Class java/lang/Throwable 21 135 179 any Now the problem is that some code is only reachable if the exceptions

How can I suppress javac warnings about deprecated api?

佐手、 提交于 2019-11-27 01:44:31
问题 When I compile, javac outputs: Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details.` I wish to suppress this warning. Trying -Xlint:none does not seem to help. 回答1: From what I can tell in the docs, you can't do it on the command-line. According to the javac documentation, -Xlint:none only disables warnings "not mandated by the Java Language Specification". It appears that warning you of the use of deprecated APIs is managed by the

Javac: Treat warnings as errors

半腔热情 提交于 2019-11-27 01:39:12
I have an Ant file that compiles my program. I want the javac task to fail if any warning was reported by the compiler. Any clue on how to do that? Michael Myers Use the -Werror flag. It's not listed in the -help output, but it works. I found it through this blog entry and tested on my own code (in NetBeans with Ant). The output was: MyClass.java:38: warning: [serial] serializable class MyClass has no definition of serialVersionUID public class MyClass extends JComponent { 1 warning BUILD FAILED (total time: 3 seconds) Note that this is Java 6 only, though. Edit : Example of specifying this in