Spring MVC Project error in Spring Tool Suite - java

In Spring Tool Suite 3.9.5, After Selecting New -> Project -> Spring Legacy Project -> Spring MVC Project. project is created but with errors. I even tried Maven -> Update Project but issues still exists.
Project Explorer
Problems
I have not installed Maven. I am using jdk 1.8

Seems as you are developing a Web project, most probably you are missing servlet.jar and other related web jars. So please proceed as follows:
Add following dependencies in your POM file with proper versions. Save the file.
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.1</version>
</dependency>
Do Maven -> Update Project (Install Maven in your system if not done)
Do a project clean build by going to Project -> Clean...
All error marks should go away by now. If not, go to Problem view by selecting Window -> Show View -> Problems
There check the issues in your project. Accordingly update the POM or change classpath. Now repeat steps 2 and 3.
EDIT :
It seems the following dependencies are missing for your project. Add these in your POM and follow the above steps.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

Removed repository folder's files from m2 folder. STS is now making Spring MVC Project without any error.

Related

package org.springframework.cloud.netflix.zuul does not exist

I am moving some test code from an older jHipster project to a new one. The old project uses the org.springframework.cloud.netflix.zuul library, specifically org.springframework.cloud:spring-cloud-netflix-core:1.3.0.RELEASE .
I put the below in my new project's pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
However, it seems to be pulling in org.springframework.boot:spring-boot:2.2.5.RELEASE. This release does not contain zuul in it however, as this code fails import org.springframework.cloud.netflix.zuul.
Does anyone know a fix or workaround?
Old library.
org.springframework.cloud:spring-cloud-netflix-core:1.3.0.RELEASE
My new project is using
org.springframework.boot:spring-boot:2.2.5.RELEASE
UPDATE:
Sorry I updated my question - my pom file already has this code. But it is very weird to me that even though I put to 1.3.0, I can see in my maven dependencies that it's pulling in 2.2.5. Also when I right click my project, I see maven - reimport and maven - generate sources etc.. I don't see a update project. And clicking both of those doesn't seem to downgrade it to 1.3.0
If you update your pom.xml file your problem would solve.
In your pom.xml file you'll see dependencies tag you need to add the library you want and then right click your project and say maven -> update project
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
Add following dependency to your pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
Upgrading spring-boot to >= 2.5 requires some extra configuration in order for Zuul to keep working, see:
https://gist.github.com/aldobongio/6a22f49863c7a777612f7887bbb8fd1d

How to resolve Microsoft Azure dependencies on Eclipse

I'm trying to follow "How to run a compute-intensive task in Java" tutorial.
However, I'm stuck on the following step:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-java-run-compute-intensive-task/#how-to-create-a-java-application-that-performs-a-compute-intensive-task
Eclipse shows an error saying that these dependencies can't be resolved:
import com.microsoft.windowsazure.services.core.Configuration;
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.serviceBus.*;
import com.microsoft.windowsazure.services.serviceBus.models.*;`
I'm using Eclipse and I've downloaded the Azure toolkit for Eclipse.
Here's how my Eclipse project looks like:
The code is simply a copy-paste of TSPSolver.java.
Per my experience, the issue was caused by missing some dependent libraries that you can try to add them via configure the Java Build Path or configure the pom.xml file in the Maven project to resolve it.
For the first way, adding the dependent libraries via configure the Build Path. You can download these libraries and their dependencies from the link.
Right click on the project name, then select Build Path and click Configure Build Path.
Add these jar files via click Add External Class Folder
For the second way, adding the maven dependencies in the pom.xml file.
Convert the current normal Eclipse Project into a Maven project.
Open the pom.xml file in the project and add the below content from link1 & link2.
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-core</artifactId>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>0.9.7</version>
</dependency>
</dependencies>
For those looking now, latest version are as follows:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>3.6.7</version>
</dependency>

No files were downloaded for org.springframework:org.springframework.core:3.2.2.RELEASE

I created a small java application using intellij, later I updated that project as Maven project using "Add framework support" option. When I tired to add spring jar file on project I got following error saying,"No files were downloaded for org.springframework:org.springframework.core:3.2.2.RELEASE".
Following are the steps I did to add spring jar files
1)Clicked on File -> Project Structure -> Modules -> Clicked on "+" Sign -> Library -> From Maven
2)Searched for org.springframework.core and selected 3.2.2 Release
3)Downloaded to lib folder under my project.
4)Got Error.
I don't know where it went wrong. I am new to java and spring application.
As already mentioned, Maven downloads dependencies itself (a reason why it's a build automation tool).
To add Spring as a dependency, add this code to Maven's pom.xml (the file is in your module's root directory):
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
</dependencies>
Also, delete the lib directory from your project root - Maven doesn't put jars there.
Maven downloads the dependencies automatically, can you try adding this to the pom.xml file. Maven should automatically download the dependencies..
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>

adding spring resources to eclipse

I'm struggling with adding spring framework libaries to my eclipse (with maven plug-in m2eclipse)
How can I achieve it in easiest way and why is it so complicated for a newbe user?
It's really frustrating that I can't move on with thing that simple like this.
Main goal is add spring libaries to my pom.xml file in depedencies tab in my dynamic web project in eclipse. Pom.xml is generated thanks to maven plug-in.
First of all I moved to the Eclipse Marketplace and installed Spring Tool Suite for Eclipse Kepler 4.3 and the result is nothing - still can't add libaries. Second attempt was installing the same suite for my whole windows, nothing worked so far.
Sample screenshot (all I can add is this):
Where is spring-web, spring-context, spring-webmvc etc. ? For me it's night and I don't have fresh eye on it but what am i missing here?
I have been using the Spring Framework and Java within Eclipse for a while now. And to be completely honest, the UI for pom.xml completely sucks. Just avoid the Eclipse UI for Maven and manipulate the raw XML. It is very intuitive and powerful.
So if you want to add a dependency, start using mvnrepository. From there you can get all the dependency snippets you need.
For 'spring-web' insert
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
In the <dependencies></dependencies> section. And you are set.
The same can be done for context and webmvc.
Just for convenience here is spring-webmvc:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
and here is spring-context
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>

Java EE Provided dependencies in Hudson / Jenkins

I'm trying to build a Maven based Java EE project on Jenkins, but I'm getting compilation errors. The reason seems to be that the Java EE dependencies that are marked as provided in the POM logically enough aren't downloaded when the project is built.
How can I set up the POM so that the build works in Jenkins, but the EE dependencies aren't included in the WAR file?
My thanks in advance for any input you can provide.
That's strange, AFAIK the dependencies with scope "provided" are simply not placed in the built file, they should however be downloaded. Are you sure your Maven is correctly configured to download dependencies - maybe there's a proxy that's not configured.
Not sure if its the best solution, but you can add EE dependencies with scope "provided", like the example:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.27</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
Maybe there is a plugin who provides all of them to you, but I'm not sure about that.
Hope that helps

Categories

Resources