javac

Javac Cross-Compilation with 1.7

a 夏天 提交于 2019-11-30 08:20:21
So guys, I'm trying to play a bit with Javac Cross compilation with Ant and on terminal. Locally and on an integration environment and i'm having the same problem on the very basic problem. I run this in the linux terminal (and also on my cygwin on windows and the cmd): javac -target 1.6 -source 1.7 -bootclasspath /usr/java/jdk1.6.0_27/jre/lib/rt.jar Main.java with Main.java with nothing other than a System.out.println. javac -version ==> javac 1.7.0_11 I'm getting the error message: javac: source release 1.7 requires target release 1.7 I have roughly the same configuration on my local windows

Is it possible to compile class files with the Java 7 SDK which can run on Java 6 JVMs?

旧巷老猫 提交于 2019-11-30 07:58:13
问题 Since the public Java 6 SE JRE is getting closer to it's EOL (Nov '12), I'm considering porting my projects from Java 6 to Java 7. This would'nt be a big deal, if Apple would provide a Java 7 JRE for Mac OS X. But since Apple isn't willing to do so, I still have to support users which only have a Java 6 JRE. Is there a way to compile Java 6 compatible binaries (class files) with the Java 7 javac? Certainly I'm aware that I can't use the new Java 7 features when doing so. Thanks in anticiption

What is sjavac, who is it for and how do I use it?

不打扰是莪最后的温柔 提交于 2019-11-30 07:48:55
There has been some buzz about a tool called sjavac on the OpenJDK mailing lists. Also, there are two related JEPs: JEP 139: Enhance javac to Improve Build Speed and JEP 199: Smart Java Compilation, Phase Two . My questions are: What exactly is the sjavac tool? Who is it intended for? How do I use it? Disclaimer: Self answered question. Just wanted to bring the knowledge of this tool to the StackOverflow community and to create a reference to future sjavac FAQ. What exactly is the sjavac tool? The sjavac tool is an (allegedly smart ) wrapper around javac , developed at Oracle and intended to

Java casting: is the compiler wrong, or is the language spec wrong, or am I wrong?

这一生的挚爱 提交于 2019-11-30 06:54:37
问题 I have been reading the Java Language Spec, 3rd edition, and have found what I think is a discrepancy between the spec and the javac compiler implementation. The same discrepancies exist in the Eclipse compiler. Section 15.16 talks about cast expressions. It says that it should be a compile time error if the argument type cannot be converted to the cast type via casting conversion (section 5.5): It is a compile-time error if the compile-time type of the operand may never be cast to the type

javac: 错误:找不到或无法加载主类 com.sun.tools.javac.Main

余生长醉 提交于 2019-11-30 06:12:07
安装java jdk 有个基本常识 就是安装后要配置 java_home ,path和classpath, 而且安装路径不能有 空格。方法网上多的是,这里变不加赘述。 我在安装的时候出现了一个很难发现的问题(— -)——如题所述。在网上找了 很久,重新设置了很多次路径,电脑也重启了,就是没用。 原因:jdk和jre安装在同一个文件夹,jre覆盖了jdk的jre文件夹(总共两个哦)。 导致jre文件夹消失了一个!!所以安装java的时候要注意选择路径。或者干脆 使用默认路径。 然后path就都不用设置了,因为已经设置过了,除非你么设置或者换了文件夹安装了。 来源: oschina 链接: https://my.oschina.net/u/264056/blog/79374

Do different Java Compilers (where the vendor is different) produce different bytecode

半城伤御伤魂 提交于 2019-11-30 05:31:14
问题 Given the same major version, say Java 7, do different Java Compilers (e.g., Oracle's hotspot, JRockit, or IBM's J9 etc...) compile a given java source code file into the same bytcode? Scanning the Java 7 language spec it would seem that what is being discussed is the semantics of the language and not the transformation of the code into bytecode. This question is not the same as do different major.minor versions for a given vendor produce the same bytecode. That question is already answered

How does javac automatically compile dependencies of a class

别等时光非礼了梦想. 提交于 2019-11-30 05:09:00
Given the following directory structure: /top |--- wrk |--- pkg |--- A.java |--- B.java Assume that the two files A.java and B.java contain the following code, respectively: // Filename: A.java package pkg; class A { B b; } // Filename: B.java package pkg; class B {...} Assuming that the current directory is /top/wrk Why does the command javac -cp . pkg/A.java work successfully even though we have not yet compiled B.java ? Also if the current directory is /top/wrk/pkg then the command javac A.java works. How so? Why does the command javac -cp . pkg/A.java work successfully even though we have

Disabling compile-time dependency checking when compiling Java classes

匆匆过客 提交于 2019-11-30 05:05:20
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 dependencies allows the compiler to tell you if you got some method argument wrong, etc. While nice and

importing external jar files

给你一囗甜甜゛ 提交于 2019-11-30 04:03:46
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! Compiling from the command-line: javac -cp path_to_jar1.jar:path_to_jar2.jar Example.java Running: java -cp .:path_to_jar1.jar:path_to_jar2.jar Example For Windows, use ; as a path-separator (instead of : ). 来源: https://stackoverflow.com/questions/4421730/importing-external-jar-files

Does Java optimize division by powers of two to bitshifting?

回眸只為那壹抹淺笑 提交于 2019-11-30 04:01:03
问题 Does the Java compiler or the JIT compiler optimize divisions or multiplications by a constant power of two down to bitshifting? For example, are the following two statements optimized to be the same? int median = start + (end - start) >>> 1; int median = start + (end - start) / 2; (basically this question but for Java) 回答1: No, the Java compiler doesn't do that, because it can't be sure on what the sign of (end - start) will be. Why does this matter? Bit shifts on negative integers yield a