How to start a new Java project without an IDE?
I was asked for help to setup a new Java project with Eclipse. The last time I used Eclipse to write a Java program was probably 10 years ago. I had forgotten most of the details, so I downloaded the latest version of Eclipse and tried to create a new project and reference the RingCentral Java SDK which is hosted on MavenCentral. But it turned out to be very hard. Eclipse changed so much and I have no idea how it could fetch a library from MavenCentral. That’s the risk of using an IDE: you will be left behind if the IDE changes, even though the Java language has changed very little.
So I really don’t want to bind my Java programming skills to any IDE. What really matters is the programming language itself instead of the IDE. If an IDE keeps blocking your way and makes you stuck, just get rid of it. Here comes the topic of this article: how to setup a new Java project without an IDE? I will create a simple Java application and reference the RingCentral Java SDK. I will use Visual Studio Code as my text editor. Other text editor works as well because we just use it to edit the code and nothing else.
Gradle Build Tool
From mobile apps to micro services, from small startups to big enterprises, Gradle helps teams build, automate and deliver better software, faster.
Gradle is arguably the most popular build tool for Java development. Another popular Java build tool is Apache Maven. We use Gradle because Gradle has better performance than Maven.
I install Gradle using homebrew:
brew install gradle
Bootstrap the project
Create the folder for the project
mkdir java-without-ide-demo
cd java-without-ide-demo
Initialize the project using command gradle init
:
gradle initSelect type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 3Split functionality across multiple subprojects?:
1: no - only one application project
2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 1Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4] 1Project name (default: java-without-ide-demo):
Source package (default: java.without.ide.demo): com.ringcentral.demo> Task :init
Get more help with your project: https://docs.gradle.org/6.8.3/samples/sample_building_java_applications.htmlBUILD SUCCESSFUL in 35s
2 actionable tasks: 2 executed
Please note that, we cannot use the default package name java.without.ide.demo
because java
is a prohibited keyword in package name.
Run the project:
./gradlew run> Task :app:run
Hello World!BUILD SUCCESSFUL in 890ms
Wow! It works out of the box! Let’s take a look at the default source code:
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package com.ringcentral.demo;public class App {
public String getGreeting() {
return "Hello World!";
}public static void main(String[] args) {
System.out.println(new App().getGreeting());
}
}
Add some RingCentral code
First, let’s edit the build.gradle
file and add a dependency:
dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13' // This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre' implementation group: 'com.ringcentral', name: 'ringcentral', version: '2.0.0'
}
The line implementation group: ‘com.ringcentral’, name: ‘ringcentral’, version: ‘2.0.0’
is to add the RingCentral SDK as dependency.
Then we edit the source code and change it to:
In the code we initialized the RingCentral SDK and we fetched the current user’s extension number and printed it.
Let’s run it:
./gradlew run> Task :app:run
101BUILD SUCCESSFUL in 1s
2 actionable tasks: 1 executed, 1 up-to-date
The current user’s extension number is 101
. You may get different result if you specify different credentials.
Source code
You can download the source code of this article from GitHub.
Summary
In this article I showed you how to create a new Java project without an IDE from scratch. It may be easier than you expected. In my opinion, it’s even easier than using an IDE to create it. Remember, what we want to focus is the programming language instead of the IDE. I hope you enjoy reading this article.
Please let us know what you think by leaving your questions and comments below. To learn even more about other features we have make sure to visit our developer site and if you’re ever stuck make sure to go to our developer forum.
Want to stay up to date and in the know about new APIs and features? Join our Game Changer Program and earn great rewards for building your skills and learning more about RingCentral!