Questions tagged [javac]

javac is the primary Java compiler, included in the Java Development Kit (JDK) from Sun Microsystems (now Oracle), and also in versions from other vendors.

javac is the primary Java compiler, included in the Java Development Kit (JDK) from Sun Microsystems (now Oracle), and also in versions from other vendors.

The compiler accepts source code conforming to the Java language specification (JLS) and produces bytecode conforming to the Java Virtual Machine Specification (JVMS). javac is itself written in Java. The compiler can also be invoked programmatically.

2467 questions
12
votes
2 answers

How can I get the source line number in error stack trace of a jar created by ant build?

I am using ant to build a jar of my project in eclipse. I deploy that jar on tomcat. But whenever an exception happen in my code (which is inside jar), the error stack trace comes but the line number does not come -- instead it says unknown…
Ranger
  • 435
  • 1
  • 4
  • 19
12
votes
2 answers

This code compiles using ecj but not javac. Is this a bug in ecj, javac or neither?

The following code creates a Collector that produces an UnmodifiableSortedSet: package com.stackoverflow; import java.util.Collections; import java.util.SortedSet; import java.util.TreeSet; import java.util.stream.Collector; import…
Robert Bain
  • 9,113
  • 8
  • 44
  • 63
12
votes
1 answer

Timing how long each file takes to compile with ant

Occasionally a slight modification to a Java source file like some additional explicit casts to help the compiler can improve compile time from 4 minutes to 3 seconds for a single java file (Especially in Java 8). The problem is: In a large java…
clinux
  • 2,984
  • 2
  • 23
  • 26
12
votes
2 answers

How to patch OpenJDK 9 with Jigsaw integrated?

Before Jigsaw it was quite easy to replace one or several classes in OpenJDK (to perform some test or make a contribution). I could copy an original file from OpenJDK source, for example, java/util/ArrayList.java into src/java/util/, add any changes…
Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
12
votes
4 answers

Set Java compiler compliance level

I need to compile a Java program on the command line, and I am trying to set the compiler level to a lower one (1.6). I tried like this but it didn't work: javac -1.6 Hello.java
georgiana_e
  • 1,809
  • 10
  • 35
  • 54
12
votes
2 answers

Two java files, in same directory, one accessing the others class/s?

I am trying to grant one .java file access to the class in another .java file. I would like to do this on the command line. For example how would I do this using the two files below? File: "ToImport.java" package ABC; public class ToImport { …
Evan Sevy
  • 659
  • 1
  • 13
  • 25
12
votes
2 answers

Javac vs Java within -classpath option

What is the difference in calling the -classpath option from javac and from java for example: javac -classpath MyJar.jar GetJar.java java -classpath MyJar.jar:. GetJar it works as well as: javac -classpath MyJar.jar GetJar.java java GetJar So…
Rollerball
  • 12,618
  • 23
  • 92
  • 161
12
votes
3 answers

"package javax.inject does not exist" error while compiling with javac in commandline

I'm making my first steps toward learning JSF. I found this interesting book called "Core JavaServer Faces Third Edition". Trying to compile the first example, you can download the source code from: http://horstmann.com/corejsf/. When I type the…
Shikatsu
  • 197
  • 1
  • 1
  • 13
11
votes
2 answers

how to set the use --enable-preview compile and run flags from gradle?

Looking to use records from Java 14 in a gradle build, but am getting: thufir@dur:~/NetBeansProjects/FileWatcherHandler$ thufir@dur:~/NetBeansProjects/FileWatcherHandler$ gradle clean build > Task :compileJava…
Thufir
  • 8,216
  • 28
  • 125
  • 273
11
votes
1 answer

Operator '+' cannot be applied to Object and String

The following code: void someMethod(Object value) { String suffix = getSuffix(); if (suffix != null) value += suffix; [...] } compiles without errors in JDK 8 (using -source 1.6), but fails in JDK 6 with the error…
Grodriguez
  • 21,501
  • 10
  • 63
  • 107
11
votes
5 answers

Static context in enum definition

The syntax sugar provided by Java's enum facility can sometimes be a little confusing. Consider this example, which does not compile: public enum TestEnum { FOO("foo") { public void foo() { helper(); // <- compiler error …
Jonik
  • 80,077
  • 70
  • 264
  • 372
11
votes
2 answers

How to tell eclipse to add-exports when compiling

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…
Luke
  • 884
  • 8
  • 21
11
votes
1 answer

Error when collecting IntStream to map

The following code String[] values = ... .... Map map = new HashMap<>(); for (int i = 0; i < values.length; i++) { map.put("X" + i, values[i]); } is converted by IntelliJ to: Map map = IntStream.range(0,…
msayag
  • 8,407
  • 4
  • 30
  • 29
11
votes
2 answers

trying to capture javac output in bash shell

I'm trying to redirect the java compiler output to a file. I thought it's supposed to be: javac file.java > log.txt or something. Instead, I see all the output on the terminal and nothing in log.txt! Also, if I want to log errors too, do I…
jcee14
  • 908
  • 3
  • 15
  • 28
11
votes
1 answer

Reference to the final field from lambda expression

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()); …
Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334