javac

How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?

梦想的初衷 提交于 2019-11-26 20:45:21
问题 My usage case is compiling generated source files from a java program using the ToolProvider and JavaCompiler classes provided in JDK 6. The source files contain references to classes in the context classloader (it runs in a J2EE container), but not in the system classloader. My understanding is that by default the ToolProvider will create the JavaCompiler instance with the system classloader. Is there a way to specify a classloader for JavaCompiler to use? I tried this approach, modified

javac error: Class names are only accepted if annotation processing is explicitly requested

 ̄綄美尐妖づ 提交于 2019-11-26 20:18:24
I get this error when I compile my java program: error: Class names, 'EnumDevices', are only accepted if annotation processing is explicitly requested 1 error Here is the java code (I'm running this on Ubuntu). import jcuda.CUDA; import jcuda.driver.CUdevprop; import jcuda.driver.types.CUdevice; public class EnumDevices { public static void main(String args[]) { CUDA cuda = new CUDA(true); int count = cuda.getDeviceCount(); System.out.println("Total number of devices: " + count); for (int i = 0; i < count; i++) { CUdevice dev = cuda.getDevice(i); String name = cuda.getDeviceName(dev); System

How do I set -Dfile.encoding within ant's build.xml?

风格不统一 提交于 2019-11-26 19:48:20
问题 I've got java source files with iso-8859-1 encoding. When I run ant , I get "warning: unmappable character for encoding UTF-8". I can avoid this if I run ant -Dfile.encoding=iso-8859-1 or add encoding="ISO-8859-1" to each javac statement. Is there a way to set the property globally within build.xml? <property name="file.encoding" value="ISO-8859-1"> does not work. I know that I can add a foo=ISO-8859-1 property and set encoding="${foo}" to each javac statement, but I'm trying to avoid that.

How to compile a java source file which is encoded as “UTF-8”?

匆匆过客 提交于 2019-11-26 18:57:57
I saved my Java source file specifying it's encoding type as UTF-8 (using Notepad, by default Notepad's encoding type is ANSI) and then I tried to compile it using: javac -encoding "UTF-8" One.java but it gave an error message" One.java:1: illegal character: \65279 ?public class One { ^ 1 error Is there any other way, I can compile this? Here is the source: public class One { public static void main( String[] args ){ System.out.println("HI"); } } Daniel Pryden Your file is being read as UTF-8, otherwise a character with value "65279" could never appear. javac expects your source code to be in

is it possible to disable javac's inlining of static final variables?

老子叫甜甜 提交于 2019-11-26 18:48:55
The Java static compiler (javac) inlines some static final variables and brings the values directly to the constant pool. Consider the following example. Class A defines some constants (public static final variables): public class A { public static final int INT_VALUE = 1000; public static final String STRING_VALUE = "foo"; } Class B uses these constants: public class B { public static void main(String[] args) { int i = A.INT_VALUE; System.out.println(i); String s = A.STRING_VALUE; System.out.println(s); } } When you compile class B, javac gets the values of these constants from class A and

Javac “cannot find symbol”

十年热恋 提交于 2019-11-26 18:30:48
问题 I've the root directory like this : ├── classes └── src └── vehicles ├── Bicycle.java └── BicycleMain.java Bicycle.java package vehicles; public class Bicycle { public int cadence; public int gear; public int speed; public Bicycle(int startCadence, int startSpeed, int startGear) { gear = startGear; cadence = startCadence; speed = startSpeed; } public void setCadence(int newValue) { cadence = newValue; } public void setGear(int newValue) { gear = newValue; } public void setSpeed(int newValue)

Differences between classpath and sourcepath options of javac

守給你的承諾、 提交于 2019-11-26 18:09:10
问题 I read the Sun documentation and a lot of posts on Stack Overflow, but I'm still confused about the differences between the Java compiler options -cp and -sourcepath . Let say I have this directory structure: c:\Java\project1\src (where the Java source files are) c:\Java\project1\bin (where the Java class files will be or already are) Let's also say I have a source file MainClass.java in a package com.mypackage , and that the directory structure is ok in the source folder. I'm in the project1

Would Java inline method(s) during optimization?

牧云@^-^@ 提交于 2019-11-26 17:28:20
问题 I wonder if JVM/javac is smart enough to turn // This line... string a = foo(); string foo() { return bar(); } string bar() { return some-complicated-string computation; } into string a = bar(); Or strip unnecessary call to foo() in release case (because unreachable code): string a = foo(bar()); // bar is the same ... string foo(string b) { if (debug) do-something-with(b); } My feeling is yes for the first example and "not so sure" for the second one, but could anyone give me some pointers

Eclipse/javac disagree on compiling signature with default method collision; who is right?

本小妞迷上赌 提交于 2019-11-26 16:51:07
问题 Here's a simple class that demonstrates the issue: package com.mimvista.debug; public class DefaultCollisionTest { public static interface Interface1 { public String getName(); } public static interface Interface2 { public default String getName() { return "Mr. 2"; }; } public static <X extends Interface1&Interface2> String extractName(X target) { return target.getName(); } } Eclipse (Neon 2) happily compiles this class while javac (JDK 1.8.0_121) spits out the following compile error: $

Running java in package from command line

不羁的心 提交于 2019-11-26 16:37:32
I have read the previously posted questions. Some are vague and none solved my problem so I am forced to ask again. I have two simple classes, package One; import One.Inner.MyFrame; public class test { public static void main(String args[]) { MyFrame f= new MyFrame(); } } And the other class is, package One.Inner; import java.awt.*; import javax.swing.*; public class MyFrame extends JFrame { public MyFrame() { setPreferredSize(new Dimension(400,560)); setVisible(true); } } I am at base folder "basic" in Windows cmd. I compile using basic> javac *.java -d . A folder and subfolder is created. cd