Not able to get directory structure and Maven dependencies - java

I have checked out a Maven project from Subversion. It has Java with Spring framework and Groovy.
We are using Groovy Eclipse compiler plugin. On Maven install, code compiles perfectly with Groovy Eclipse compiler and a jar is created in target.
But there is no directory structure which is usually created in Maven. No classpath too.
I tried many things nothing worked. Finally I converted project to faceted form and then src/java was created as it was faceted to Java project. Still no Maven dependencies.
As there was no Maven dependencies, many jars were missing, so I added jars to build path manually. I also added src/groovy to build path and then it was not able to compile Groovy classes, so I configured project as Groovy project and DDSL was generated. Now after so many manual settings, it is not working fine when it has to create object using spring for Maven class.
I tried a project without Spring framework, and it worked fine.
For pom.xml: I have referred: http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html.

Related

Combining a maven project with a java project

Currently, I have a maven project that has a server running (using Jersey REST API). I also have a java project, I need to move all the contents of the java project into the maven project. The maven project is a subset of the java project. However, the maven project only displays the parts of the java project. However, I want a project that allows me to use maven and displays all of the other details from the java project.
I would've copied and pasted however I'm using git so I want to also preserve history.
I was thinking it would be easier to nest the maven project inside the java project but I don't know if that's possible.
Here's a picture of my package explorer to help explain everything.
Package explorer showing the maven project being a subset of the java project.
What I've tried is converting the java project into a maven project and then updating the pom.xml but then it doesn't link to the web.xml. Also, it tries to run the server with the name of the project name TeamProject. When infact it should run the url with the name client_server
I was considering just copying and pasting all the code into the maven project (from the Teamproject java project).
Actually nesting the java project inside the Maven project makes more sense, as it is the purpose of Maven to handle a project lifecycle. (also by default Maven will look for sources in the src/ folder which should ease the task of putting your Java project inside Maven's hands)
There are several possibilities I would see:
Copy your java project in the src/ of your client project and update maven accordingly (within the pom.xml)
Make your Java project a Maven project and aggregate the two projects in a parent pom (see Multi module maven project example)
Make your Java project a Maven project, and decide of a "Master" project between it and the client and compose one with the other (not sure that's a great solution)
Nesting your Maven project inside the Java project would not be so great because Maven could only handle the client and not your Java project, and then you'd miss on numerous functionalities offered by Maven (just look at how simple it is to get dependencies compared to downloading a jar and including it on the build path manually)

Maven Jar dependency is not coming automatically

I am quite new to Maven.
I have a Maven Project.
When I create execute using mvn clean -e install it creates executable jar (commounutil.jar) for my project in target folder.
Not I have another project (project2) in Eclipse which is not a Maven based project.
Project2 uses features and classes from commounutil.jar.
If I manually add my executable jar commounutil.jar in eclipse using Java build path/add external jar.
But even after adding this jar there are some errors in my project which are related to log4j.
Now when I build commounutil the dependency for log4j was already added.
Still it is giving compile time error.
Could you please tell me where I am going wrong?
Add log4j in your Eclipse classpath. Commonutils.jar,if it follows modularity promoted by maven,provides only common utils class and do not provide class related to its dependencies.
Maybe you should consider to update your second project to a maven project.

Eclipse m2e plugin stopped changing classpath to add dependencies

I have used the m2e plugin in luna 4.4.1 for a while for handling dependencies and it worked fine. Normally, I create new Java projects then convert them into a Maven project.
I decided I wanted to start using the standard Maven directory layout, so for my most recent project I created it as a Maven project and then added the Eclipse Java facet so that Eclipse would treat it like a Java project.
This has broken Maven, so that it is no longer making it's dependencies available to new projects. Normally, Eclipse adds a "Maven Managed Dependencies" library to a project with Maven dependencies; new projects no longer do this and the dependencies are never added to the project classpath. Projects that had been working before still add and remove them normally.
I have narrowed the problem down to a .classpath error; for some reason m2e has stopped modifying the project classpath to make it's dependencies available. I can work around it by manually copying and pasting the entries from a working project but I would like to find a way to "re-automate" it correctly.
I have sidestepped the issue by finally buckling down to learn Gradle.

How and where does a pom.xml will be configured to be invoked by a web project

I have been working on maven for some time but never had this question before, Many times I created my maven project using a IDE wizard which helps me to create a maven project which has pom.xml pre-configured or the other way is to convert a general java project into maven project which generates a pom.xml. I have a question what exactly happens in the background when we convert this java project into a maven project. What will be configured and how does the java project detects it has a pom.xml.
Inside the .project file in the root of the Eclipse project, m2eclipse will add the org.eclipse.m2e.core.maven2Nature to it. This tells Eclipse that the m2e plugin will handle various stages of the project lifecycle, and m2e has a hybrid partially-internal and partially-external engine that applies the instructions in the pom.xml to the project. (For example, it finds the classpath placeholders that are marked as maven.pomderived and replaces them with the appropriate Maven dependencies.)

Integrating a maven project into Eclipse

I have a maven module for validation which I must pass to a old version of Eclipse which has the Jrules API within. However there is not a maven plugin for this eclipse IDE. So I figured I would do a maven:install on the module and move over the created jar.
However when I try to import->Existing Projects into Workspace->Select archive file:
and point it to the jar no projects appear. I'm at a loss as to how I can move my maven module to the outdated eclipse, without having to grab the 101 jars required for the project and non mavenise it...
Surely their has to be an easy way to this or is maven will monolithic
Use the maven-eclipse-plugin to generate the .project and .classpath files for you:
mvn eclipse:eclipse
This will create the IDE metadata files which reference all of the JARs your project depends on from within your local maven repository folder.
Attempting to import the JAR that is built by the Maven build process into Eclipse using the " import->Existing Projects into Workspace->Select archive file" doesn't work because Eclipse expects to find a .zip/.jar file with the .project metadata files and the source code. Your compiled JAR likely contains neither.
I would recommend using the M2Eclipse maven plugin. Right click the project -> Enable Dependency Management -> Update Project Configuration
I have used eclipse:eclipse extensively and my experience is that M2Eclipse is not only better supported but works better overall.

Categories

Resources