Generate a JAVAC/JAVA/JAVAW command strings [message #251209] |
Mon, 04 February 2008 11:22  |
Eclipse User |
|
|
|
Originally posted by: vpetrone.sympatico.ca
Hi,
I'm new to Java and Eclipse. I've been using Eclipse (v3.3.1.1 under
Windows XP) for all aspects of my first Java development and I've found it
very intuitive to work with. However, once I've completed my development,
I'd like to be able to port the compile and run functions out of Eclipse
so that non-Eclipse users may support and execute my Code. Therefore, I
need to create JAVAC and JAVA/JAVAW command strings to perform the compile
and run functions that Eclipse is performing for me.
So, my question is: does anyone know if the Eclipse JDT provides a
facility to generate the following command strings?:
1) A JAVAC command string to compile a given Java class within a package.
2) A JAVA/JAVAW command string to execute a given Java class.
Essentially, I'd like to have Eclipse generate these command strings from
the build and run properties that it has defined for a given class.
Thanks in advance,
Vic
|
|
|
|
|
Re: Generate a JAVAC/JAVA/JAVAW command strings [message #251242 is a reply to message #251238] |
Mon, 04 February 2008 15:56   |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Vic Petrone" <vpetrone@sympatico.ca> wrote in message
news:4fc630a0bec6d990d73fea7bbf14afa8$1@www.eclipse.org...
> I've looked into Ant. It appears to create an XML that you then feed back
> into an Ant program to perform a compile. However, I'd like to generate a
> plain JAVAC command string aswell as an execution (JAVA or JAVAW) command
> string.
So far as I know, Eclipse does not have any functionality to produce just an
isolated javac command line for compilation.
Allow me to gently suggest that for compilation, you should learn how to
make use of ant, just as if it were part of the language. (It's pretty
simple.) Ant is the industry-standard way of managing builds in Java, sort
of like "make" is for C. If your compilation command is complicated enough
to require asking this question - i.e., if you're compiling more than a
single Java file - it's complicated enough to manage with ant rather than a
batch script. Batch scripts (command lines) have a way of very quickly
growing larger than their developer initially intended.
As for launching, there are basically two scenarios: either your application
is completely contained within one jar file, or it calls upon other jar
files. If it's the first case, the command line is simply "java -jar
[yourJar]". If you've set your options properly in Eclipse, the main entry
point will be specified in the manifest.mf file, which is contained in the
jar file, so Java will know how to find it and run it. (Of course if you
have your own command line options, they need to be added as well.) If
there are more jar files, then you either need to use a tool such as
"fatjar" to combine them together, or you need to specify the classpath,
"java -cp [classpath] -jar [yourJar]". The classpath will depend on where
those other jars are installed - if they are system or third-party jars,
rather than part of your application, the classpath may be different for
different users' installations. You can also use Ant to run your
application, as well as to compile it, but that is a less common thing to
do.
|
|
|
|
Re: Generate a JAVAC/JAVA/JAVAW command strings [message #251254 is a reply to message #251246] |
Mon, 04 February 2008 19:20  |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Vic Petrone" <vpetrone@sympatico.ca> wrote in message
news:8e3e641c512b2e4d64fc004cbbed522e$1@www.eclipse.org...
> Hi Walter,
>
> Thannks for your reply! I will look into learning more about Ant when time
> permits.
One very easy way is to allow Eclipse to generate an Ant script for you, and
then take a look at its contents.
The basic idea, just as with "make", is that you have a structure of
dependencies and associated actions. For instance, foo.jar might depend on
some .class files with the associated action of calling the 'jar' tool, and
the .class files would depend on .java files with the associated action of
calling 'javac' with appropriate flags. The rest of the ant script is just
about setting up the correct flags, environment variables, and tool
definitions.
|
|
|
Powered by
FUDForum. Page generated in 0.03018 seconds