I used Maven to generate a Jersey project from command line, and I also used mvn eclipse:eclipse so that I can import my project to eclipse.
After I opened the project from Eclipse I see all the jars were in the root folder, how do I create a folder or package so that I can move all these jars into it?
Don't use mvn eclipse:eclipse.
Just do File -> Import -> Maven -> Existing Maven projects and browse the folder where your pom.xml is and Eclipse will organize everything for you.
It looks like you aren't using Maven eclipse integration - m2eclipse. You shouldn't have to install it, it comes already with more recent versions of Eclipse, though follow the instructions in that link if you don't yet have it.
If you just generated the project, try deleting it and then generating it again inside eclipse with New -> Other -> Maven Project. If you have a lot of code written already, instead right click on the project and do Configure -> Convert to Maven Project. Once you've done that, you may have to do Maven -> Update Project project to straighten out your jars, and possibly remove them manually with Build Path -> Configure Build Path.
However, I recommend creating the project from within Eclipse, if possible.
Addendum: #cahen's answer is also correct; don't use mvn eclipse:eclipse.
Related
In an eclipse project, I referenced a class that was currently not in project's build path.
In the context sensitive pop-up that opens by hovering the mouse over the error, "Fix project setup" option has offered me to add a jar to the build path of the project. This jar is in my local maven repository.
However, the "correct" way to fix it is obviously by adding the relevant dependencies to my project's pom, instead of adding this jar to the build path of the project.
So is there a way to configure eclipse, so that it won't offer to add a maven repo jar to the build path, but it will offer to fix the project's pom?
This feature used to exist in m2eclipse (the predecessor of m2e), see e.g.
https://blog.sonatype.com/2010/03/adding-dependencies-using-m2eclipse/ which shows a "Search dependency for XXX" quickfix above the "Fix project setup..." quickfix.
Unfortunately it didn't make it into m2e, see https://www.eclipse.org/lists/m2e-users/msg01130.html
Make sure:
your project is fine outside of eclipse using only maven/pom, mvn
clean install (or similar) in an external shell/console
your eclipse project has maven nature
Eclipse -> Project -> Build Automatically is checked
Refresh your eclipse project
Do something in the pom.xml (save file) should trigger a build
why do I need to apply: mvn eclipse:eclipse command?
are they equivalent to application container/server?
Is there a file for which customizing is necessary besides web.xml?
when you create a web project using maven, like maven-archetype-webapp. It creates the folder structure as recommend by Maven for a webapp like shown here .
Now when you try to import these folders in Eclipse, it still would look like folders but eclipse cannot understand the nature of these folders. Eclipse relates folders and contents within them to an Eclipse dynamic web project only through its .project , .settings files
So in order for your maven project to be understood by Eclipse, you run the goal mvn eclipse:eclipse. After executing this goal, maven generates the .project, .settings files necessary for eclipse to understand the project as Web project.
This is however optional. You can still import the project as Maven projects within eclipse and continue to use them but you cant rely on Eclipse's features like clean/ build / build automatically.
Though I use eclipse, I dont rely on Eclipse's build feature. I have installed Maven eclipse plugin and that allows me to run maven goals and commands within Eclipse which is as good as running Eclipse's build feature. Hope this helps.
I am learning building a Java project in Eclipse using Maven. I created a Java project HelloWorld from
“maven-archetype-quickstart” template in a folder D:/maven_projects. Then to convert the Maven project to support Eclipse IDE, I navigated into the project folder and issued the commands:
mvn eclipse:eclipse and mvn package .
Then I imported the project in Eclipse and did the necessary Eclipse configurations like setting the Maven local repository in Eclipse classpath. Now the project in D:/EclipseWorkspace folder. I ran the project successfully in Eclipse printing "helloworld".
Now if I want to go on develop the project and for that reason want to add new dependencies in pom.xml in Eclipse, then the new jars are not added in classpath when I run the project.
So my question is after importing a Maven project into Eclipse how can I add more and more dependencies in pom.xml, then build and run the project? What is the recommended and efficient way to do this?
I would recommend you don't use the m2eclipse command line tools (i.e. mvn eclipse:eclipse) and instead use the built-in Maven support, known as m2e.
Delete your project from Eclipse, then run mvn eclipse:clean on your project to remove the m2eclipse project data. Finally, with a modern version of Eclipse, just do "Import > Maven > Existing project into workspace..." and select your pom.xml.
M2e will automatically manage your dependencies and download them as required. It also supports Maven builds through a new "Run as Maven build..." interface. It's rather nifty.
1.Update project
Right Click on your project maven > update project
2.Build project
Right Click on your project again. run as > Maven build
If you have not created a “Run configuration” yet, it will open a new configuration with some auto filled values.
You can change the name. "Base directory" will be a auto filled value for you. Keep it as it is. Give maven command to ”Goals” fields.
i.e, “clean install” for building purpose
Click apply
Click run.
3.Run project on tomcat
Right Click on your project again. run as > Run-Configuration.
It will open Run-Configuration window for you.
Right Click on “Maven Build” from the right side column and Select “New”.
It will open a blank configuration for you.
Change the name as you want. For the base directory field you can choose values using 3 buttons(workspace,FileSystem,Variables). You can also copy and paste the auto generated value from previously created Run-configuration. Give the Goals as “tomcat:run”. Click apply. Click run.
If you want to get more clear idea with snapshots use the following link.
Build and Run Maven project in Eclipse
(I hope this answer will help someone come after the topic of the question)
Dependencies can be updated by using "Maven --> Update Project.." in Eclipse using m2e plugin, after pom.xml file modification.
Just install the m2e plugin for Eclipse. Then a new command in Eclipse's Import statement will be added called "Import existing maven projects".
answer 1
Right click on your project in eclipse
go to maven -> Update Project
answer 2
simply press Alt+F5
after updating your pom.xml. This will build your project again and download all jar files
Right Click on your project
Go to Maven>Update Project
Check the Force Update of Snapshots/Releases Checkbox
Click Ok
That's all. You can see progression of build in left below corner.
When you add dependency in pom.xml , do a maven clean , and then maven build , it will add the jars into you project.
You can search dependency artifacts at http://mvnrepository.com/
And if it doesn't add jars it should give you errors which will mean that it is not able to fetch the jar, that could be due to broken repository or connection problems.
Well sometimes if it is one or two jars, better download them and add to build path , but with a lot of dependencies use maven.
If you are getting this error :in cucumber Exception
Cucumber Exception: java.lang.ClassNotFoundException:
cucumber.io.ResourceLoader :
then add following jar file to your pom.xml
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.8</version>
</dependency>
Run the maven build once and should be gone
I am trying to add java code from a Maven project (called docx4java) which I checked out from svn to an existing Eclipse project (called DocumentManager). I have tried the normal way, that I thought would work, i.e.:
Right Click on eclipse project>Properties>Java Build Paths> Projects > Add (here I add the Maven project) and >Libraries (here I specify Native Library location e.g. docx4/trunk/docx4/src/) but I still can't get the 'Maven' classes to be recognised in eclipse. I get the message
import docx4j.src.main.java.org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator cannot be resolved
I have tried adding a test project that was compiled in Eclipse and that works fine, Eclipse seems to recognise it i.e. import org.me.TestProject works fine.
How can I get the code from the Maven project docx4java to work in the Eclipse compiled project DocumentManager?
You can generate eclipse poject files (which you can just import into your Workspace) using the maven eclipse plugin
Take a look at these ecplise plugins for a more direct integration of maven into eclipse
You should create a eclipse project for docx4java as #Attila has commented. Once that is done, you should have two projects on your workspace: docx4java and DocumentManager. At this point, what you are doing now (adding a project reference to the Java Build Paths) should work.
It seems that the source path is not configured correctly, this is why the compiler cannot find your "Maven classes".
docx4java.src.main.java...
Maven has a different directory structure and you have to tell Eclipse where to find your sources.
For a "vanilla" eclipse project, remove the standard eclipse build path src and add the maven source path src/main/java (or whereever you added the code), the compiler should correctly pick up your sources.
Note that you still have to add all jars mentioned in the dependencies section of the maven pom.xml file. Otherwise it won't compile, even if it finds your added java classes.
(Addendum: I would recommend to use maven in your existing project as well.)
I am currently working on a Java project within a team of 5 colleagues for university. Actually, we will finish the planning phase within the next few days and then start implementing.
For the project, we have to use Mercurial (via Bitbucket.org) and Apache Maven. We'd like to use Eclipse as IDE. I know how to use Mercurial, and I've read some articles and guides about Maven. The thing I don't understand is how we should use those tools in collaboration.
What should be placed on the repository? The whole Eclipse project? Or just the source files and Maven's pom.xml? If the latter, how would a working session look like? Pull the files, create an Eclipse project with mvn eclipse:eclipse, code a while and commit/push them to the repo?
I am responsible for creating the project structure, so my colleagues - and me too - can start developing. But I really don't know how to start now. If the use of Maven wasn't obligatory, I would just place the Eclipse project into the repository. But having to use it, I'm quite confused now how if affects everything.
I use a similar setup, except I am using Dropbox for my repository (just two developers). Just follow these steps, with the m2eclipse (update site: http://m2eclipse.sonatype.org/sites/m2e) and the MercurialEclipse (update site: http://cbes.javaforge.com/update) plugin you can do all in eclipse.
Create a maven project:
File -> New -> Other -> Maven project
In Project explorer right click on the new created maven project
Team -> Share Project... -> Mercurial -> (leave the folder as it is) Finish
Then create an .hgignore file in the project root:
In Project explorer right click on the new created maven project
New -> File -> File Name: .hgignore and Finish
.hgignore:
syntax: regexp
target # maven output
\.classpath # eclipse
\.project # eclipse
\.settings # eclipse
test-output # eclipse junit/testng plugin output
Then you can make your first commit, but beware, hg does not store empty folders in it's repository, so to keep the maven folder structure with no source code in it you have to put a (empty) file in each empty folder, for a simple maven project without any sources it would be in the folders:
myproject/src/main/java
myproject/src/main/resources
myproject/src/test/java
myproject/src/test/resources
For example I put a file with the name .empty in it with the content "this is a placeholder file, remove if other files are in this folder"
If some of this folders are missing your colleagues would see errors in eclipse if they import your project.
First commit:
In Project explorer right click on the new created maven project
Team -> Commit... -> Select all and enter a commit message -> Finish
Now you can clone it to bitbucket (I don't have experience with bitbucket).
Tell your colleagues to install the two eclipse plugins and then they can get the repo via
File -> New -> Other -> Check out Maven Project from SCM -> enter url to your repo -> Finish
And then you are good to go.
Here are alternatives based on practices at the ASF (though we don't use Mercurial).
To begin with, set up a source tree with Maven build that you check into Hg. Don't touch eclipse yet. You'll want to find some Eclipse plugin for Hg.
Then, look at two alternatives: the maven-eclipse-plugin and M2eclipse.
The maven-eclipse-plugin is a maven plugin. You run it from command line, and it generates .project and .classpath and some of .settings. It's not currently being worked on, but it's quite stable and functional in many common cases. You then import 'existing Eclipse project' and you are good to go.
M2Eclipse is an Eclipse plugin that integrates Maven builds. It's quite ambitious. However, it's current avatar is quite new, and can be full of surprises.