javac

Can I use JAVAC to compile a project with multiple files and directories?

百般思念 提交于 2019-11-29 07:02:53
I'm working on a very large project that has associated class files in multiple directories, all stemming from the root dir \src. I'm trying to compile a file in src\solution\ (called Console.java) that uses imports from other directories in the src, which are still uncompiled. So if I want to compile Console.java outside of an IDE, how do I go about doing that? Oh yeah, I also have some external JARs which need to be included in the build. Thanks! I appreciate it! I would look at using Ant to create a build script. It's a little bit of work now but it'll pay off over the lifetime of your

Reference to the final field from lambda expression

帅比萌擦擦* 提交于 2019-11-29 06:18:57
Recently I've found a subtle difference between anonymous class and lambda expression: public class FinalTest { final Runnable x = new Runnable() { @Override public void run() { System.out.println(x.hashCode()); } }; final Runnable y = () -> System.out.println(y.hashCode()); } Usually lambdas are equivalent to the anonymous classes. Even my Eclipse IDE has the refactoring to convert the x to lambda (it becomes exactly like y ) and convert y to anonymous class (it becomes exactly like x ). However the lambda gives me a compilation error while anonymous class can be perfectly compiled. The error

Illegal forward reference error for static final fields

◇◆丶佛笑我妖孽 提交于 2019-11-29 03:45:33
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 Object call() throws Exception { return bar; } }); static final Object bar = foo; static Object method

Java generics compile in Eclipse, but not in javac

不想你离开。 提交于 2019-11-29 03:26:06
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: Main.java:10: incompatible types found : java.util.Set<java.lang.Integer> required: java.util.Set<java

Disabling compile-time dependency checking when compiling Java classes

那年仲夏 提交于 2019-11-29 02:51:15
问题 Consider the following two Java classes: a.) class Test { void foo(Object foobar) { } } b.) class Test { void foo(pkg.not.in.classpath.FooBar foobar) { } } Furthermore, assume that pkg.not.in.classpath.FooBar is not found in the classpath. The first class will compile fine using the standard javac. However, the second class won't compile and javac will give you the error message "package pkg.not.in.classpath does not exist" . The error message is nice in the general case since checking your

Run ant task in different jvm

白昼怎懂夜的黑 提交于 2019-11-29 02:26:36
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? Christopher Peisert To make Jeanne Boyarsky's suggestion of using the exec Ant task concrete, the following example wraps the exec task in a macro to simplify calling targets with various JVMs. Notice

Java8, how discover the class and method name in visitMethodInvocation?

谁都会走 提交于 2019-11-29 00:43:40
With Java7 and Java8, I would like to generate a warning if some methods was called. The warning will be print if a specific jar is present when then user compile. I write an Annotation Processor and catch the visitMethodInvocation(). Now, I want extract the class and method names will be invoked. Is it possible to do that ? Or how to approach this? You can do something like: package mystuff; import com.sun.source.tree.*; import com.sun.source.util.*; import java.util.*; import javax.annotation.processing.*; import javax.lang.model.element.*; import javax.tools.*; @SupportedAnnotationTypes("*"

How to tell ant to build using a specific javac executable?

偶尔善良 提交于 2019-11-28 23:27:15
How can I tell ant to use a specific javac executable from the command line? I have an installation of gcj, built as part of gcc, within a library we distribute, and I'd like to have a particular piece of Java software built against that. However, it just seems to use the system-gcc, and options such as "-Dbuild.compiler" seem to want me to specify some kind of Java class rather than a filepath. I was hoping for something similar to CC in Makefiles. I'm sure it's something really simple, and I'm just being stupid. To be clear, I'd like to avoid editing the build file myself if possible. Is

What is annotation processing in Java?

荒凉一梦 提交于 2019-11-28 23:26:06
Quoting, Sun's Official Java Tutorial Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested What does it mean? And how to apply it? Arne Deutsch "Annotation Processing" is a hook into the compile process of the java compiler, to analyse the source code for user defined annotations and handle then (by producing compiler errors, compiler warning, emitting source code, byte code ...). API reference: http://java.sun.com/javase/6/docs/api/javax/annotation/processing/package-summary.html From the very next line of the page that you refer to: Class names,

Troubleshoot slow compilation

萝らか妹 提交于 2019-11-28 23:15:04
What should I do to investigate and troubleshoot a slow compilation problem ? My project has about 100 classes and takes more than 45 seconds to compile, which seems very slow to me. As a reference, I have another project with 50 classes that compiles in 3 seconds. ps: I use maven as a build tool. It takes maven ~50 seconds to compile ( mvn clean compile ), of which 45 seconds are spent running javac (confirmed by running with the -X option). increasing the amount of memory did not help ( -Xms500m ) I can give more info about my project but it is fairly standard so I'm not sure what