Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

JavaCompiler can output in a different folder?

Thread view: 
Jean-Sébastien Goupil - 19 Oct 2007 19:59 GMT
Hi,

I'm currently using Java6 and I'm compiling my class with the
JavaCompiler.

When I compile my class with a specific file, the output .class is
copied just aside the java file.
When I compile my class without specifiying a folder (with the
following code)

///////
final GaeaJavaSourceFromString javaFileObject = new
GaeaJavaSourceFromString("Data", code)
final Iterable<? extends JavaFileObject> compilationUnits =
Arrays.asList(new SimpleJavaFileObject[] { javaFileObject });
final Iterable<String> options = Arrays.asList(new String[] {"-
verbose", "-Xlint" });
boolean compilation = _compiler.getTask(null, _fileManager,
_diagnostic, options, null, compilationUnits).call();

code = "public class Data { }";
_compiler = ToolProvider.getSystemJavaCompiler();
_fileManager = _compiler.getStandardFileManager(null, null, null);
_diagnostic = new DiagnosticCollector<JavaFileObject>();

and
public class GaeaJavaSourceFromString extends SimpleJavaFileObject {
   final String code;

   public GaeaJavaSourceFromString(String name, String code) {
       super(URI.create("string:///" + name.replace('.','/') +
Kind.SOURCE.extension),
             Kind.SOURCE);
       this.code = code;
   }

   @Override
   public CharSequence getCharContent(boolean ignoreEncodingErrors) {
       return code;
   }
}
/////////

The output .class is copied in the folder where the program is
started.

I would like to output this class in a specific folder... is it
possible? I know that Eclipse has the property "Output Folder". I
don't know if I should simply move the file ? Is there any option i
can set in the compiler to output the .class file somewhere?
Richard Reynolds - 19 Oct 2007 20:42 GMT
> Hi,
>
[quoted text clipped - 46 lines]
> don't know if I should simply move the file ? Is there any option i
> can set in the compiler to output the .class file somewhere?

yes, did you consider googling this? the very first hit for "javac options"
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html
Lew - 19 Oct 2007 20:58 GMT
"Jean-S�bastien Goupil" <jsgoupil@gmail.com> wrote
>> I'm currently using Java6 and I'm compiling my class with the
>> JavaCompiler.
[quoted text clipped - 3 lines]
>> When I compile my class without specifiying a folder (with the
>> following code)

which you really, really should lay out for readability on Usenet.

>>  boolean compilation = _compiler.getTask(
>>         null, _fileManager, _diagnostic,
>>         options, null, compilationUnits ).call();

According to
<http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompiler.html#getTask(java
.io.Writer,%20javax.tools.JavaFileManager,%20javax.tools.DiagnosticListener,%20j
ava.lang.Iterable,%20java.lang.Iterable,%20java.lang.Iterable
)>

it looks like your "options" are the key.

>> ...
>> The output .class is copied in the folder where the program is
[quoted text clipped - 4 lines]
>> don't know if I should simply move the file ? Is there any option i
>> can set in the compiler to output the .class file somewhere?

> yes, did you consider googling this? the very first hit for "javac options"
> http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html 

He might've done, except that he's using Java 6, not the obsolescent Java 1.4.

That said, given the information in the JavaCompiler Javadocs, it looks like
the standard compiler options at
<http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html>
<http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html#options>
apply, specifically "-d directory".

Signature

Lew

Jean-Sébastien Goupil - 19 Oct 2007 21:41 GMT
> "Jean-S?bastien Goupil" <jsgou...@gmail.com> wrote
>
[quoted text clipped - 38 lines]
> --
> Lew

I tried that and it seems it's not working...,
I tried with
-d C:\
-d file://C:/
-d .
"-d ."
-d "."
-dC:\

...

And I receive this : "java.lang.IllegalArgumentException: invalid
flag: -d ."
Richard Reynolds - 19 Oct 2007 22:04 GMT
>> "Jean-S?bastien Goupil" <jsgou...@gmail.com> wrote
>>
[quoted text clipped - 55 lines]
> And I receive this : "java.lang.IllegalArgumentException: invalid
> flag: -d ."

Please show us the whole command you're using.
Jean-Sébastien Goupil - 19 Oct 2007 22:36 GMT
On Oct 19, 5:04 pm, "Richard Reynolds" <richiereyno...@ntlworld.com>
wrote:
> "Jean-S?bastien Goupil" <jsgou...@gmail.com> wrote in message
>
[quoted text clipped - 61 lines]
>
> Please show us the whole command you're using.

there is the code I am using

Remove the -d . to make it works, But i would like to move the .class
file somewhere else...

http://pastebin.com/f1e39ed76
Lew - 19 Oct 2007 22:58 GMT
>>> I tried that and it seems it's not working...,
>>> I tried with
[quoted text clipped - 4 lines]
>>> -d "."
>>> -dC:\

That's probably because "-d" and the target directory are two different
arguments, not one.

How about:

 final Iterable<String> options =
   Arrays.asList( new String[] { "-verbose", "-Xlint", "-d", "."} );

Then, of course, there is the very dicey issue of where "." is.

Signature

Lew

Jean-Sébastien Goupil - 19 Oct 2007 23:26 GMT
> Jean-S?bastien Goupil wrote:
> >>> I tried that and it seems it's not working...,
[quoted text clipped - 18 lines]
> --
> Lew

This is perfectly working
of course i don't use ".", it was just to test here

thank you very much


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.