I'm trying to run 'javac' tool on a compiled .class file in Eclipse. I open External Tools Configuration them fill the filds:
Location: C:\Program Files\Java\jdk1.6.0_25\bin\javac.exe
Working directory: ${workspace_loc:/Main/bin}
Arguments: ?
I want to ask you what must I write in the Arguments field, and am I fill*Location* and Working directory: fields right ?
Launching the javac compiler from within Eclipse can be a very useful feature in some cases (e.g. for testing purposes, to compare the javac output with the output of the Eclipse compiler, to recompile individual class files with special javac compiler options or with a compiler of a different JDK version etc.). Other than using ant, there are two convenient ways to integrate javac into Eclipse: Setting up an "External Tools Configuration" for javac, or adding javac to the Eclipse build chain of a project.
Setting up an "External Tools Configuration" for javac
Here are the steps required to setup the javac compiler so it can be used inside Eclipse (ready to use launch configurations are below):
C:\Program Files (x86)\Java\jdk1.7.0_25\bin\javac.exe
).-classpath ${project_classpath}
).-d ${project_loc}\bin
).${selected_resource_loc}
for the selected source file or ${selected_resource_loc}\*
for the selected package). The complete "Arguments" field for the configuration could look like this:-verbose -classpath ${project_classpath} -d ${project_loc}\bin ${selected_resource_loc}\*
In addition to that, you will probably want to select "Refresh resources upon completion" for the selected project under the "Refresh" tab of the tool configuration, and possibly deselect "Build before launch" under the "Build" tab.
I created two default launch configurations for javac, that you may reuse by putting them into a file ending with ".launch" in your project folder (e.g. "javac.launch"). Eclipse will automatically detect these configuration files once you open the "External Tools Configuration" dialog. You will most likely need to change the location of javac to the location of javac on your computer.
File "javac (verbose file).launch" - launches javac with the -verbose option on a single selected file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="C:\Program Files (x86)\Java\jdk1.8.0\bin\javac.exe"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value=" -verbose -classpath ${project_classpath} -d ${project_loc}\bin ${selected_resource_loc}"/>
</launchConfiguration>
File "javac (dir).launch" - launches javac on the selected package:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="C:\Program Files (x86)\Java\jdk1.8.0\bin\javac.exe"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-classpath ${project_classpath} -d ${project_loc}\bin ${selected_resource_loc}\*"/>
</launchConfiguration>
Adding javac to the Eclipse build chain of a project
Adding javac to the build chain, so it gets executed automatically during a full or automatic build is done in a similar way as described above:
-d ${build_project}\bin
. Then you should add the source files/folders that you want to be compiled by javac to the end of the argument list using the "${resource_loc}" variable. The complete argument list for compiling a single source file could look like this: -classpath ${project_classpath} -d ${build_project}\bin ${resource_loc:MyProject/src/myPackage/MyClass.java}
. To compile a complete package you can write ${resource_loc:MyProject/src/myPackage}\*
instead.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With