How to get dependencies into the project?


(Vijay Raju) #1

Hai friends,
I am writing one build script to compile my java class and to download the specified dependencies from maven repository.When i am compiling , my script is downloading the dependencies from the repository server .But i am not getting the jars into my context project of eclipse(I am using gradle buildship).

it showing error called—>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
And if i am running in command prompt like
java -jar build\libs\JdbcEx.jar com.raj.GetRecords
I am getting output but i want it from eclipse
following is my code
build.gradle

apply plugin:"java"
repositories {
mavenCentral()
jcenter()
}
configurations{
myConfig
}

dependencies{
myConfig 'mysql:mysql-connector-java:5.1.38’
compile 'org.slf4j:slf4j-api:1.7.18’
testCompile ‘junit:junit:4.12’
}

sourceSets{
main.java.srcDir "src/main"
test.java.srcDir “src/test”
}

jar{
from configurations.myConfig.collect{zipTree it}
manifest.attributes “Main-Class”: “com.raj.GetRecords”
}

And this is my mysql java code

GetRecords.java

package com.raj;

import java.util.;
import java.sql.
;

public class GetRecords {
public static void main(String args[]) {
try {
Class.forName(“com.mysql.jdbc.Driver”);
Connection con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/test”, “root”, “root”);
System.out.println(“connection is established” + con);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(“select * from test”);
while (rs.next()) {
System.out.println(rs.getString(“id”));
}
} catch (Exception e) {
System.out.println(e);
}
}
}

plz help me??? ASAP
Thanks