# How to use Exec type task to run javac command

**URL:** <https://discuss.gradle.org/t/how-to-use-exec-type-task-to-run-javac-command/32924>\
**Category:** Help/Discuss\
**Created:** [August 26, 2019, 2:42pm UTC](https://discuss.gradle.org/t/how-to-use-exec-type-task-to-run-javac-command/32924 "2019-08-26T14:42:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sming](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sming](https://discuss.gradle.org/u/sming)\
**Post date:** [August 26, 2019, 2:42pm UTC](https://discuss.gradle.org/t/how-to-use-exec-type-task-to-run-javac-command/32924/1 "2019-08-26T14:42:17Z")

</div>

Hello all,

I am currently testing how to implement the javac command in gradle on my local directory. My current test directory structure is:

my .java files that I want to compile are contained within:  
“C:/Users/s7959615/Desktop/Technical\_Work/gradle\_test/com/bns/csm/downstream/basket/jaxb”

The destination directory of the generated .class files is:  
“C:/Users/s7959615/Desktop/Technical\_Work/gradle\_test/classes/basket”

My (test) task currently is:

apply plugin: ‘java’

task javaComp (type:Exec) {  
executable = “javac”  
args = ["-sourcepath", “C:/Users/s7959615/Desktop/Technical\_Work/gradle\_test/com/bns/csm/downstream/basket/jaxb”,  
“-d”, “C:/Users/s7959615/Desktop/Technical\_Work/gradle\_test/classes/basket”]  
}

However it returns an error of:

Finished with non-zero exit value 2.

Any input would be appreciated.

Thanks,

Steven

---

<div class="post-metadata">

**Author:** ![DJViking](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@DJViking](https://discuss.gradle.org/u/DJViking)\
**Post date:** [August 28, 2019, 8:38pm UTC](https://discuss.gradle.org/t/how-to-use-exec-type-task-to-run-javac-command/32924/2 "2019-08-28T20:38:29Z")

</div>

Why use an Exec task to compile Java?

Just put your source code within src/main/java and it will compile automatically.  
src/main/java/com/bns/csm/downstream/basket/jaxb

All you need is the java or java-libary plugin and it will compile all main and test java code.  
src/main/java and src/test/java

```gradle
plugins {
    id 'java-library'
}

```

I assume your gradle project is gradle\_test? No need, nor should you use absolute paths like that. It will make it much more difficult to build anywhere else.

However if what you really want is to run the javac manually on some piece of code. Other than you should not use absolute paths, the arguments looks right, but Windows path has wrong file separator /, should be . C:\Users…  
Try adding -verbose to find out more about why javac failed.
