Using gradle to generate eclipse projects for EJB Module - eclipse

I want to generate project and settings for a EAR project, a EJB client jar and a EJB module but i was not able to insert new facets to the eclipseWtp task, tried many combinations based on the documentation on gradle website.
tried things like the following and always got Premature end of file error.
eclipseWtp {
beforeConfigured { wtp ->
wtp.facets.add(new Facet('jst.ejb','3.1'))
}
}
eclipseWtp {
facet(['name':'jst.ejb','version':'3.1'])
}

Make sure that both war and eclipse plugins are applied on the project. Then it will work correctly, eg.:
apply plugin: 'war'
apply plugin: 'eclipse'
eclipseWtp.facet(name: 'jst.ejb', version: '3.1')

Related

Gradle other project as dependency in eclipse

I have a web application which depends on another standalone project. Simply the web project requires a standalone project jar to be in classpath. I have built the standalone project jar with gradle and included that in web application's WEB-INF/lib folder. The project is running as expected. Now i want to make it automatic by adding that project as dependency. This is also achieved using the following code.
settings.gralde
include 'job-invoker'
project(':job-invoker').projectDir = new File(settingsDir, '../job-invoker')
build.gradle
dependencies {
compile project(':job-invoker')
.
.
}
I'm able to build the war file from command line using gradle and run it in tomcat. But i'm getting errors in eclipse. I'm not able to run the project in eclipse due to the compilation errors. Can some one please help me. Thanks in advance.
Finally i found a solution for this by installing the other project in maven local repository and adding this as a regular dependency in project. Reference code is given below.
Other project Gradle file
apply plugin: 'maven'
group = 'com.xxx.job'
version = '1.0'
Run gradle install command on this project. Then add mavenLocal() to your repositories in another project and add the dependency
compile 'com.xxx.job:job-invoker:1.0'

Eclipse Gradle Spring Boot MVC Build does not recognize jsp's

I am new to Spring Boot MVC. I have a simple Hello World MVC application that I found on the web. I am aware of several problems with Spring Boot embedded running MVC. I believe I have modified my application to handle these problems. The last issue I am having is running the application as Eclipse "Run as Spring Boot App" feature with jsp's. If I build my application from the command prompt with Gradle and run the executable war file everything works fine including displaying jsp webpage elements.
>Gradle Build
...
...
> cd build\libs
> java -jar MvcDemo3.war
If I run the application in Eclispe as "Run as Spring Boot App", the browser displays the webpage but none of the jsp elements are correct. It is as if the server side code is not recognizing jsp code.
Here is my build.graddle code,
buildscript {
ext {
springBootVersion = '1.4.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'MvcDemo3'
version = 'v001'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.apache.tomcat.embed:tomcat-embed-jasper')
}
Not sure why command line Gradle .war build works but Eclipse does not. I have read that Eclipse does not come with jsp support. I tried adding jstl jars to the build but no luck. Any ideas?
The problem is that spring boot mvc using jsp's is not supported using jars. All I had to do was modify the gradle.build to build a .war instead of a .jar. I executed the .war and it worked perfectly. Of course I read the spring boot mvc documentation after I discovered this problem and the specifically point out that you need to create an executable .war instead of a .jar. For any newbies, you execute the .war in command line using; java -jar MyMvcApplication.war.

Eclipse dynamic web project run on tomcat get 404 (page not found) error

After migrate to eclipse 4.5 (mars), I imported my project from remote git repository. Added tomcat 7 server to eclipse servers list. And tried to run project on server, but get 404 error. I use gradle as build tool.
apply plugin: 'java'
apply plugin: 'war'
repositories {
mavenCentral()
}
war.archiveName "gepick.war"
dependencies {
compile 'org.scala-lang:scala-library:2.11.1'
//...... list of libs
runtime 'javax.servlet:jstl:1.1.2'
}
war {
from 'WebContent'
}
task copyTask(type: Copy) {
from 'build/libs/gepick.war'
into '/opt/tomcat/webapps/'
}
Eclipse Web deployment assembly: http://postimg.org/image/kq5h1dol9/
Server settings: http://postimg.org/image/ohrcpuirb/
For me is strange why deployed project on deploy path has only folders without .class files on /../.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/gepick/WEB-INF/classes.
I read other posts but not found way how to fix it. Where I should look to search the problem?

Gradle dependency sources not appearing in Eclipse for the War Plugin

I am working on a Java web project that uses Gradle (version 2.1) as the build dependency tool. I use Eclipse Luna as my IDE. My OS is Mac 10.9 (Mavericks).
This is my build.gradle file (very basic and stripped down for ease of illustration):
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '3.0'
}
So just one dependency, Guice. I will generate my Eclipse classpath and project files using gradle cleanEclipse eclipse. Then I will import an existing project into my workspace. I like being able to view the source code of my dependencies in my Eclipse projects, so I will open a Guice class, such as com.google.inject.Injector, using CMD-SHIFT-T. And voila, the source code of that file will appear.
But I working on a web project, so I need to be able to build a WAR file instead of a JAR file. Therefore, I am going to apply the Gradle War Plugin by replacing apply plugin: 'java' with apply plugin: 'war'. Then I rerun gradle cleanEclipse eclipse and reopen my project.
Now, instead of seeing the source code when I open up Injector, I will see the bytecode viewer with the Attach Source button. Anyone have any ideas whether it's something I'm forgetting in my build.gradle file or if it could be a bug in Gradle/Eclipse?
Note that I am not using the Gradle Integration for Eclipse Plugin because I wish to pinpoint the root cause of this issue without adding an extra layer of complexity to it. I have also checked other SOF questions about Attach Source issue with Gradle and Eclispe, such as how to tell gradle to download all the source jars and Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?, but to no avail.

How can eclipse find 'javax.servlet' when using the gradle with plugins 'war' and 'jetty'

This must be very basic. But I just don't know how to make it work.
I'm following the book "Gradle in Action". When making the webapp the following is put in the build.gradle file
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5',
'javax.servlet.jsp:jsp-api:2.1'
runtime 'javax.servlet:jstl:1.1.2',
'taglibs:standard:1.1.2'
}
I'm using eclipse. But it seems eclipse can't find javax.servlet. In cmd, I'm still able to run gradle jettyRun. Am I missing something? Thanks ahead!
apply plugin: 'eclipse-wtp'
is probably missing in your build.gradle. I suppose you have WTP (Web Tools Platform) plugins installed into your Eclipse.