javac

Compiling multiple packages using the command line in Java

旧巷老猫 提交于 2019-11-27 08:43:34
Hi i have been using an IDE but now I need to run and compile from the command line. The problem is that I have multiple packages and I have tried to find the answer but nothing has worked. So I have src/ Support/ (.java files) Me/ (.java files) Wrapers/ (.java files) Do you know how to compile everything with javac? This should do it (may require additional classpath elements via the -cp command line switch): javac Support/*.java Me/*.java Wrapers/*.java But if your build process gets more complex (and it will!), you should look into using Apache Ant for build automation. You should use build

How can I compile and run a Java class in a different directory?

拈花ヽ惹草 提交于 2019-11-27 07:48:21
I'm writing a makefile that compiles a .java file in a different directory, and then I want to run it, without changing directories. I want to do something along the lines of: $(SQM_JAVA_TOOL_DONE) : $(SQM_JAVA_TOOL) $(shell cd /home_dir) javac myjavafile.java java myjavafile where the Java file is /home/myjavafile.java , and the makefile isn't running from /home . How can I do this? I might be misunderstanding the question, but you can compile with javac /home/MyJavaFile.java This will create MyJavaFile.class in /home You can then run it by including /home on the classpath. e.g. java -cp

How to configure Eclipse to compile using Oracle javac 1.7.0_09?

本秂侑毒 提交于 2019-11-27 06:53:57
问题 I am trying to compile following piece of code: public class DuplicateMainExample { public static void main(String[] args) { System.out.print("A1"); } public static void main(String... args) { System.out.print("A2"); } } In Eclipse it's working fine, but with warnings on the both methods - " Duplicate method main(String[]) in type DuplicateMainExample " Using javac (java version "1.7.0_09") I have an compilation error: >javac DuplicateMainExample.java DuplicateMainExample.java:8: error:

Drawbacks of javac -parameters flag

£可爱£侵袭症+ 提交于 2019-11-27 06:44:07
问题 I want to try some frameworks features that required names of parameter in runtime, so I need to compile my app with -parameters and it will store the names of parameter in JVM byte code. Which drawbacks except the size of jar/war exist of this parameter usage? 回答1: The addition of parameter names to the class file format is covered by JEP 118, which was delivered in Java 8. There was a little bit of discussion about why inclusion of parameter names was made optional in OpenJDK email threads

what's the difference between -source and -target compatibility?

别等时光非礼了梦想. 提交于 2019-11-27 05:32:59
问题 When using the Java compiler ( javac ), we can specify two kinds of compatibility. One is using -source and the other is using -target . What is the difference between these two? For example, -source 1.5 and -target 1.6 ? Also, is there any case where we use a different source and target compatibility level? 回答1: From the javac docs: -source Specifies the version of source code accepted. -target Generate class files that target a specified version of the VM. Class files will run on the

Size of Initialisation string in java

断了今生、忘了曾经 提交于 2019-11-27 05:08:49
Apparently there is a limit to the size of an initialisation string in javac. Can anyone help me in identifying what the maximum limit is please? Thank you edit: We are building an initialisation string which will look something like this "{1,2,3,4,5,6,7,8......}" but with 10,000 numbers ideally. When we do this for a 1000 it works, 10,000 throws an error saying code too large for try statement. To produce this we are using a stringbuilder and looping over an array appending the values. Apparently it is a limitation in javac. We have been told that we could rebuild the array in the method we

Why does array[idx++]+=“a” increase idx once in Java 8 but twice in Java 9 and 10?

纵然是瞬间 提交于 2019-11-27 04:55:20
问题 For a challenge, a fellow code golfer wrote the following code: import java.util.*; public class Main { public static void main(String[] args) { int size = 3; String[] array = new String[size]; Arrays.fill(array, ""); for(int i = 0; i <= 100; ) { array[i++%size] += i + " "; } for(String element: array) { System.out.println(element); } } } When running this code in Java 8, we get the following result: 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94

Suppress javac warning “…is internal proprietary API and may be removed in a future release”

风格不统一 提交于 2019-11-27 04:44:15
When I compile the Spring JDBC source on OS X with JDK 1.7.0, I get this warning: warning: CachedRowSetImpl is internal proprietary API and may be removed in a future release How do I suppress the warning message during a compile? I already know and use Java's @SuppressWarning annotations. I'm looking for the specific use of this to suppress the warning I've described. My question specifically is, in this line of code: @SuppressWarnings("valuegoeshere") what should "valuegoeshere" be replaced with? EDIT: People, I know that it is best to avoid the code that leads to the warning. And usually

Why does Java compiler allow static variable access through null object? [duplicate]

耗尽温柔 提交于 2019-11-27 04:32:31
问题 This question already has an answer here: How come invoking a (static) method on a null reference doesn't throw NullPointerException? 5 answers I was pointing some tricks and came across this. In following code: public class TestClass1 { static int a = 10; public static void main(String ar[]){ TestClass1 t1 = null ; System.out.println(t1.a); // At this line } } t1 object is null . Why this code is not throwing NullPointerException ? I know this is not proper way to access static variables but

javac source and target options

前提是你 提交于 2019-11-27 04:30:20
I have seen the compile options like discussed in Which JDK's distributions can run `javac -source 1.6 -target 1.5`? . I understand the individual options for source and target. I don't understand why source version is higher that the target version. Compiling the code for older targets makes sense. But in that case, why dont we just use -source of the oldest target we want to be able to run on Peter Tseng source: The version that your source code requires to compile. target: The oldest JRE version you want to support. Be sure to also set bootclasspath to ensure your program will work on older