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

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.

Related

Spring 2.0.2 Build war file using gradle

I utilized the following to develop a Restful application.
jdk1.8.0_171
tomcat 8.5(servlet 3.1)
Spring boot 2.0.2 to
I built a war file by doing below three things:
made main class to extend SpringBootServletInitializer and overrode its configure method
add apply plugin: 'war' to build.gradle
add providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' to dependencies in build.gradle
I started application by executing java -jar MyApp.war. The application can be accessed from any browser. But when the same war file was deployed to tomcat server, I got 404 error when I tried to access the application from a browser. There is no error in log.
Anyone has idean? Thanks!

Tomcat not booting up Gradle Webapp

I have a Gradle webapp having plugin war and jetty defined in build.gradle, as follows:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'
group = 'com.company'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
war.baseName = 'deploy'
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repository.pentaho.org/artifactory/repo/" }
}
dependencies {
..
}
When I perform a gradle build with jettyRunWar, as follows:
$ ./gradlew jettyRunWar
It build the application and deploy it to Jetty as expected.
Now I want to deploy the same application to Tomcat7 as well, to do the same, I ran the gradle war task as follows:
$ ./gradlew war
after running the task, I can see the deploy-1.0.war inside /Users/ArpitAggarwal/deploy/build/libs/ and when I tried to deploy it to Tomcat7, it's not picked up by Tomcat.
My question is - Do I need to apply any additional plugin to make the application deployable to Tomcat7?
Thanks.
war plug-in only creates a war, it doesn't deploy generated war to tomcat by itself.
You can create a task to deploy war to tomcat.
task deployToTomcat(type: Copy) {
from war.archivePath
into "${tomcatHome}/webapps"
}
You can also use gradle-tomcat-plugin.
The problem is contextRoot of .war file. Gradle generates the contextRoot of .war file picking the war.baseName and version, so the contextRoot is changed to deploy-1.0 and the application is accessible at:
localhost:8080/deploy-1.0
Then I removed the version field from build.gradle which makes Gradle generate .war with contextRoot as deploy and application accessibility at:
localhost:8080/deploy/

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.

Using gradle to generate eclipse projects for EJB Module

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')