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
10
votes
1 answer

importing external jar files

I have written a Java code which imports an external jar file. How can I compile and run it on the command-line? Thanks in advance!
Pavithra Gunasekara
  • 3,902
  • 8
  • 36
  • 46
10
votes
4 answers

How can I build a jar for a previous Java version?

I am trying to compile my code and run it on a different server. The problem is my JRE version is Java version "1.6.0_13" and that on the server is Java version "1.4.2". This gives me "unrecognized class file version" exception when I try to run the…
codeObserver
  • 6,521
  • 16
  • 76
  • 121
10
votes
3 answers

Unreachable statement: while true vs if true

How should I understand this Java compiler behaviour? while (true) return; System.out.println("I love Java"); // Err: unreachable statement if (true) return; System.out.println("I hate Java"); // OK. Thanks. EDIT: I find out the point after a few…
marek094
  • 424
  • 2
  • 11
10
votes
3 answers

java compiler's target version "jsr14" with JDK7/8

Can anybody tell me the jsr14 target option of javac will be still available with JDK7/8? Say, $ javac -source 1.5 -target jsr14 Hello.java
Jin Kwon
  • 2,005
  • 3
  • 15
  • 15
10
votes
3 answers

Java Compilation Speed

I have a Java project with ~2400 classes. They are mostly generated using XJC from XML schema with a few extensions. Compilation takes very long time, ~20 minutes, and I was wondering if there's anything I can do to improve this? A similar project…
klafbang
  • 355
  • 2
  • 4
  • 14
10
votes
2 answers

Strange generics behaviour. Being erased early?

I ran into some strange behaviour of Java generics today. The following code compiles fine and works as you would expect: import java.util.*; public class TestGeneric { public static void main(String[] args) { GenericClass
joel_s
  • 158
  • 1
  • 9
10
votes
3 answers

javac: invalid target release: 1.7

Using OS X Mavericks, and after upgrading my JDK, I can no longer compile with ant. I've done the usual googling and the vast majority of answers point to JAVA_HOME not being set. Help me stackoverflow, you're my only hope! Information which may be…
davedave
  • 241
  • 1
  • 2
  • 9
10
votes
4 answers

compiling only part of the source tree with ant

Say I have my sources in my src/ tree (and possibly in my test/ tree). Say I would like to compile only part of that tree. The reasons why I might want to do that are various. Just as an example, I might want to create the smallest possible jar…
Davide
  • 17,098
  • 11
  • 52
  • 68
10
votes
2 answers

javac.exe AST programmatic access example

Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could you provide an example?
hawkeye
  • 34,745
  • 30
  • 150
  • 304
10
votes
4 answers

javac cannot be run, and furthermore does not seem installed

I have a problem involving setting up Java. I have installed the JRE, added its path to PATH, and set JAVA_HOME and CLASSPATH. Now, java and javacpl work fine, but running javac generates a command-not-found error. Furthermore, javac.exe does not…
Irina Matveeva
  • 127
  • 1
  • 3
  • 8
10
votes
4 answers

(JAVA) Use Command Prompt to create .jar file from multiple .class files

I have written a .java file, called Main.java, and have compiled it using the javac in the Windows Command Prompt. The compiler is creating multiple .class files (called Main.class, Main$1.class, & Main$2.class--presumably because I have anonymous…
Skyler
  • 2,834
  • 5
  • 22
  • 34
10
votes
3 answers

Java 8 compiler error - how to get more information?

I played around with Java 8 ea b72, but I get a compiler error. Is there a way to get more information from javac, e.g. the file list it is currently working on? If I had a general idea where to look I might be able to find a work-around until the…
Landei
  • 54,104
  • 13
  • 100
  • 195
10
votes
5 answers

Java generics with wildcard compile in Eclipse, but not in javac

As a follow up to Java generics compile in Eclipse, but not in javac, I post another snippet which compiles and runs fine in Eclipse, but raises a compilation error in javac. (This prevents the project the snippet is extracted from, from being build…
mtsz
  • 2,725
  • 7
  • 28
  • 41
9
votes
4 answers

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

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…
Monster
  • 1,573
  • 6
  • 23
  • 35
9
votes
6 answers

Covariant Return Type in Interface not compiling via Javac

I have the following structure: public interface BarReturn {} public interface FooReturn {} public interface FooBarReturn extends FooReturn, BarReturn {} public interface Foo { FooReturn fooBar( ); } public interface Bar { BarReturn…