I am starting a new project and I am trying to configure spring boot as a web project to use jsp's. I am using Spring Tools Suite 4.
I have added the spring web option while setting up.
I have added the following in the application.properties
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
I have also have the following dependencies in my pom file
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
When I try to add a tsp to the main/webapp/WEB-INF/jsp folder I dont get the jsp option.
Try installing the plugin from eclipse marketplace
Go to help -> eclipse marketplace
Then search Eclipse Java EE Developer Tools
Install it and restart your IDE
Related
I have not touched anything in the pom file. The fresh project shows 99 maven dependency problems. I generated the project from start.spring.io by adding various dependencies like lombok, spring data jpa, java mail, spring web etc. Why am I getting this and how can I solve this? I am attaching the pom without the build tag because I was getting an error while posting this question.
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.integrity</groupId>
<artifactId>signup</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>signup</name>
<description>POC</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
First thing to check if your system has maven installed or not?
If this is the freshly created spring project in eclipse, then you should do following steps to avoid most of the errors:
Right click on project, go to Maven and update project. Keep looking at the bottom right to see progress.
Click on Project from tool bar at top and clean all the project.
Right click on the project and go to java build path. Click on Libraries, verify if the project is using correct JRE version.
Right-click on your project and choose Properties to open the Project Properties dialog. There is a Project Facets item on the left, select it, look for the Java facet on the list, choose which version you want to use for the project and apply, always make sure that the version selected is available on your system.
I hope that these points would make most of the errors go away. Let me know if you still see any issue, otherwise you can just do a copy paste on google and you should get the answer to your errors.
I am having this error message for all the imported packages "The import org..... cannot be resolved". and my Spring and Hibernate dependencies are not being resolved. I have tried multiple solutions to fix this error but nothing seams to work, below are the solution I've tried.
Maven => Update Project but same error. Also did => Force Update of Snapshots/Releases
I have also tried to Right-click on the project and choose Properties, and then Maven. Uncheck the box labelled "Resolve dependencies from Workspace projects", hit Apply, and then OK
Deleted my local Maven repo, the .m2 directory and Restarted Eclipse.
https://i.stack.imgur.com/LCUta.png
'''
<modelVersion>4.0.0</modelVersion>
<groupId>com.luv2code.springdemo</groupId>
<artifactId>spring-crm-rest</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<properties>
<springframework.version>5.0.6.RELEASE</springframework.version>
<hibernate.version>5.4.1.Final</hibernate.version>
<mysql.connector.version>5.1.45</mysql.connector.version>
<c3po.version>0.9.5.2</c3po.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- Add Jackson for JSON converters -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
<!-- C3PO -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3po.version}</version>
</dependency>
<!-- Servlet+JSP+JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- to compensate for java 9 not including jaxb -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<finalName>spring-crm-rest</finalName>
<plugins>
<!-- Builds a Web Application Archive (WAR) file from the project output
and its dependencies. -->
<plugin>
<!-- Add Maven coordinates (GAV) for: maven-war-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</build>
'''
You need as first step to run from terminal in your project root directory the mvn clean install command. In this way you will "install the package into the local repository, for use as a dependency". After that for sure you need to refresh your workspace and run a mvn update
A major problem is apparent from the picture you provided, but I'm not sure how you got it into this state.
By default, Maven projects will have a source directory at "src/main/java" and "src/test/java". Your source directory appears to be just "src", so it's finding classes in "main/java/com/..." so it wants the packages to start with "src.main.java.com...".
You appear to have overridden the settings in the .classpath file somehow. If you're using Maven in Eclipse, you should let the m2e plugin determine the classpath.
From what I can see, if you remove the "src" source directory and replace it with "src/main/java", it will more likely be able to compile your code.
Update:
To answer your question in the comment (this is too long for a comment):
Neither. I would suggest copying the project to a location outside of your workspace, if it isn't already outside of the workspace. If the project was already located outside of the workspace, now delete the project, but DO NOT delete the contents. If the project was located inside the workspace, as you've now copied it out, you can delete the project. At this point, go to the location where the project lies outside of the workspace, and delete the ".classpath" file from that location. Now, import the project back into Eclipse. If your project is conventional otherwise, this will "reset" it to a sane organization with respect to m2e.
I am bootstrapping my spring application to spring boot and I have the problem that the embedded tomcat is not rendering the jsp files instead the file will be downloaded.
I have googled and tried everything what I have found so far but I still do anything wrong.
I have the following dependencies in my pom.xml file
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
</dependency>
Clipping from the application.properties
server.port=8080
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
Clipping from the Controller
#GetMapping(value= "/")
public String showPage(Model theModel) {
theModel.addAttribute("scrumbled", new Scrumbled());
return "main";
}
What am I doing wrong that the jsp file is downloaded instead of showing and rendered in the browser?
Thanks in Advance
The problem is with the jasper version. It worked with the below version irrespective of the tomcat version.
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.24</version>`enter code here`
</dependency>
My tomcat version was 9.0.63.
I have solved the issue.
The problem was a corrupted jar dependency. I had to maven clean, maven install the whole project to see the error. After deleting the jar from the file system maven downloaded the dependency again and now its working.
I am new to spring boot. I am trying to migrate project from old spring boot to the latest version.
I changed the version of spring boot in project. But when i build the project it fails in tests throwing computational failure with error below
package org.springframework.test.annotation does not exist
I have this dependency in my project
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
Not sure what i could be missing?
Change spring-boot-test TO spring-boot-starter-test like below :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
to
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Refer http://www.baeldung.com/spring-boot-starters for more info about starters.
I made a new Maven project with Netbeans. There is a pom.xml in which i added:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.24</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
Is it normal if I don't have a web.xml in my project tree after building the project or should i treat the glassfish.xml just the same ?
I wonder if I didn't messed up things.
Java EE 6 made web.xml optional (traded in for a bunch of annotation-based configurations).
If maven knows that Java EE 6 is the version, then it won't complain about a missing web.xml.
You should be able to configure for the most part using annotations. For portability's sake, use web.xml IF NEEDED rather than relying on vendor-specific configuration files.
Yup I Got solution (how to create web.xml in maven NetBeans 12.0 or later)
After making web application in maven NetBeans
1) Right click on WEB-INF Folder -> New -> Other
after clicking on other.. a window will popup
in that choose : WEB folder in category
after choosing WEB on right corresponding file type will open
in that select: Standard Deployment Descriptor(web.xml)
and now u have it enjoy .....
[My first Answer on Stack Overflow :)]