Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Compile a java class from within another java program using tool.jar

Reply
Thread Tools

Compile a java class from within another java program using tool.jar

 
 
Mathias Conradt
Guest
Posts: n/a
 
      09-07-2004
I need to compile a java class from within another java program.

Using
Runtime.getRuntime().exec("javac ...
works fine. But I would like to user the javac class from Sun's
tool.jar directly.

When I try to compile just the same file using the Sun tool.jar:

String arg[] = {"-sourcepath","c:/projects/pm/WEB-INF/src","-d","c:/tmp/pm","c:/path/to/class.java"};
com.sun.tools.javac.Main.main(arg);

it gives me the following short stack trace:
"Error: Can't read <path_to_class.java>"

Any idea what the problem might be? The java class to be compiled is
given as absolute path and exists. I don't think that I have any other
application using the file at the same time. And the path is also
correct.

Mathias
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      09-07-2004
On 6 Sep 2004 17:28:34 -0700, Mathias Conradt wrote:

> "c:/path/to/class.java"


Try..
"C:/path/to/class.java"

If that fails, try Linux.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
 
Mathias Conradt
Guest
Posts: n/a
 
      09-08-2004
Andrew Thompson wrote:
> Try..
> "C:/path/to/class.java"
>
> If that fails, try Linux.


This didn't make any difference, but meanwhile I found the problem.

Runtime.exec accepts a term including a wild card for the java files to
be compiled: /path/to/Some*.java

The compile-Method in tool.jar does not accept a wild card, therefore I
had to list all one by one. But it's working. Fortunately it's just
three files.

Mathias
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-08-2004
On Wed, 08 Sep 2004 23:44:37 +0200, Mathias Conradt wrote:

> The compile-Method in tool.jar does not accept a wild card, therefore I
> had to list all one by one.


Try giving it the name of a file containing
the entire list of Java files to be compiled,
one on each line. From memory, that works..

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
How to launch One Java Program from another Java Program joshivaibhav Java 3 11-21-2006 05:42 PM
How to javac a java program w/ another java program which is w/o a main method cjeffwang@yahoo.com Java 1 10-31-2005 04:25 AM
Calling Java program in another Java program Rey Java 4 12-12-2003 10:18 PM



Advertisments