org.springframework package cannot be imported - spring

As the topic says I cannot import this package in my web dynamic project using SpringSource Tool Suite.The command Spring Tools --> Add Spring Project Nature has been already executed.
Thank you.

What kind of project did you create? Is it a Maven project? If so, you need to make sure that you are importing 'at least' the spring-context dependency like so
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.1.0.RELEASE</version>
    <scope>runtime</scope>
</dependency>
(or whatever version you want to use)
[EDIT]
Since as you say, you are using a Dynamic Web Project through this example -> http://www.vaannila.com/spring/spring-mvc-tutorial-1.html, you need to physically add the following jar files to your WEB-INF/lib folder
antlr-runtime-3.0
commons-logging-1.0.4
org.springframework.asm-3.0.0.M3
org.springframework.beans-3.0.0.M3
org.springframework.context-3.0.0.M3
org.springframework.context.support-3.0.0.M3
org.springframework.core-3.0.0.M3
org.springframework.expression-3.0.0.M3
org.springframework.web-3.0.0.M3
org.springframework.web.servlet-3.0.0.M3
You should have the following:
Adding the 'Spring Project Nature' does not add the dependencies for you, but only instructs the IDE that this project is using Spring.

Use maven.it automatically adds the necessary jar files.otherwise u need to manually do it.you can have a look at this http://www.mkyong.com/maven/how-to-convert-java-web-project-to-maven-project/
to migrate an existing project into maven
OR
You can manually add the necessary jar files.
Right click on the spring project>>
properties>>
java build path>>
libraries>>Add jars
:)

Related

adding Apache Commons Lang3 to my Spring Boot project

I am doing a Spring Boot exercise from Baeldung.com. The project has a test class that uses the method randomAlphabetic, which I have traced back to RandomStringUtils, which in turn belongs to Lang3 from Apache Commons. I can't seem to add the import of RandomStringUtils or even Lang3 itself to my project.
I have looked at the import on the GitHub repository for the project. The project is done as a Maven project, but I have done mine as a Gradle project, because Gradle is what I use at work (I don't know Maven). I have added the following to my build.gradle file:
plugins {
id 'org.apache.commons'
}
dependencies {
implementation 'org.apache.commons:commons-lang3:3.12.0'
}
I have attempted the following import statements:
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.*;
When I am writing my import statement and I put the period after commons, the autocomplete only comes up with two choices: logging and logging.impl . I do not even have an option to add lang3. I have also checked in the Spring Initializer to see if I could add lang3 there, but I cannot.
I have downloaded lang3 onto my computer. It contains 5 JAR files plus a lot of other material that I don't know how to use. I thought I could move those JAR files into my Project and External Dependencies 'folder,' but I can't find any way to do so. I'm using Spring Tools 4 Suite for Eclipse, btw.
Any help is appreciated.

Call a flow of one mule project in another mule project

I have a mule project-A where in I need to call a flow from another mule project-B. I have added <classifier>mule-plugin</classifier> in the project-B's pom. And I have added a dependency with project-B's group-Id, version, artifact-Id, classifier in project-A's pom and also created an "import" config in project-A with flow name of project-B which I want to use. Still I am unable to call the flow of project-B in project-A
If you are implementing this to just test in your local machine, then follow the below steps. You can also look at the concept of Mule Domain Project, which does resource sharing for those apps falling under the same domain ; enabling you to call other apps flow-refs, global configurations and more.
Note : All this below said has to be in Mule 4.
First, export your Project-B as a mule deployable jar.
Steps
Right click on Project-A and goto - > mule
Add a maven dependency.
Choose your Project-B.jar from your local repository and
add.
This will get your project imported as a maven dependency
in your pom.xml file.
Make sure your jar added under your project libraries of 'A' in
the package explorer.
Goto to the global elements of Project-A and select import
configurations.
Add the Import configuration to your elements and specify
your Project-B main XML file you want to use in Project-A.
Finally refresh/restart your main project and check if you can
reference the flows.
If you still can't get this work, try updating to the latest version of studio, like 4.3.1 which is a much stable version.
Detailed explanation is given here -> Mule Shared Projects
Update
You can also try doing the same in your cloudhub runtime. You don't need a Domain project concept to do this. Basically you kind of imported your Project-B into Project-A completely ; Altogether making it a one mashed up Mega project.

Spring boot resources properties from config dependency

So my project is dependent on some another one which is kinda shared config for several projects.
I have added it as dependency using maven. Now I can easly import classes from this depeneney project and use them.
So the question is how to copy some src/resources or test/resources files into my project or maybe I dont need to copy them but how to point to those files ? As I can import classess so this jar should be in classpath so how to point to resources?
classpath:shared_project_name.jar/src/resources/<file>
Maybe I should't use jar name?
If you are sharing stuff between several projects i suggest you check out Monorepos.

cannot find service.jar file custom portlet liferay

I am using liferay 6.2 & built a maven portlet and working fine, I want to use its tables to store data for another portlet so that I need its services in this portlet.
But we can't access it externally so i find a way something like: required-deployment-contexts=Portlet-Project1 inside liferay-plugin-package.properties, then found its works for Ant only.
I was also finding the xxx-portlet-service.jar but didn't able to, so that i could manually put it in other portlet's lib folder i.e inside tomcat-webapps-xxxportlet-WEB-INF.
Just want to find how to use xxxLocalService.util in other in maven portlet
The best approach you can implement is a plugin to manage all the interaction with the DB.
First of all you must create a Service with a maven project and include it into your pom.xml in each portlet that you need. Then you can invoke its methods whenever you want because each portlet will store the dependencies.
Create Service Plugin into jar file
Rebuild with mvn clean liferay:build-service
Custom your own methods to manage the iteraction with the DB (LocalServiceUtilImpl and rebuild).
Include this plugin into pom.xml portlets
Rebuild your portlet.
The JAR will be placed in your .m2 folder, then each time that you rebuild your Service Plugin will be updated.
If i understood your question correctly, You need to create service builder project using maven and then you can add as dependency in other project wherever you need access to use xxxLocalServicutil class.
You can follow below link to create maven service builder project.
http://www.liferay-guru.com/how-to-use-liferay-servicebuilder-archetype/
As you mentioned in your question.
was also finding the xxx-portlet-service.jar but didn't able to, so
that i could manually put it in other portlet's lib folder
To answer this, manually putting .jar file in lib directory will not help when you are working with maven project

Spring Jars to download

I am using below link for downloading spring jars.
http://repo.spring.io/release/org/springframework/spring/4.1.4.RELEASE/
I am confused with so many links.
Which link should i use to download the jar?
I am using a Windows machine and create a project directly through New Java Project.
Please refer this url http://repo.spring.io/release/org/springframework/spring/ and Choose the which version Spring Jars you want.
Choose the spring-framework-X.X.X.RELEASE-dist.zip
You should be using this link to download spring jars. Other links in there are for checksum or documentation.
Important points to understand in all the spring related repo is that it contains 3 zip files .
spring-framework-{version}-dist.zip : contains all the spring
related jars.
spring-framework-{verison}-docs.zip : contains all the standard documents in HTML format for spring and related java api documents. It is similar to Oracle API Documentation.
**Note : Inside all the folders you will find and index.html file. U can consume it typing the folder path till index.html in web browser.
spring-framework-{version}-schema.zip*: contains all the spring modules based standard xsd for xml based spring development.
I hit the same issue and I followed Brian Clozel advice above.
Create a new Maven project in eclipse.
Edit the pom.xml and add the Spring dependencies as follows -
org.springframework
spring-core
5.0.6.RELEASE
When you build the project in eclipse,it hits the maven repo and downloads the requisite spring jars for you. The indirect dependencies should also be downloaded automatically.
Hope this helps.
Step 1) Place this URL in browser
https://repo.spring.io/ui/native/release/org/springframework/spring/
Step 2) Scroll down & select latest version. Example : 5.3.9/
Step 3) Click on the file similar to "spring-5.3.9-dist.zip" to download
Step 4) Hence JAR files of latest spring is downloaded in zip format.

Resources