I recently set up a j2ee development environment under Ubuntu: Eclipse (Helios) with the maven plugin (m2eclipse).
When I try to create a maven project, it tells me to select an "Archetype".
Then, I select an Archetype with a GroupId : "org.apache.maven.archetypes" and the
ArctifactId : "maven-archetype-quickstart" (I tried also with the followinf artifactIds
"maven-archetype-mojo" "maven-archetype-j2ee-simple", ....).
Then, it creates a standard maven directory structure.
I added the "javax.perssitence" Maven Dependency that load the "persistence-api-1.0.jar".
But I can't find the "src/main/ressources" and "src/test/ressources" to access to the "persistence.xml" file.
Is it a bug? Should I create it manually?
Thank you for your answers ;)
No, it's not a bug, just create them manually and update the project configuration under Eclipse (via right-click on the project and Maven > Update Project Configuration)
Related
I create a simple sample Spring MVC project, where IntelliJ 14 by default generate a pom with
<properties>
<spring.version>4.1.4.RELEASE</spring.version>
</properties>
I change it to
<properties>
<spring.version>3.2.0.RELEASE</spring.version>
</properties>
and choose Maven -> Reimport, I can see the dependencies are downloaded to my local .m2 folder
However, when I expend lib folder, all dependencies stays with previous version:
How can I get the latest dependencies showing in \lib folder? I tried to synchronize current project, but it doesn't help this matter
UPDATE
here is my maven setting
UPDATE 2
I forget some detail, which is I create a Spring MVC project in the beginning(so I think it may not be a maven project at the moment), then I right click pom.xml and set current project to maven project.
So I think the jar files listed in \lib folder may be downloaeded via intellij for Spring MVC application, however when I set current project to maven project, it does not remove or update the jar file under the \lib folder.
You should do:
1. Choose menu File \ Project Settings..., In section Build, Execution, Deployment \ Build Tools \ Maven \ Importing, check Import Maven projects automatically. It means IntelliJ IDEA will Synchronize Maven project model and IDEA project model each time when pom.xml is changed.
2. Try closing project, restart IntelliJ IDEA, then reopen the project.
3. Check your internet connection.
IntelliJ isn't shouldn't be looking there for your Maven project dependencies. It is should be using the libraries and resources in your .m2 directory instead.
Mind you, I've left those comments struck out on purpose; depending on your configuration, you may accidentally be doing that.
This is a picture of what the Dozer project looks like. It's a Maven project which I cloned a ways back to see how it worked.
You're going to have to check your Project Structure (Ctrl + Alt + Shift + S) to ensure that the libraries that are coming through are prefixed with "Maven:".
If they are, then the files in your lib folder aren't being used by your project.
In all actuality, those are your global libraries (which you can also find under Project Structure > Global Libraries). Any project has access to them.
If that's causing a conflict, consider deleting those JARs from your global libraries. If you need them for another project, consider adding it to the project's local libraries instead.
I created a Maven project and imported it in Intellij IDEA.
In a run configuration, there is a field "working directory", which points to the root of Maven project.
If I change this folder, it doesn't seem to affect anything. So what is it?
This is the directory that is set as the Java user.dir system property. If you have any code that creates relative files or directories, it will be relative to this directory. So for a well designed application (i.e. resolves resources from the classpath and is configurable for output directories) this will not be a factor. There is also some importance to this value in maven projects, especially multi-module maven projects. This directory specifies the directory IDEA will read the POM from.
If you are unflamilar with what the Java user.dir is, there is some discussion available here and in the class level Javadoc for the File class.
In addition to answer given by #Javaru if you want to update or view your working directory in IntelliJ IDEA go to:
Run | Edit Configurations | Configuration Tab | Working Directory
From the IntellJ help Run/Debug Configuration: Maven
Working directory Specify the path to the Maven project file pom.xml.
I am using Maven with Nexus for building my project with hudson ci. Everytime when I am deploying a new snapshot artifact he is doing this with a unique version in nexus. Which is OK for me as Nexus is giving me always the latest version.
Now I looked into the war file of my project which is using this snapshot dependency and its having the following jar file in its lib directory which is absolutely not fine:
framework-client-1.1-20120302.141044-3.jar
The problem is that I am using EBean as an ORM and I need to specify the jar name in the ebean.properties to let him know where to find its models.
How can I prevent such behaviour so that the latest snapshot dep is always call framework-client-1.1-SNAPSHOT.jar?
Thank you!
Just rename the jar in the war file to whatever name you like. Details are here
Renaming Maven dependency in WAR's WEB-INF/lib folder
I mean is there a possibility to run some maven command to add new module to existing project , or manually create folder and needed changes to pom.xmls ?
If you are using archetypes, mvn archetype:generate will create subproject's POM and structure, and will also set it as a module of the current project.
If you are working with Eclipse (m2eclipse) you can add a maven-module via Eclipse (NetBeans and IntelliJ should work the same way) otherwise you have to do that manually...editing the pom and create the folder and put stuff into the new module.
To add to #khmarbaise's answer,
If you are using Idea, right click on your project's name on (Project view perspective) and New > Module. Select maven and follow the wizard.
If you want to create a new module in eclipse then do follow below steps:
Right click on root project. and select maven -> New maven module project
[1]: https://i.stack.imgur.com/DdPcP.png
but parent project must be pom project like add pom in your pom.xml of root project if you face any error.
How to convert a Ant project to Maven project? A sample project that would link (a Wicket project)
Thanks
The nice part of using maven is that most standard stuff works automatically once you do things the maven way. For a simple webapp:
Create a pom with groupId, artifactId and version (packaging: war)
Add the required dependencies to the pom
move the
java sources to src/main/java,
resources to src/main/resources,
webapp content to src/main/webapp,
test content to src/test/java and src/test/resources
set the compiler compliance version using the maven compiler plugin
That should get you up 'n' running.
http://www.sonatype.com/people/2009/04/how-to-convert-from-ant-to-maven-in-5-minutes/
I don't know what your ant script looks like, but assuming its a basic script for building, you will need to create a pom.xml file for your project, add your dependencies, and then build it via maven.
For anyone who lands here in future, there is an easier way to find dependencies for maven using the file hashes. So, you won't have to guess artifact versions.
As per the below article, the idea is to generate a SHA1 checksum of the dependency that you want to find the information, then do a reverse search in Nexus repository manager using that hash. For the checksum generation, you can use Microsoft's FCIV (free) utility.
https://devreads.xyz/ant-to-maven-conversion-the-painless-method/