Spring 2.0.2 Build war file using gradle - rest

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!

Related

No EJB found with interface when built as jar

I have the following error when deploying and starting the application with Wildfly.
No EJB found with interface of type "de.dev.java.project.api.ProjectApi" for binding de.dev.java.project.restservice.ProjectRestService/projectApi.
Project module structure:
- project-api -> built as jar
- ProjectApi.java
- project-impl -> built as jar
- ProjectRestService.java
{
#EJB ProjectApi projectApi
}
- application -> built as ear, which includes modules above
I only have a problem when i build "project-impl" module as jar. When i built as war i do not have a problem. What does war include which jar does not?
You must build as a proper ejb jar, not just regular jar. It also needs to be referenced properly in the ear. Use you IDE to setup suitable maven project with the right archetype

Eclipse run a spring boot application with MavenDependencies in classpath taken from a maven profile

I have a spring boot project that run correctly when launched from maven mvn -P dev spring-boot:run.
When I start it as a java application it fails because of several ClassNotFoundException. It's due to the fact that some dependencies belong to dev maven profile so they're not present in Maven Dependencies that eclipse put in classpath when it launchs java appication.
So the question is: how can I obtain the correct Maven Dependencies choosing a particular maven profile?

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.

java.lang.ClassNotFoundException for a class in external JAR

I have a maven project in Eclipse Java EE IDE for Web Developers.
When running Tomcat, I'm getting an error for a class that I can see that I have included.
My question is - do I have to add these JARs to an additional place because of Tomcat Apache?
Error:
SEVERE: Servlet /Resource threw load() exception
java.lang.ClassNotFoundException: org.odata4j.jersey.producer.resources.ODataApplication
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:240)
at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:220)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:711)
And here is the class in my Library:
UPDATE:
My Web Deployment Assembly looks like:
The issue you are seeing is due to the fact that tomcat is looking at the wrong directory. It is currently most likely pointed at your src/main/webapp directory of your project. This does not jive with how maven works. Maven downloads the dependencies, but will only include them in the target build. You need to have the tomcat server look at target/myapp-0.0.1, or build to a war and deploy that way. The easiest solution as of now, would be for you to use the tomcat plugin. After setting it up, you can use an imbedded server, and just use the following command 'mvn tomcat:run'.
Maven Tomcat Plugin Docs
UPDATE:
I looked at the properties settings, and you should actually be able to edit the "Web Deployment Assembly" settings for your project (under project properties). Check screenshot for how I have mine setup. Notice how Maven Dependencies is mapped.
http://imgur.com/ofxryns

Spring 3.1 NoClassDefFoundError ListableBeanFactory

I am trying to upgrade an old project from Spring 2.5.6 to Spring 3.1.0. The project is not built with Maven so I had to add the jars manually to the build path.
The application uses Eclipse RAP as well as Spring.
I added all the Spring 3.1 jars in my build path:
lib/org.springframework.aop-3.1.0.RELEASE.jar
lib/org.springframework.asm-3.1.0.RELEASE.jar
lib/org.springframework.aspects-3.1.0.RELEASE.jar
lib/org.springframework.beans-3.1.0.RELEASE.jar
lib/org.springframework.context-3.1.0.RELEASE.jar
lib/org.springframework.context.support-3.1.0.RELEASE.jar
lib/org.springframework.core-3.1.0.RELEASE.jar
lib/org.springframework.expression-3.1.0.RELEASE.jar
lib/org.springframework.instrument-3.1.0.RELEASE.jar
lib/org.springframework.instrument.tomcat-3.1.0.RELEASE.jar
lib/org.springframework.jdbc-3.1.0.RELEASE.jar
lib/org.springframework.jms-3.1.0.RELEASE.jar
lib/org.springframework.orm-3.1.0.RELEASE.jar
lib/org.springframework.oxm-3.1.0.RELEASE.jar
lib/org.springframework.test-3.1.0.RELEASE.jar
lib/org.springframework.transaction-3.1.0.RELEASE.jar
lib/org.springframework.web-3.1.0.RELEASE.jar
lib/org.springframework.web.portlet-3.1.0.RELEASE.jar
lib/org.springframework.web.servlet-3.1.0.RELEASE.jar
lib/org.springframework.web.struts-3.1.0.RELEASE.jar
and I also listed them in the MANIFEST.MF.
The project builds fine, but at runtime when trying to login it gives me the following error:
java.lang.NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory
I looked in the beans jar and the class is definitely there. I also searched through the project and the class is not used explicitly anywhere.
What could cause this? Thank you in advance.
This class does not exist in Spring 3.1.0. See http://www.jarfinder.com/index.php/java/info/org.springframework.beans.factory.ListableBeanFactory