I started working on a Dynamic Web Project some time back and now I'm almost in the stage of finishing it. I have used a number of jars in my project which I have used by downloading the jars manually and then adding them to the build path in Eclipse
Now my requirement asks me to convert the project to a Maven Project which I did using Eclipse. The pom.xml is empty now.
Is there anyway I can automate the addition of <dependency> of the jars which I have used in my project to the pom.xml ?
Or do I have to manually search for each jar in the repo and then add its dependency in the pom.xml?
I have also customized some jars to suit my application. So I will skip adding them to the pom.xml obviously. But that jar has some dependencies on other jars which are used as it is; which can be obtained from the maven repo.
I could not find anything related to this on Google or Stack Overflow.
Related
I'm currently working on creating a Maven-Tycho build environment for a relatively large RCP project. The Maven build is already completing successfully, but I'm having trouble removing all the errors from the projects when opening all the sub-projects in the Eclipse IDE.
One of the problems that is most common is, that a MANIFEST.MF contains a Require-Bundle line that cannot be found. This is mostly because I'm using the tycho-pomless extension to reduce the number of pom files I need to maintain.
So the error that happens is, that it cannot find a dependency in the Manifest, because the project should inherit it from the parent-pom. Because it is a pomless build though, the temporary pom for the project is only existing while building the project with tycho-maven. This means that eclipse does not seem aware of the inheritance of the dependency.
I've created a minimal example HERE.
If you open this workspace with an Eclipse IDE you can see, that there are errors and the following lines in App.java have errors:
import com.github.oxo42.stateless4j.conversion.ParameterConversion;
ParameterConversion.validate(null,null);
The required dependency is in the parent pom in the root directory of the workspace:
<dependency>
<groupId>com.github.oxo42</groupId>
<artifactId>stateless4j</artifactId>
<version>2.5.0</version>
</dependency>
The dependency is also in the Manifest of module 1, but it cannot be found in the Eclipse IDE.
If you try to build the project with Maven from a shell, you will notice that the dependency inheritance is honored, even without test.module1 having a pom file and the build succeeds.
So the current state is: CLI Maven build is working, but Eclipse IDE cannot resolve the dependencies correctly making development a bit of a mess.
Is there a way around this, or will I just have to create a pom file for those specific modules?
I had a GWT app, and I wanted to automate its build and deploy system, since I do it manually. But I did not find a way how to build the app from command line, so it can than be automated. I had to click the Google button, then compile GWT project and then click Compile.
I found out that it is possible to create a GWT maven project and that it should then be possible to compile my project from commandline with mvn gwt:compile.
So I created a new project using this plugin. Copied my sources from the old project to this new one.
Now the structure is like this:
/src
---/main
------/java -> here are all my sources including my Project.gwt.xml file.
------/webapp
---/test
pom.xml
Now I have 2 problems.
1. I thought that I add dependencies to the pom.xml, and then when I build the app, it will create the jars and I can use those libraries in my GWT app. I guess 'mvn clean install' should do this, but so far I'm getting compile errors.
2. I did not get mvn clean install to work, so I added all the jars manually again... And then yes! I was able to build the app using the plugin GWT button! So I was thinking that now I can use 'mvn gwt:compile', but it fails with:
Unable to find: "com/company/project/Project.gwt.xml" on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
EDIT:
So I fixed my <moduleName> element in pom.xml, so now it finds the Project.gwt.xml. I'm trying to run:
mvn clean install gwt:compile
But I am getting compile errors. I think, it tries to build my project without the actual dependecies because it tells few classes don't exist, but those classes are part of an external library. (specifically this one). But I have it in the dependencies, so I don't know what more to do.
<dependency>
<groupId>com.github.tdesjardins</groupId>
<artifactId>gwt-ol3</artifactId>
<version>3.0.0</version>
</dependency>
Also in eclipse I had to manually add the jars to my project, so that was why it worked there and not in the command line. So I would also like to ask how to tell eclipse to get those jars and include them to the project, because otherwise eclipse is missing those dependencies and displays many errors.
First I had a problem with <moduleName> in my pom.xml was missing com.company.project prefix before the actual module name.
Then I had errors in my Java files, which was caused by RELEASE version of GWT-OpenLayers 3 library missing some of the features that I previously used by building the JAR from the GitHub repository.
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.)
Is it possible for maven plugin to manage only dependencies and nothing more.
I work with "strange" maven project, and want Eclipse/maven plugin only to read dependencies from pom.xml and add it to project classpath. And nothing more.
I don't want it to set exclusion filters, source folders and output folders, or to overwrite other dependencies.
Also, pom.xml is not located in the source folder of Eclipse project. I know I could use mvn eclipse:eclipse task manually, but it mess with my .classpath and .project files, which I don't want to merge manually.
To summary, I want that all dependencies from pom.xml are automatically managed by plugin, but for plugin not to touch anything else.
EDIT: The problem is that whenever something in pom.xml changes, maven plugin changes my project configuration.
EDIT: It has to be maven since there is already pom.xml which I can replace with sbt or ivy or lein or anything eles.
Does it have to be maven? If you don't need any of the plugins, or project organisation you could use apache ivy instead.
Or you could use a even more simple one like SBT
if you have to use maven, just strip out the plugins from the pom.xml file and only add the dependencies and repos and use an IDE to launch the aplication or create a jar.
you will need to run mvn commands thought if you change the dependencies.
I've been trying to add a custom .jar (ftp://ftp.ncbi.nlm.nih.gov/pub/eutils/soap/v2.0/java/axis2_1.5.2_jdk_6.0.12/eutils_axis2.jar) to a project that doesn't have a central corporate maven repository and that instead will have the custom JARs checked into SCM in the project directory tree. I was following this post to make it happen: Maven: add a dependency to a jar by relative path (awesome post btw).
What I did was:
Add local repository to pom.xml
install the file into the local repository
Add dependency to pom.xml
Based on what I see in m2eclipse, the library has been successfully recognized by Maven and added to the dependency list (or it'd be called ? : ? or something similar)
The problem is that Eclipse still doesn't see the referenced lib, so this still fails:
import gov.nih.nlm.ncbi.www.soap.eutils.*;
Pardon my maven newbiness, but what are changes / next steps I need to make to get to:
Have Eclipse see the library so that autocomplete works (and the import can be resolved)
Be able to compile the project
Be able to execute the jar produced by mvn package?
Thanks!
If you see the JAR under "Maven Dependencies" in your project, Eclipse should be able to see and use it. If it's not there, then m2eclipse wasn't able to resolve the dependency properly.
If it is missing, m2eclipse was unable to download the dependency from your local repository for some reason. Check the Maven 2 Console for errors and the Problem View.
Lastly, the JAR itself might be corrupt. Maven doesn't check for that, it simply adds the file to the classpath. If Eclipse can't open the JAR, you can also get the errors you mentioned.