javac

Java: specific enums and generic Enum<?> parameters

假如想象 提交于 2019-12-03 14:17:17
I want to pass any enum value to method in utility class and get another enum value of same enum type. Something like this: public class XMLUtils { public static Enum<?> getEnumAttribute(Element element, String name, Enum<?> defaultValue) { if (element.hasAttribute(name)) { String valueName = element.getAttribute(name); // search for value for (Enum<?> value: defaultValue.getClass().getEnumConstants()) if (value.toString().equalsIgnoreCase(valueName)) return value; } // not found, return default value return defaultValue; } } Use of method getEnumAttribute() : // simple enum public enum

How can I build a jar for a previous Java version?

不羁岁月 提交于 2019-12-03 13:36:48
问题 I am trying to compile my code and run it on a different server. The problem is my JRE version is Java version "1.6.0_13" and that on the server is Java version "1.4.2". This gives me "unrecognized class file version" exception when I try to run the jar on the server. I cannot compile my code on the server because of various dependencies I will have to set up. So I need to know if there is a way to "use Eclipse" [this is easier than command line since it takes care of dependencies] and

Specifying the Eclipse compiler completely from _within_ build.xml

北慕城南 提交于 2019-12-03 12:59:46
问题 As an experiment we want to build our products using the Eclipse java compiler (ecj-3.5.jar downloaded from eclipse.org) on the runtime version of Java 6 instead of the JDK, and as I understand it, it is a matter of adding this jar to the ant classpath, and setting the build.compiler property to point to the adapter. By including <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" /> in my build.xml and invoking ant with a JRE, I get the expected error that the

Is there a Java library to generate class files from an AST?

﹥>﹥吖頭↗ 提交于 2019-12-03 12:58:07
This page describes how I can use the code generator in javac to generate code given that I can build an AST (using a separate parser which I wrote). The technique involves editing javac's source code to basically bypass the Java parser, so that one could supply his/her own AST to the code generator. This could work, but I was hoping to do it in a slightly cleaner way. I want to include the code generating part of javac as a library in my project so I can use it to generate code, without bringing with it the rest of javac's source. Is there a way to do this with javac, or is there perhaps a

“package javax.inject does not exist” error while compiling with javac in commandline

青春壹個敷衍的年華 提交于 2019-12-03 11:33:34
I'm making my first steps toward learning JSF. I found this interesting book called "Core JavaServer Faces Third Edition". Trying to compile the first example, you can download the source code from: http://horstmann.com/corejsf/ . When I type the following on the command-line javac UserBean.java I get errors: package javax.inject does not exist package javax.enterprise.context doe not exist I have downloaded Java EE, Ant and GlassFish. Here is a snap of my command-line: C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf>javac UserBean.java UserBean.java:4: error: package

javac complains: cannot find symbol on enum implementing interface

巧了我就是萌 提交于 2019-12-03 10:32:32
I have three java types as defined below: Main.java: import java.util.Arrays; import java.util.List; public class Main { private Object callFunction() { OperationDefinitions func = OperationDefinitions.CONCATENATE; List<Object> values = Arrays.asList(new Object[] {"ABC", "-", "DEF"}); return func.call (values); } public static void main (String[] args) { Main main = new Main(); System.out.println (main.callFunction()); } } Operation.java import java.util.List; public interface Operation { abstract Object call(List<Object> params); } OperationDefinitions.java import java.util.List; enum

Compiling and running java application using powershell

╄→尐↘猪︶ㄣ 提交于 2019-12-03 10:14:28
问题 I am trying to compile and a sample Helloworld.java file. I have my jdk installed in C:\Program Files\jdk1.7\bin. And I have my Helloworld.java in C:\Helloworld.java I am actually a novice in both powershell and java. I got some examples from web regarding this but many of them advice to run it like this: java.exe -classpath $Env:CLASSPATH C:\Helloworld.java But when I give this in powershell I get an error called 'CLASSPATH' is not defined even after adding it in env variables. And when I

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

前提是你 提交于 2019-12-03 09:45:20
问题 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

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

痞子三分冷 提交于 2019-12-03 08:58:49
问题 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 [

How to see the compiler output when running javac through an Ant task?

久未见 提交于 2019-12-03 08:37:45
问题 Is there any clearly explained and simple way to see the compiler output when running javac through an Ant task? Here is my javac Ant tag: <javac srcdir="${myproject.src}" destdir="${myproject.class}"> <!-- ... --> </javac> Here is the only error message I get: /path/to/build.xml:42: Compile failed; see the compiler error output for details. The problem is that I don't know how to see the compiler error output for details ... Few configuration elements that may help: Ant 1.6.5 Windows 7 x64