javac

Issue running java program from batch file, runs fine in IDE

﹥>﹥吖頭↗ 提交于 2019-12-07 15:22:25
问题 I'm doing some basic java homework for a class on my new laptop - issue is, I can't seem to get the program to compile and run from my batch file using the directions the instructor gave me. I've set the Path variable to my JDK inside the Environment Variables settings. My program is a simple shipping program to keep track of shipment information - I have the program working flawlessly in NetBeans (which our instructor advised us to use for developing the code), but he's going to be testing

Do repeating annotations need a public container?

天大地大妈咪最大 提交于 2019-12-07 13:59:56
问题 I noticed a discrepancy between Eclipse's compiler and javac while using repeating annotations. The repeating annotation and its container were in the same package, but the former was declared public, while the latter remained package-private. Eclipse had no problem with the arrangement, even though the repeating annotation was referenced in another package. javac, on the other hand, refused to compile, saying value() in [container] is defined in an inaccessible class or interface My question

Using @Repeatable while mainaining support for Java 7

[亡魂溺海] 提交于 2019-12-07 13:24:08
问题 Java 8 came with support for repeatable annotations through the use of "container" annotations: @Repeatable(FooContainer.class) @interface Foo { String value(); } @interface FooContainer { Foo[] value(); } @Foo("bar") @Foo("baz") public class SomeClass { } I have a library where I want to support Java 7 (or newer). This library makes extensive use of annotations, and would greatly benefit from supporting repeatable annotations. From what I understand, the container annotation works even in

Import-on-demand declaration with subpackages only

喜夏-厌秋 提交于 2019-12-07 10:50:23
问题 Related : How can I compile "import pack.*" with ant/javac, when there are no such classes? Suppose we have the given package structure parent | ---a ---b where the package parent only contains the two subpackges a and b (no class is under the package parent ). The code import parent.* , situated in a package other than parent , compiled with Maven (i.e. javac ) throws a compile-time error. The error is: package parent does not exist I looked into the Java Language Specification about such a

JDK8 type inference issue

风格不统一 提交于 2019-12-07 07:05:02
问题 I'm trying to run the following code which is compiled fine under JDK8 thanks to type inference: public static <A,B> B convert(A a) { return (B) new CB(); } public static void main(String[] args) { CA a = new CA(); CB b = convert(a); //this runs fine List<CB> bl = Arrays.asList(b); //this also runs fine List<CB> bl1 = Arrays.asList(convert(a)); //ClassCastException here } However, running this throws ClassCastException: CB cannot be cast to [Ljava.lang.Object, but the CB b = convert(a) works

How can I see the javac command IntelliJ IDEA uses to compile my code?

孤街浪徒 提交于 2019-12-07 06:13:20
问题 When I write a Java code in IntelliJ IDEA and runs it, IntelliJ compiles the Java file, a class file is extracted and then the class file is run. How can I see the javac command line that IntelliJ runs. I ask it so I can see whether IntelliJ adds some flags to the javac command. 回答1: IntelliJ IDEA doesn't run javac , therefore you can't see the command line. Compiler API is used directly from Java code. If you enable debug logging for build.log file, you may find some more details how the

Javac fails to find symbol when wildcard is used, but works when .java file is manually specified

∥☆過路亽.° 提交于 2019-12-07 04:14:17
问题 When I compile with this compiler code: @echo off javac -d bin -sourcepath src/*.java src/sign/*.java src/Alert.java pause I don't get any errors. but when i compiler with this code @echo off javac -d bin -sourcepath src/*.java src/sign/*.java pause I do get errors the alert.java is the first file 回答1: Have you tried this one Navigate to src directory javac -d ../bin *.java sign/*.java All the required jars and dependencies must be set in class path before compilation or you can use

package java.nio.file does not exist

喜欢而已 提交于 2019-12-07 03:24:09
问题 I'm working out how to compile java from command line at the moment. Here's what I've got: Here's what I've got: /myjava/compile.cmd /myjava/src/a_pack/HelloWorld.java /myjava/src/b_pack/Inner.java /myjava/src/b_pack/Inner2.java /myjava/bin HelloWorld: package a_pack; import b_pack.Inner; import b_back.Inner2; import java.util.ArrayList; import java.util.Iterator; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); Inner myInner = new Inner()

Compile and Run java program in linux with path to the .java file and path to external jars

匆匆过客 提交于 2019-12-07 02:22:28
Yesterday I solved a problem with an answer here on stackoverflow. But I ended up with another problem, I will try to be clear: I have a project folder in the /home/demo/Desktop/xlsToCsv/ directory where inside of it is the java file "xlsToCsv.java" and another directory with the external jars that I need in /home/demo/Desktop/xlsToCsv/jars . Now I need to compile and run my program. Yesterday I ran a command that assumed that I was already inside of /home/demo/Desktop/xlsToCsv/ , and the commands were: javac -cp ".:./jars/*" xlsToCsv.java java -cp ".:./jars/*" xlsToCsv The problem was solved

How are anonymous classes compiled in Java?

冷暖自知 提交于 2019-12-06 18:59:53
问题 I've heard that Java bytecode actually doesn't support any kind of unnamed classes. How does javac translate unnamned classes to named ones? 回答1: It synthesizes a name of the form EnclosingClass$n , where "n" is a counter for anonymous classes in EnclosingClass . Because using $ in identifiers is discouraged, these names should not collide with any user-specified names. 来源: https://stackoverflow.com/questions/5808492/how-are-anonymous-classes-compiled-in-java