Gradle jettyRuns works but no dependencies in Eclipse - java

I am trying to make this application work and the building is configured in gradle. When I use jettyRun in cmd to run the application it works as expected however when I open the actuall code in eclipse I am missing all of these dependecies such as spring or hibernate and others... I am unsure how to resolve this
The gradle.build looks like this
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'jetty'
// JDK 7
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'ch.qos.logback:logback-classic:1.1.3'
compile 'org.springframework:spring-webmvc:4.1.6.RELEASE'
compile 'javax.servlet:jstl:1.2'
compile 'org.springframework:spring-orm:4.1.6.RELEASE'
compile 'org.springframework:spring-tx:4.1.6.RELEASE'
compile 'org.springframework:spring-jdbc:4.1.6.RELEASE'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'org.hibernate:hibernate-core:4.3.10.Final'
compile 'org.hibernate:hibernate-entitymanager:4.3.10.Final'
}
// Embeded Jetty for testing
jettyRun{
contextPath = "etnshop"
httpPort = 8080
}
jettyRunWar{
contextPath = "etnshop"
httpPort = 8080
}
//For Eclipse IDE only
eclipse {
wtp {
component {
//define context path, default to project folder name
contextPath = 'etnshop'
}
}
}

Using the command gradle eclipse fixed the problem.

Related

Spring boot where is my jar file

Spring boot makes it really easy to setup a simple app.
But it takes me longer to actually get a jar file which I can upload to a remote server.
I am using IntelliJ, no command line, and I use gradle. The application is running somehow out of Intellij. But where are the created files? Where is my jar from Bootjar?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
// add spring data repos
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql:42.2.4")
// REST interface
compile("org.springframework.boot:spring-boot-starter-data-rest")
// Security
compile("org.springframework.boot:spring-boot-starter-security")
}
Update: Added a picture of the project structure:
Update 2: Folder structure:
There will not be a jar created if you are just running this in your IDE. In order to do that, you need to run the gradle build (in your case) either from your IDE or the command line to get it to build it into a jar.
From the command line, go to your project directory and type this:
./gradlew build
This executes the gradle wrapper, which should download everything you need to run the build, and then executes the build.
You will then find your jar in build/lib
build/libs (if you've ran build to build the jar file)

Project ignores build.gradle when cloned from Git

First of all I've got a Java Project with Spring boot and I'm using Gradle.
My Problem is, when I am cloning my Project from Gitlab the spring framework libraries aren't working. On every import statement the following occurs:
Unused import statements
I figured out how to fix it. I only need to copy the content of my whole build.gradle file, delete the content and paste it in the build.gradle file again. After this step everything works normal.
my build.gradle looks as follows:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Is there a better way of fixing this issue than copy and paste?

Package org.json does not exist while pushig spring-boot(gradle) project to heroku

I am trying to deploy spring boot gradle project to heroku. The app is running fine locally. But after executing git push heroku master the push crashes with the error error: package org.json does not exist
Here is my Procfile
web: java -Xmx384m -Xss512k -XX:+UseCompressedOops -jar target/*.jar
--server.port=$PORT
--spring.data.mongodb.uri=$MONGOLAB_URI
and here is my build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
jar {
baseName = 'planaroute'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile('org.springframework.boot:spring-boot-starter')
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile 'org.springframework.data:spring-data-mongodb:1.9.2.RELEASE'
compile group: 'org.json', name: 'json', version: '20160810'
compile group: 'org.json', name: 'org.json', version: 'chargebee-1.0'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
Even I have downloaded org.json jar and added the jar externally to the project. It still doesnot work.
I added the following dependency to my build.gradle file and it worked fine after.
dependencies {
compile 'org.json:json:20090211'
.
. all my other project dependecies
.
}
I hope it helps you as it helped me.
Credits to
Dependencies not copied into jar (in Gradle) where I got this hint from.
Best wishes,
Marcos.

Unable to Build Spring RestService Tutorial in IntelliJ

I am attempting to work through the Spring Framework Restful Web Service creation tutorial(https://spring.io/guides/gs/rest-service/#scratch) using Gradle and IntelliJ. I have followed everything to the letter but being fairly new to Spring, IntelliJ, and Java in general I'm unsure how to go about further debugging my issue.
When I attempt to build my project I receive a few errors stating "Java: package org.springframework.web.bind.annotation does not exist." I'm guessing I'm missing a library reference but am unsure how to check and include it.
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.springframework:spring-web:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'hello_springtest'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
Just thought I'd add some additional information. I'm still seeing the errors and am unsure why but my project does report that the build was successful. When I attempt to make the project however that's when I receive the annotation does not exist error.
You have some dependency in your builds script, which seems to me redundant and causes Gradle to look up for additional dependencies.
Just remove this dependency from your buildscript dependencies
classpath("org.springframework:spring-web:${springBootVersion}")
I see no reason to use it within your buildscript.

build using gradle instead of eclipse

I'm very new to whole tomcat/spring/eclipse world.
I used gradle a little bit for android projects.
This is a project with tomcat/spring/eclipse and I 'd like to build it with gradle.
I copied a build.gradle file from one of tutorial on the web.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Now I run > gradle build and I see tons of errors which says 'org.springframework.*** does not exist'
I guess I need to somehow tell gradle to include *.jar files under
WebContent/WEB-INF/lib directory, but don't know how.
Please let me know if need to supply more info.
To add all jar files from WebContent/WEB-INF/lib and subfolders you must include the first line:
dependencies {
compile(fileTree(dir: "WebContent/WEB-INF/lib", include: "**/*.jar"))
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
}

Categories

Resources