java Spring import error - java

I've downloaded spring-framework-4.1.6.RELEASE from http://maven.springframework.org/release/org/springframework/spring/
Then I followed the Spring Website http://spring.io/guides/gs/rest-service/ to start a project,but I found there is a problem in it.
//The import org.springframework.boot cannot be resolved
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
It seems like that it can't find the jar files so can't import it,but I've add all jar files to build path.
How can I solve it? Is Spring and SpringFramework the same one?

It looks like you are trying to access classes which are part of the Spring Boot project, it might be the case that your Spring libraries do not contain the Spring Boot project related libraries.
Naturally I'd recommend for you to import it via Maven or Gradle as suggested by the Spring Boot Quickstart.
But if you want to add it manually, the latest release jar currently for SpringApplication is spring-boot-1.2.3.RELEASE.jar
Find it HERE
And the SpringBootApplication class is found within spring-boot-autoconfigure-1.2.3.RELEASE.jar
Find it HERE
So check if you have similar jars among your current ones and download them if not, also remember since you are dealing with dependencies manually, it's quite possible that these two new libraries will have dependencies of their own and you'll have to accommodate to them as well.

I had the problem that just anything in package org.springframework.boot.autoconfigure.* could not be resolved/compiled though proper jar was included in classpath.
My solution: wipe the local maven repository
Running command line 'mvn clean compile' showed me a line like
[ERROR] error reading /Users/greyshine/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.4.3.RELEASE/spring-boot-autoconfigure-1.4.3.RELEASE.jar; invalid LOC header (bad signature)
That gave me the guess that the artefact was not properly downloaded in the first run.
I wiped my maven spring boot repository artefacts (i.e located at ~/Users/MYHOME/.m2/repository/org/springframework/boot) then I rebuild with 'mvn clean compile' and it all worked.

Spring framework zip artifact you downloaded off the maven repo doesnt have the Spring boot jar, thats why its not compiling.
Download the spring boot jar and add it to your classpath.
This link has the maven dependency defined.
http://projects.spring.io/spring-boot/

I had a similar problem and fixed it by tweaking the pom.xml
from
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
to:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

As an alternative to Dirk Schumacher's approach of removing the entire local maven repo, I only remove the .m2/repository/org/springframework folder to force that part to redownload.

Related

Importing Spotify API Client Library through Maven / Eclipse

I want to use this wrapper to access the Spotify Web API using Java, via an Eclipse IDE :
https://github.com/thelinmichael/spotify-web-api-java
However, I have zero knowledge of Maven and working with external libraries. I imported this project using "File > Import > Existing Maven Projects..." and that seemed to work fine. However, I am not sure how to actually use the library / project in my code. Do I make a new user library and put the jar files into it? And if I do that, how does the Maven part of it work?
Thanks so much. I'm really struggling here.
Just like any maven dependency, you simply add
<!-- https://mvnrepository.com/artifact/se.michaelthelin.spotify/spotify-web-api-java -->
<dependency>
<groupId>se.michaelthelin.spotify</groupId>
<artifactId>spotify-web-api-java</artifactId>
<version>6.4.0</version>
</dependency>
to your dependencies in your pom.xml. Maven will automatically import the jars into your .m2 directory when you build, and you can use import them into our code the regular way

Spring - Missing Required Library - hibernate3-3.2.3.GA.jar

I was following this tutorial to understand the Spring and Hibernate. After I added the hibernate dependency like this:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.3.ga</version>
</dependency>
I got this error
Project 'SpringExample' is missing required library: 'C:\Users\gmuniandy\.m2\repository\hibernate\hibernate3\3.2.3.GA\hibernate3-3.2.3.GA.jar' SpringExample Build path Build Path Problem
.
I have downloaded the jar file and placed in the folder manually but the issue still remain. Please advice.
EDIT
I guess it is an wrong writing in thy pom.xml: Instead of "ga" use "GA" as Ragu already wrote.
Did you try already the downloadable project from the Website?
And what looks strange to me, I found no hint about case-sensitivity on maven.org, though maven uses case-sensitive match when matching against property values. Referring to Maven Model
May I suggest, that you follow this tutorial?
Accessing Relational Data using JDBC with Spring
At the bottom of the Article you will see a complete pom.xml which obtains the required and correct versions of libs from a inherited pom.
It should keep your pom short and simple. So you can better concentrate on your task rather than bothering around with libs at an early stage of your project.
Have you tried to clean up your local Maven repository and resolve dependencies again?
version is wrong -correct one 3.2.3.GA , In mvn repository you can search specific jar maven dependency.

Intelij Spring project to eclipse Not working

I have created a spring web application in intellij idea 12. and now try to configure the same project in eclipse
for that i choose export to eclipse. and when i import that project into eclipse using import project from existing source
It says full of error for spring libray file missing. I have included all the spring mvc libraries from .m2/repository (Intellij)
but it says error in import javax.servlet.http.httpservletrequest cannot be resolved
Please anyone help me to run the idea spring project into eclipse using tomccat 7. Please provide any suggestions. I am using maven
Thanks in advance
HttpServletRequest is a part of Java servlet API. You can use different dependencies to resolve that. In your case, I think the best choice will be
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
It's avaliable from maven central repository. Because, as you said, you're using maven, all you need to do is to put dependency described above to your pom.xml
I have included all the spring mvc libraries from .m2/repository (Intellij)
I'm not sure you're resolving your dependencies via maven. ".m2/repository" has nothing to do with Intellij, it's your local maven repository.
Install the plugin m2e to manage maven project into eclipse m2e
Using "import project from existing source" will not manage the dependencies store into maven

Can't run the google-api-java-client samples in eclipse

I'm trying to run the YouTube JSON-C Sample in eclipse. I have followed the instructions in the link and I managed to run it in the command line using mvn -q exec:java, but when I import the project to eclipse (I use eclipse indigo), it says that "The import com.google.api.client.googleapis cannot be resolved", and gives me compiler errors in every line that is related to the api. Is there some other configuration that needs to be done? Specifically adding google-api-java-client-1.5.0-beta jars to the build path?
Ok I finally solved the problem. What did the work for me was to execute mvn eclipse:eclipse on the project folder in terminal...
You need to check if you are pulling out all the dependencies in pom.xml from the repository:
<dependencies>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.5.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.5.0-beta</version>
</dependency>
</dependencies>
Check the settings.xml file in the Maven installation directory if it is pointing to a global repository or if you have hosted your own Nexus/Sonatype repository then make sure that your settings.xml points to that and also you must have the above two jars in your repository.
Or if you just want to get the project up and running, then instead of importing as a Maven project, just import it as a normal Java project and manually add the two libraries to the project's classpath. That should at the least get you started with the project without worrying about the Maven stuff.

Created Simpl JAR file, imported to Maven project but Maven install is complainining "package does not exist"

I guess I haven't really had to do this much before because I am running into a strange issue. I am trying to generate a JAR from an existing Java project and then and putting it into a Spring Maven project. I'm sure I'm including it correctly, I have done this many times before with 3rd party JARs that I get (even though its a Maven project I have included some obscure JARs in it and put on buildpath, etc), with my JAR within Eclipse it is showing up fine as if its included, I have a test class that is importing a class from the JAR, instantiating it, etc and its not showing any errors (imports are fine in the IDE, etc), however when I go to do a Maven install I get:
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[11,15] package org.test does not exist
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[21,2] cannot find symbol
I have tried doing a Maven clean but still the same problem, the JAR class I am testing with is this: (was trying a more complex one but then tried this to troubleshoot the issue)
package org.test;
public class something {
public String main () {
return "it is definitely working fine";
}
}
Here is the JAR I generated (with sources visible):
https://docs.google.com/leaf?id=0BzB_xvrbRpbYODQyMjEzOWEtOTdjNS00YjM3LTlkZGUtNjY5NmIwN2RiNTRj&hl=en
I would appreciate any advice as I am rather perplexed and frustrated by this. Thanks
You can include a 'regular' jar in your maven project -just as you described- though it's not a best practice mainly because then you not even lose the functionality of Maven for that jar, but also the whole point of Maven dependency management: you will have to include that jar with your source to make it build.
You can of course also create a Maven artifact for that jar, build it with Maven, install it with Maven and use it as a normal Maven dependency.
You also can create a parent .pom and have your dependency project as a module in it and also your real application (or also your real app can be your parent). See further here.
Since this caused me quite a bit of grief, I figure I should post the solution I found. Apparently you aren't supposed to just include a regular lib JAR in a maven project (although I swear I have done it before and it worked), I found this way to include a local JAR that isn't form a repository from this post:
Can I add jars to maven 2 build classpath without installing them?
I did this and its doing the maven install properly (where version and artifactID are just made up value)
<dependency>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/testjar.jar</systemPath>
</dependency>

Categories

Resources