Intelij Spring project to eclipse Not working - java

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

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

What is the equivalent of adding a jar to deployment assembly in maven

I am working with a maven project in eclipse which I have been testing using the built-in "run on server" tomcat option. When I try to do this, I get errors stating certain dependencies are unmet from an external jar I reference in the POM. However I have found if I add the jar via the DeploymentAssembly Tab I can run in eclipse without issues:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.company.user.server.UserDetailsAuthoritiesMapper#0'
The issue comes when I try to deploy on an actual tomcat instance. The Maven build runs fine, but when I start the servlet I get the same unmet dependency errors. This to me is indicating that the external jar is not being properly packaged into the war. What is the maven equivalent of adding the package via the DeploymentAssembly tab in eclipse? The entry in the POM.xml:
<dependency>
<groupId>com.company.webapp</groupId>
<artifactId>webapp-user</artifactId>
<version>106</version>
</dependency>
Thanks
You need to locate the maven info for the external jar. If you google the name of the jar and maven you often find a direct link to the block you need. For example if I want version 1.58 of the Bouncy castle jar Google "Maven BouncyCastle" you can find the artifact info. Add that info to your pom.xml as a new dependency in your block.
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.58</version>
</dependency>
After you rebuild, refresh maven in your IDE 1st after doing a clean, this will tell maven to pull down the jar and added it to your build.
You can also go to the repo directly and search:
Maven Repo: https://mvnrepository.com/

Servlet referencing a Maven project - NoClassDefFoundError

I have a Maven project that uses Hibernate and PostgreSQL, and it's working fine on it's own. Now I want to use some classes from this project (essentially the database) in a servlet, but now things break.
I get a java.lang.NoClassDefFoundError: javax/persistence/Persistence error when accessing the servlet in Tomcat.
I'm thinking that somehow the Maven dependencies don't get "forwarded" to the servlet project, but I don't know what to do about it. I've added the Maven project to the servlet build path, and also to its "Web Deployment Assembly"... what more do I need to do?
Please try this dependency.
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final-redhat-3</version>
</dependency>
1.Check for all the jars, make sure that all the dependencies are added.
2.Clean your tomcat
Try adding Runtime dependencies.
3.Right click on your project and select Properties-> Deployment Assembly
click on Add
select Java Build Path Entries
select Maven Dependencies
Finish
Re-run your server.
Hope this helps!!

java Spring import error

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.

How to use apache wicket extensions?

I want to use the AjaxFallbackDefaultDataTable in wicket to view my data but these imports are showing error in eclipse :
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
I guess I should be downloading an extensions jar file from somewhere but I don't know where at, and the Apache wicket website is vague regarding this point.
I am using eclipse with maven plugin and wicket 1.5RC1
You can get the wicket-extensions library from the maven repository. This site shows assorted versions and allows you to retrieve it by just downloading the jar or by using various build tools including of course maven.
Maven is a good tool for dealing java dependency management, and wicket quickstart is useful for starting wicket projects with a maven setup.
I simply added the following lines to the pom.xml file to add the extensions dependency .
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>1.5-RC1</version>
</dependency>

Categories

Resources