javac

Why is javac 1.5 running so slowly compared with the Eclipse compiler?

自古美人都是妖i 提交于 2019-12-03 00:19:03
I have a Java Maven project with about 800 source files (some generated by javacc/JTB) which is taking a good 25 minutes to compile with javac. When I changed my pom.xml over to use the Eclipse compiler, it takes about 30 seconds to compile. Any suggestions as to why javac (1.5) is running so slowly? (I don't want to switch over to the Eclipse compiler permanently, as the plugin for Maven seems more than a little buggy.) I have a test case which easily reproduces the problem. The following code generates a number of source files in the default package. If you try to compile ImplementingClass

Compiling (javac) a UTF8 encoded Java source code with a BOM

廉价感情. 提交于 2019-12-02 23:06:19
Hello and thank you for reading my post. My problem is the following: I want to compile a Java source file with "javac" with this file being UTF-8 encoded with a BOM (the OS is WinXP). Below is what I do: 1) Create a file with "Notepad" and choose the UTF-8 encoding dos> notepad Test.java "File -> Save as..." File name : Test.java Save as type: All Files Encoding : UTF-8 Save 2) Create a Java class in that file and saved the file like in 1) public class Test { public static void main(String [] args) { System.out.println("This is a test."); } } 3) Visualize the hexadecimal version of the file

Why does the Java Compiler copy finally blocks?

五迷三道 提交于 2019-12-02 22:19:00
When compiling the following code with a simple try/finally block, the Java Compiler produces the output below (viewed in the ASM Bytecode Viewer): Code: try { System.out.println("Attempting to divide by zero..."); System.out.println(1 / 0); } finally { System.out.println("Finally..."); } Bytecode: TRYCATCHBLOCK L0 L1 L1 L0 LINENUMBER 10 L0 GETSTATIC java/lang/System.out : Ljava/io/PrintStream; LDC "Attempting to divide by zero..." INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V L2 LINENUMBER 11 L2 GETSTATIC java/lang/System.out : Ljava/io/PrintStream; ICONST_1 ICONST_0 IDIV

Cannot run simple compiled java program?

亡梦爱人 提交于 2019-12-02 20:51:14
问题 I am on Arch Linux, I just installed JRE and JDK and all the proper bin files (javac and java) are in /opt/java/bin/ I simply compiled a standard hello world, and compiled it with javac running javac ./hello.java and that made a class. Now my problem is running it. I run java ./helloworld.class and it gives me an error, even if the file I point java to is non-existant: Exception in thread "main" java.lang.NoClassDefFoundError: //helloworld/class Caused by: java.lang.ClassNotFoundException: .

Why if I try to execute a class containing the main() method from within its package I obtain an error message?

ε祈祈猫儿з 提交于 2019-12-02 20:17:55
问题 I have a Main class containing the main() method declared into a package named mainPkg . Now I use an ANT script to perform the compilation with Javac, this tartget: <target name="compile" depends="clean"> <mkdir dir="build/classes"/> <echo>INTO compile TASK</echo> <echo>BASE DIR: ${basedir}</echo> <echo>CLASSPATH: ${basedir}\lib\ojdbc6.jar</echo> <javac srcdir="src/mainPkg/" destdir="build/classes"> <classpath> <fileset refid="classpath.compile"/> </classpath> </javac> </target> Ok it works

setting the correct classpath for compiling and running Java packages? [duplicate]

主宰稳场 提交于 2019-12-02 19:17:51
问题 This question already has an answer here : getting error when I compile the Java code using package in commandline? (1 answer) Closed 5 years ago . I have been using Eclipse lately, where compiling and running the program is very simple. Not much needs to be done in setting the classpath . But apparently that is not the case when it comes to running them from commandLine . when I try compiling from terminal , I am having various errors. I am pasting an image of my package structure of the

How to compile and run a java class with a package

允我心安 提交于 2019-12-02 17:56:07
问题 I have a class called MyClass in the file MyClass.java file (code mentioned below) package myclass; class MyClass { public int add (int a, int b){ return a+b; } public static void main(String args[]) { MyClass obj = new MyClass(); System.out.println(oobj.add(2, 3)); } } I am compiling the class with javac MyClass.java But I am trying to run the class using java MyClass or java myclass.MyClass I am getting the Error Error: Could not find or load main class MyClass But, I am able to run this

Setup Java 6 annotation processing configuration for eclipse compiler with maven

杀马特。学长 韩版系。学妹 提交于 2019-12-02 16:48:43
What's the best way to setup the eclipse project compiler configuration for Java 6 annotation processors? My solution is to setup the org.eclipse.jdt.apt.core.prefs and factorypath files manually. This is a bit cumbersome: Reference the processor jar in the factorypath file Configure the eclipse annotation processor output directory (org.eclipse.jdt.apt.genSrcDir property in org.eclipse.jdt.apt.core.prefs ) Add the eclipse annotation processor output directory as source folder One problem is that eclipse generated sources will be compiled with maven. Only maven clean compile is reliable as it

Can't execute javac or other command line applications in Java using ProcessBuilder under Windows 7

亡梦爱人 提交于 2019-12-02 16:38:18
问题 I'm trying to execute javac from Java using ProcessBuilder but i get no output and nothing happens. I tried reading the input stream (as there is a bug where the process hangs if i don't read it) but still no results. I originally passed all required parameters to javac but it was not working, so i simplified it down to just javac (which should print the help message). i tried running "C:\Windows\System32\cmd.exe /c C:\\"Program Files\"\Java\jdk1.6.0_23\bin\javac.exe" "C:\\"Program Files\"

What is the difference between using javac and javax.tools.JavaCompiler?

余生颓废 提交于 2019-12-02 16:37:34
Maven Compiler Plugin documentation states : The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse And indeed when forceJavacCompilerUse is not specified in our build there are some build errors, for example when the code references the com.sun. packages (legacy, we know that its a bad idea...) What are other differences between these two compile modes in