javac

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

时间秒杀一切 提交于 2019-12-02 12:33:41
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 and it create the compiled Main.class file inside this directory (situated in the project root): build

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

南楼画角 提交于 2019-12-02 12:00:15
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\"\Java\jdk1.6.0_23\bin\javac.exe" and surrounding the entire path to javac with double quotes but still

Ant Javac and Commandline Javac give different results

╄→гoц情女王★ 提交于 2019-12-02 09:31:19
问题 I have a class that imports some servlet libraries. When I compile it from command-line it is fine. When I use the ant compile task to compile it, it gives the errors that it can't find the servlet libraries in its path. Is that a known/common occurrence? Here is my Ant target: <target name="compile" depends="prepare" description="compile the source" > <echo>=== COMPILE === SRCDIR: ${src}/com/udfr/src/java </echo> <!-- Compile the java code from ${src} into ${build} --> <javac srcdir="${src}

Compiler is creating extra class files with $ in them

两盒软妹~` 提交于 2019-12-02 06:37:29
I'm using Eclipse and I've written a Java application using SWT. When Eclipse compiles my program, it renames my main file into 4 different files like this: MainFile.class MainFile$1.class MainFile$2.class MainFile$3.class When I go to run this program from command line, I get Could not find the main class: MainFile.class. Program will exit. I really don't understand why this is happening. Louis Wasserman The $ classes are for anonymous inner classes and perfectly normal. Could we see the command line you ran? You probably need to write java MainFile instead of java MainFile.class . 来源: https:

Ant Javac and Commandline Javac give different results

早过忘川 提交于 2019-12-02 04:17:19
I have a class that imports some servlet libraries. When I compile it from command-line it is fine. When I use the ant compile task to compile it, it gives the errors that it can't find the servlet libraries in its path. Is that a known/common occurrence? Here is my Ant target: <target name="compile" depends="prepare" description="compile the source" > <echo>=== COMPILE === SRCDIR: ${src}/com/udfr/src/java </echo> <!-- Compile the java code from ${src} into ${build} --> <javac srcdir="${src}/com/udfr/src/java" destdir="${dist}/WEB-INF/classes"/> </target> It's a common occurrence if you don't

How to execute “javac and java commands” from java program?

半城伤御伤魂 提交于 2019-12-02 00:57:21
问题 Is there any way to execute "javac and java commands" from java program? If so,please help me out.... 回答1: Like Runtime.getRuntime().exec("javac ..."); ? 回答2: You can use Runtime.getRuntime.exec() to do this. But there're some common traps that you take care of. This article on "When Runtime.exec() won't" work correctly highlights some of them. 回答3: You can use the ProcessBuilder class ProcessBuilder pb = new ProcessBuilder("javac", "arg1, "arg2"); 回答4: I would suggest using http://docs

Why javac “-source” flag doesn't work?

邮差的信 提交于 2019-12-02 00:21:27
问题 I am testing the javac -source flag and I am a bit confuse about how it is supposed to work. See this code as an example. It is a non-compatible Java5 code as the method isEmpty() is not defined for String in that version of the JDK. public class TestJavac { public static void Main(String args[]) { String pippo = "pippo"; pippo.isEmpty(); } } Trying to compile using: javac -source 5 TestJavac.java Then it works! This sounds weird to me, but maybe there is something that I am ignoring. My JAVA

【javac添加python 列表特性7】解决List各种下标访问的翻译

徘徊边缘 提交于 2019-12-02 00:08:49
在Python式的列表访问中,下标访问有很多种形式,详见: http://ez2learn.com/index.php/python-tutorials/python-tutorials/167-slice 而这些访问一定要用到for循环,如把 List k=[1,2,3,4,5]; System.out.println(k[1:3:2]); //k[1:3:2]的翻译要用到for循环 //所以只能用函数来替换k[1:3:2] 所以就只能把k[1:3:2]替换成:__list_access(k,1,3,2); 那么这就意味着我必须要把__list_access的定义添加到每个类的源代码中。 为了解决这个问题,我在javacParser.java里面,调用了它自己提供的parser,把我自己写的__list_access的定义parse了进去,并且添加到了语法树上面。 这样,在translator中进行转换的时候,就能把k[1:3:2]节点转换成__list_access(k,1,3,2); 另外,对于__list_access的定义,今天晚上还真是写了半天啊。本来以为挺简单的。。。没想到python的list访问规则这么麻烦。最后写出来一份比较简单的代码,希望它没有问题吧: private static java.util.List __list_access(java.util

Which javac.exe is used by ant javac task?

烈酒焚心 提交于 2019-12-01 22:29:45
问题 I am facing one problem. I renamed javac.exe on my machine and noticed that ant javac task still works fine. Does anybody know from where its getting javac.exe? 回答1: Actually, I believe, that by default Ant tries to execute the java compiler class directly with this code: try { Class c = Class.forName ("com.sun.tools.javac.Main"); Object compiler = c.newInstance (); Method compile = c.getMethod ("compile", new Class [] {(new String [] {}).getClass ()}); int result = ((Integer) compile.invoke

Why javac “-source” flag doesn't work?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 22:22:48
I am testing the javac -source flag and I am a bit confuse about how it is supposed to work. See this code as an example. It is a non-compatible Java5 code as the method isEmpty() is not defined for String in that version of the JDK. public class TestJavac { public static void Main(String args[]) { String pippo = "pippo"; pippo.isEmpty(); } } Trying to compile using: javac -source 5 TestJavac.java Then it works! This sounds weird to me, but maybe there is something that I am ignoring. My JAVA_HOME point to a 1.6 JDK . The source option is only for the language level, not for the API (supplied