javac

What is the --release flag in the Java 9 compiler?

只愿长相守 提交于 2019-11-27 01:23:11
Java 9's javac has a new flag --release : > javac --help ... --release <release> Compile for a specific VM version. Supported targets: 6, 7, 8, 9 How is it different from -source and -target flags? Is it just a shortcut for -source X -target X ? Li357 Not exactly. JEP 247: Compile for Older Platform Versions defines this new command-line option, --release : We defined a new command-line option, --release , which automatically configures the compiler to produce class files that will link against an implementation of the given platform version. For the platforms predefined in javac , --release N

How to compile java package structures using javac

杀马特。学长 韩版系。学妹 提交于 2019-11-27 01:22:38
问题 I am trying to compile (from the command line) a java package that imports another package of my own. I was following a tutorial online but it seems that I get an error when I try to compile the final java file (CallPackage.java). Here is the file structure: + test_directory (contains CallPackage.java) -> importpackage -> subpackage (contains HelloWorld.java) Here is CallPackage.java: /// CallPackage.java import importpackage.subpackage.*; class CallPackage{ public static void main(String[]

How to run a .class file that is part of a package from cmd?

此生再无相见时 提交于 2019-11-27 01:14:09
问题 I keep getting errors when I make my .class part of a package and try to run it from cmd. Here's the code that works after using javac and then java: class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } and then the code that does not work: package com; class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } giving me this error after trying to run the program via the command: java HelloWorld :

Maven: javac: source release 1.6 requires target release 1.6

本秂侑毒 提交于 2019-11-27 00:44:23
问题 NOTE: This appears to be a limit in the "javac" program. I have Java 6 code that needs to be built for a Java 5 JVM. My previous work with the javac ant target (both with the JDK compiler and with ecj) led me to believe that it would simply be a matter of setting source and target for javac. Hence this pom.xml fragment: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.5<

Is the creation of Java class files deterministic?

为君一笑 提交于 2019-11-27 00:09:02
问题 When using the same JDK (i.e. the same javac executable), are the generated class files always identical? Can there be a difference depending on the operating system or hardware ? Except of the JDK version, could there be any other factors resulting in differences? Are there any compiler options to avoid differences? Is a difference only possibly in theory or does Oracle's javac actually produce different class files for the same input and compiler options? Update 1 I'm interested in the

How to compile and run with this folder structure

被刻印的时光 ゝ 提交于 2019-11-26 23:43:15
问题 I have my java source files in src/net/... folders and .jar files in lib folder. How to compile and run this files with command line without writing build script ? 回答1: Lets say you have your code files in [someDirectory] | +-[lib] | | | +-someLib.jar | +-someOtherLib.jar | +-... | +--[src] | +-[net] | +-[name] | +-[one] | +-[two] | +-[main] | +-Main.java <- code you want to compile and execute then if your console is in someDirectory> you can compile it with someDirectory>javac -cp "lib\*"

Java Access Denied

青春壹個敷衍的年華 提交于 2019-11-26 23:16:59
C:\Program Files (x86)\Java\jdk1.6.0_17\bin>javac VendingMachine.java VendingMachine.java:27: error while writing VendingMachine: VendingMachine.class (Access is denied) public class VendingMachine ^ 1 error Here is the code from my editior from line 27 to 39: public class VendingMachine /*This is line 27*/ { private int itemPrice; private int currentBalance; private int totalCollected; public VendingMachine(int itemCost) { itemPrice = itemCost; } /*line 39*/ I am thinking my problem might be related to Win7 Prof: (Access is denied) How do I resolve this or what do I need to be doing or

Cannot stop ant from generating compiler Sun proprietary API warnings

穿精又带淫゛_ 提交于 2019-11-26 22:01:28
问题 I call javac from my ant script like this: <javac srcdir="src" destdir="build/classes" source="1.6" target="1.6" debug="true" encoding="Cp1252" nowarn="true"> But it still throws compiler warnings in the output: [javac] Compiling 73 source files to C:\IKOfficeRoot\Java\ERP\Framework\build\classes [javac] C:\IKOfficeRoot\Java\ERP\Framework\src\de\ikoffice\util\LoggerFactory.java:49: warning: sun.reflect.Reflection is Sun proprietary API and may be removed in a future release [javac] return

How to run Javac from Eclipse

冷暖自知 提交于 2019-11-26 21:51:47
问题 I'm trying to run 'javac' tool on a compiled .class file in Eclipse. I open External Tools Configuration them fill the filds: Location: C:\Program Files\Java\jdk1.6.0_25\bin\javac.exe Working directory: ${workspace_loc:/Main/bin} Arguments: ? I want to ask you what must I write in the Arguments field, and am I fill* Location * and Working directory: fields right ? 回答1: Launching the javac compiler from within Eclipse can be a very useful feature in some cases (e.g. for testing purposes, to

Why calling method with generic return on a generic class is considered unsafe by javac?

百般思念 提交于 2019-11-26 21:47:16
问题 Consider the following code: public class Main { public static class NormalClass { public Class<Integer> method() { return Integer.class; } } public static class GenericClass<T> { public Class<Integer> method() { return Integer.class; } } public static void main(String... args) { NormalClass safeInstance = new NormalClass(); Class<Integer> safeValue = safeInstance.method(); GenericClass unsafeInstance = new GenericClass(); Class<Integer> unsafeValue = unsafeInstance.method(); } } If I compile