# Simple Java project build example

**URL:** <https://discuss.gradle.org/t/simple-java-project-build-example/7548>\
**Category:** Old Forum Archive\
**Created:** [August 3, 2012, 5:37am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548 "2012-08-03T05:37:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 5:37am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/1 "2012-08-03T05:37:00Z")

</div>

Please provide an example to build a simple java project along with dependencies fully written in gradle and groovy .This will help a lots to me as well as our fellows who are new to gradle .

I can not find even a single complete script for that on net

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 5:48am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/2 "2012-08-03T05:48:00Z")

</div>

the simpliest java build file with repository and dependency definition can look like this:

```gradle
apply plugin:'java'
  repositories{
    mavenCentral()
}
  dependencies{
    compile 'org.slf4j:slf4j-api:1.6.6'
 }

```

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 6:01am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/3 "2012-08-03T06:01:00Z")

</div>

Suppose I have a simple pojo class Abc.java and i want to compile it, build it , and create a jar for it .

Please provide a Gradle build script for that

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 6:02am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/4 "2012-08-03T06:02:00Z")

</div>

putting that java file in src/main/java of your project folder and run build with the script above should do the trick

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 6:28am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/5 "2012-08-03T06:28:00Z")

</div>

Thank you .It worked

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 7:28am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/6 "2012-08-03T07:28:00Z")

</div>

Hi Rene

with your help I am now able to compile the codes for my project

how to run it on jetty server

please help

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 8:06am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/7 "2012-08-03T08:06:00Z")

</div>

You can either use the war plugin to package your web application as web archive and deploy this manually to your server. for testing your app you can also use the jetty plugin to start and stop your web app in a jetty container from your build. Have a look at the according chapters in the userguide: [http://gradle.org/docs/current/userguide/userguide\_single.html#web\_project\_tutorial](http://gradle.org/docs/current/userguide/userguide_single.html#web_project_tutorial) and [http://gradle.org/docs/current/userguide/userguide\_single.html#jetty\_plugin](http://gradle.org/docs/current/userguide/userguide_single.html#jetty_plugin)

cheers!

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 10:50am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/8 "2012-08-03T10:50:00Z")

</div>

```gradle
Directory 'D:\sow\SowTrackerTool\src\main\webapp' specified for property 'webAppSourceDirectory' does not exist.

```

What should i do now

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [August 3, 2012, 10:52am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/9 "2012-08-03T10:52:00Z")

</div>

Perhaps check out the samples that are part of the ‘-all’ distribution. There are some examples of web projects in there.

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 11:38am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/10 "2012-08-03T11:38:00Z")

</div>

I am not getting any proper sample

Till now i have been able to compile all my java files to the build folder

what should i do now to configure my jetty server

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 11:43am UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/11 "2012-08-03T11:43:00Z")

</div>

Hey vivek, the jetty plugin chapter of the userguide has the details: [http://gradle.org/docs/current/userguide/userguide\_single.html#jetty\_plugin](http://gradle.org/docs/current/userguide/userguide_single.html#jetty_plugin)

cheers, René

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 2:35pm UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/12 "2012-08-03T14:35:00Z")

</div>

I am still not getting .

Till now i have only added the jetty plugin to the build script . Can u please suggest me how to proceed in a step wise manner .

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 3, 2012, 2:38pm UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/13 "2012-08-03T14:38:00Z")

</div>

In what problems do you run when trying out the jetty plugin?

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 2:50pm UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/14 "2012-08-03T14:50:00Z")

</div>

[![](https://sea1.discourse-cdn.com/gradle/uploads/default/1393/968c94171d502739.JPG)](https://d37wxxhohlp07s.cloudfront.net/s3_images/773534/vivek.JPG?1344005227)

I am sending u the screenshot

The project structure is

[![](https://sea1.discourse-cdn.com/gradle/uploads/default/1394/59856c2f68dd422c.JPG)](https://d37wxxhohlp07s.cloudfront.net/s3_images/773536/cccccccc.JPG?1344005285)

I have till now only added the jetty plugin to my build script

My build Script Is [![](https://sea1.discourse-cdn.com/gradle/uploads/default/1395/e0dae7981b40e12b.JPG)](https://d37wxxhohlp07s.cloudfront.net/s3_images/773539/builsss.JPG?1344005405)

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 3, 2012, 2:54pm UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/15 "2012-08-03T14:54:00Z")

</div>

Sorry i am new to jetty and i want to do a hot deployment on the jetty server ,without creating any war file.

---

<div class="post-metadata">

**Author:** ![vivek\_prasad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vivek_prasad/32/430_2.png) [@vivek\_prasad](https://discuss.gradle.org/u/vivek_prasad)\
**Post date:** [August 4, 2012, 1:11pm UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/16 "2012-08-04T13:11:00Z")

</div>

Hi Rene

Are you there , please find the screenshots above and suggest a solution

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [August 5, 2012, 9:11pm UTC](https://discuss.gradle.org/t/simple-java-project-build-example/7548/17 "2012-08-05T21:11:00Z")

</div>

To keep things clean here in the forum, let’s close this thread and move on in the other jetty related thread you already opened: [http://forums.gradle.org/gradle/topics/jetty\_server\_configuration](http://forums.gradle.org/gradle/topics/jetty_server_configuration)

cheers, René
