Access CQ5 project bundles on same instance - eclipse

I have two project bundles my local CQ/AEM server. Project A contains some java Util class methods which can be utilized in project B as well.
While developing, how do I import my project A classes in project B to access the methods so that I do not have to duplicate the methods again?
I tried adding dependency in my Project B bundle pom.xml as below. Is this correct?
<dependency>
<groupId>com.project-a</groupId>
<artifactId>cq-project-a</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
I get missing artifact error for this.
"Missing artifact com.project-a:cq-project-a:jar:1.0-SNAPSHOT"
Please suggest how the import can be done.
Thanks

I guess you forgot to build project a using mvn install. The dependency will be searched in your local maven repo.

This solution may fix you issue: update your pom.xml on project a, modify groupId, artifactId, version, packaging tags and make sure they look likes:
<groupId>com.project-a</groupId>
<artifactId>cq-project-a</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
Then run mvn clean install on project a, run mvn clean install one more time one project b. I applied this to my last project, I hope it works for you.

Related

Eclipse maven not adding dependencies

I am new to maven and am experiencing difficulties while trying to mavenise a Java project.
Setting:
IDE: Eclipse Oxygen.2 Release (4.7.2)
Java: 8
m2e: 1.8.2
What I did:
- copy-pasted the entire original java project and renamed it
- right-click in eclipse: Configure > Convert to Maven project
- in java build path, deletion of libraries import from original local lib repo. The build path shows the Maven Dependencies folder, with the only junit library.
- maven install => downloaded things in the user/.m2/repository/, but not all.
What does not work:
When I try to add a dependency right from a file:
,
nothing pops up in the artifact selection windows, even though there is a commons-logging/ folder in m2/repository
When I try to add the dependency manually in the pom.xml:
<dependency>
<groupId>org.kie.modules</groupId>
<artifactId>org-apache-commons-configuration-main</artifactId>
<version>6.5.0.Final</version>
<type>pom</type>
</dependency>
but the package resolution error still appears in the java file, and I get this warning after Maven install
`[WARNING] The POM for org.kie.modules:org-apache-commons-configuration-main:pom:6.5.0.Final is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details`
I did Maven Update project, eclipse project clean, nothing changes.
My goal for now is just that eclipse understands (at least for one library), that it has to take it from maven repository. I still have many other dependencies to solve (intra-project), but that will be the next step.
Thanks for your help.
The cause of the issue is stated in the warning message :
[WARNING] The POM for
org.kie.modules:org-apache-commons-configuration-main:pom:6.5.0.Final
is invalid, transitive dependencies (if any) will not be available,
enable debug logging for more details
It means that the pom.xml downloaded in your local maven repository exists but is not valid.
Delete the folder of the dependency downloaded in your local maven repository and try again.
If you still have the same problem, check that your central repository that provides the dependency provides also correctly the pom.xml for that.
You can do it by browsing the directory of the dependency from a web browser.
For example we can see that the maven central repository provides a valid pom :
http://central.maven.org/maven2/org/kie/modules/org-apache-commons-collections-main/6.5.0.Final/org-apache-commons-collections-main-6.5.0.Final.pom

JBoss Fuse Workspace Reference

I have created a JBoss Fuse Camel integration project and I can deploy it as a Profile on the Karaf Server using fabric8:deploy. The project is running fine so far.
Now I want to create a new Profile to do some other tasks. In oder to avoid double code, I wanted to create a Commons Project and add common code into this. But i cannot figure out how to add the dependency so that fabric8:deploy will still work and also deploy the commons library on BOTH profiles.
How should I add the commons project to both projects pom.xml?
I tried to add it as a normal dependency:
<dependency>
<groupId>com.my.project</groupId>
<artifactId>common-tools</artifactId>
<version>1.0.0</version>
</dependency>
but i'm getting this error when i want to deploy it via fabric8:deploy:
The POM for com.my.project:common-tools:jar:1.0.0 is missing, no dependency information available
and
Failed to execute goal on project inbound: Could not resolve dependencies for project com.my.project:inbound:bundle:1.0.1-SNAPSHOT: Failure to find com.my.project:common-tools:jar:1.0.0 in https://maven.repository.redhat.com/ga was cached in the local repository, resolution will not be reattempted until the update interval of red-hat-ga-repository has elapsed or updates are forced -> [Help 1]
The message indicates that your common-tools project could not be found in the maven repositories. Do you have it in your local maven repo? Have you done a:
mvn clean install
for the common-tools project?

Eclipse cannot find class com.google.common.reflect.TypeToken?

My project which uses Dataflow compiles just fine using
mvn compile
However when I import my project into eclipse, eclipse is unable to build the project and gives the following error
The project was not built since its build path is incomplete.
Cannot find the class file for com.google.common.reflect.TypeToken.
Fix the build path then try building this project
Adding an explicit dependency on Guava to my pom file appears to have fixed the problem.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>[18.0,)</version>
</dependency>
By running
mvn dependency:tree -Dverbose -Dincludes=com.google.guava
I learned that I had several dependencies that were pulling in Guava so by adding an explicit dependency I was able to force maven to pull in a newer version.
However, I don't know why running 'mvn compile' on the command line worked.

Maven add custom multiple jars from folder

I have a custom list of jars around 40 jars in a libs folder. I want to add all as a maven dependenices.
+ project
pom.xml
+ src
+ libs
Is there any way by that add all jar at a time.
Maven manages dependencies rather different than just including jars.
Essentially if you have a dependency on A and A uses B, you will need to have both A+B in your lib folder, but only A in your maven project, because maven transitively will include the subdependencies.
You should probably look through the maven repository, and see if you can find the jar files there in a similar version, and include that instead.
i.e. if you have commons-collections4-4.0.jar, use http://search.maven.org and write commons-collections4, and you will see a list of candidates. probably some with multiple version. Note, maven uses a groupId to scope jar files, so pick one with a suitable groupId, in this case org.apache.commons (Since commons-collections is an apache.org project).
When you have identified your dependency, it will show you ways to include it in your build, e.g. for maven, it would be
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
Looking at the pom file, you will be able to spot potential subdependencies, but otherwise, once you have added the dependency to your <dependencies/> section of your pom, run a mvn dependency:tree or mvn dependency:list to see how dependencies are transitively included.
Should you end up with libraries you cannot find in maven central, read this guide for the rest http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Found one wonderfull plugin to achieve this task. addjars-maven-plugin

m2eclipse error

I am developing a web application with Eclipse and I generate the project with a maven archetype.
When I enable maven dependency management, Eclipse mark some errors in the pom file, this error is:
Multiple annotations found at this line:
- Execution default-testResources of goal org.apache.maven.plugins:maven-resources- plugin:2.4.3:testResources failed:
Plugin org.apache.maven.plugins:maven-resources-plugin:2.4.3 or one of its dependencies could not be resolved: Failed to collect
dependencies for org.apache.maven.plugins:maven-resources-plugin:jar:2.4.3 () (org.apache.maven.plugins:maven-resources-
plugin:2.4.3:testResources:default-testResources:process-test-resources)
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
(execution: default-compile, phase: compile)
- CoreException: Could not get the value for parameter compilerId for plugin execution default-compile:
PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be
resolved: Failed to collect dependencies for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2 ():
ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.maven:maven-plugin-api:jar:2.0.6:
ArtifactResolutionException: Failure to transfer org.apache.maven:maven-plugin-api:pom:2.0.6 from http://repo1.maven.org/
maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or
updates are forced. Original error: Could not transfer artifact org.apache.maven:maven-plugin-api:pom:2.0.6 from/to central (http://
repo1.maven.org/maven2): null to http://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-
api-2.0.6.pom
- CoreException: Could not get the value for parameter compilerId for plugin execution default-testCompile:
PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be
resolved: Failed to collect dependencies for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2 ():
ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.maven:maven-plugin-api:jar:2.0.6:
ArtifactResolutionException: Failure to transfer org.apache.maven:maven-plugin-api:pom:2.0.6 from http://repo1.maven.org/
maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or
updates are forced. Original error: Could not transfer artifact org.apache.maven:maven-plugin-api:pom:2.0.6 from/to central (http://
repo1.maven.org/maven2): null to http://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-
api-2.0.6.pom
- Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources failed: Plugin
org.apache.maven.plugins:maven-resources-plugin:2.4.3 or one of its dependencies could not be resolved: Failed to collect
dependencies for org.apache.maven.plugins:maven-resources-plugin:jar:2.4.3 () (org.apache.maven.plugins:maven-resources-
plugin:2.4.3:resources:default-resources:process-resources)
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:
2.3.2:testCompile (execution: default-testCompile, phase: test-compile)
My pom file is the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lala.sarasa</groupId>
<artifactId>msrdecision</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>msrdecision Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
</build>
</project>
Any idea?
I had same problem with Eclipse 3.7.2 (Indigo) and maven 3.0.4.
In my case, the problem was caused by missing maven-resources-plugin-2.4.3.jar in {user.home}\.m2\repository\org\apache\maven\plugins\maven-resources-plugin\2.4.3 folder. (no idea why maven didn't update it)
Solution:
1.) add dependency to pom.xml
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</dependency>
2.) run mvn install from Eclipse or from command line
3.) refresh the project in eclipse (F5)
4.) run Maven > Update Project Configuration... on project (right click)
JAR file is downloaded to local repository and there are no errors in WS.
I also had same problem with Eclipse 3.7.2 (Indigo) and maven 3.0.4.
Eclipse wasn't picking up my maven settings, so this is what I did to fix the problem:
Window - Preferences - Maven - Installations
Add (Maven 3.0.4 instead of using Embedded)
Click Apply & OK
Maven > Update Project Configuration... on project (right click)
Shutdown Eclipse
Run mvn install from the command line.
Open Eclipse
Those steps worked for me, but the problem isn't consistent. I've only had with issue on one computer.
Just go to your user folder, inside it there's a ".m2" folder, open it and delete the folder "repository". Go to eclipse, clean your project, then right click->Maven->Update Project .. and you are ready to go.
I solved this by running mvn -U install from command line and then "Maven->Update Project" from Eclipse
In this particular case, the solution was the right proxy configuration of eclipse (Window -> Preferences -> Network Connection), the company possessed a strict security system. I will leave the question, because there are answers that can help the community. Thank you very much for the answers above.
In my case the problem was solved by Window -> Preferences -> Maven -> User Settings -> Update Settings. I don't know the problem cause at the first place.
This what helped me:
Delete the project from eclipse (but don't delete from disk)
Close eclipse
In your user folder there is .m folder. Delete repository folder underneath it (.m/repository).
Open eclipse
Import project as existing maven project (from disk).
Good luck.
I would add some points that helped me to solve this problem :
When all other missing archetypes have been indeed installed into your local repository, and the only remaining and abnormally sticking error is this (damned ..) one, whereas the maven-filtering-x.jar is present in his directory, the problem could finally only be solved by creating a new work space as was suggested by Dan in his response ( http://mail-archives.apache.org/mod_mbox/incubator-isis-dev/201112.mbox/%3CCALJOYLFfSJ5Xc_z7a7N+S2_kabuVv0ykv7A5afQaJJOb99iCdg#mail.gmail.com%3E ) (thanks).
Having the local repository OK, on the other hand, turned out to be quite costly, as many archetypes would not get loaded, due apparently to timeouts of m2eclipse and very unstable communication speeds in my case.
In many cases only the error file could be found in the folder ex : xxx.jar.lastUpdated, instead of the jar or pom file. I had always to suppress this file to permit a new download.
Also really worthy were :
as already said, using the mvn clean install from the command line, apparently much more patient than m2eclipse, and also efficient and verbose, at least for the time being.
(and also the Update Project of the Maven menu)
downloading using the dependency:get goal
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=url -Dartifact=groupId:artifactId:version1
(from within the project folder) (hint given in another thread, thanks also).
also downloading and installing manually (.jar+.sha1), from in particular, "m2proxy atlassian" .
adding other repositories in the pom.xml itself (the settings.xml mirror configuration did'nt do the job, I don't know yet why). Ex : nexus/content/repositories/releases/ et nexus/content/repositories/releases/, sous repository.jboss.org, ou download.java.net/maven/2 .
To finish, in any case, a lot of time (!..) could have been et could certainly still be spared with a light tool repairing thoroughly the local repository straightaway. I could not yet find it. Actually it should even be normally a mvn command ("--repair-local-repository").
Encountered the same problem.
For my case i was working behind a proxy.
My solution was
Modify the settings.xml file in the .m2 folder to add the proxy configuration.
proxy
true
http
172.23.182.63
4145
In eclipse Click update settings button. Menu: Windows>>Preferences>>Maven>>User Settings
Delete the .m2/repository folder
Refresh my maven project.
After step 4 - eclipse took a few minutes downloading files and project refreshed successfully.
It must be a configuration problem. Your pom is fine.
Here's what I did. New folder, put your pom inside. Then in eclipse: import -> maven -> existing maven project. Dependencies got included in the project.
I did this using eclipse helios. I think the plugin version I am using is 0.12
You should check the maven properties in eclipse.
This error bothered me for two days. I tried all kinds of solutions, nothing worked. Finally I give up and tried a radical approach. and it worked! Here are the steps:
Save a copy of the pom.xml,
deleted all text in pom.xml
Let eclipse do a clean rebuild, of course everything will be broken.
pasted back everything in the original pom.xml
let Eclipse build again
I guess it was "indeterministic" as the following article said.
http://wiki.eclipse.org/M2E_plugin_execution_not_covered
in my case there was a dependency without a version. in eclipse m2e does not force you to enter a version so i left it blank. once i put the version in pom.xml from within eclipse all was fine
I had a similar case for the default groovy compiler plugin
The solution was to install ME2 provided by Springsource according to this answer
Plugin execution not covered by lifecycle configuration maven error
This immediately solved the "Plugin execution not covered by lifecycle configuration" problem in Eclispe Juno.
I had the same problem but with an other cause. The solution was to deactivate Avira Browser Protection (in german Browser-Schutz). I took the solusion from m2e cannot transfer metadata from nexus, but maven command line can. It can be activated again ones maven has the needed plugin.
I am using MacOSX with Eclipse 4.3 (Krepler). What I originally tried was to install Maven via the terminal using Brew. It installed correctly Maven 3.0.4. However when I tried to import any ready maven projects (File > Import > Maven) it would display the following two errors:
No marketplace entries found to handle Execution default-testResources
What I did is go to Help > Eclipse Marketplace and type "Maven" in the search bar and install the first default Maven client for Eclipse. Everything worked for me from this point.
Hope it helps to you too.
The following steps worked for me:
Close Eclipse.
Navigate to user home directory. (For example: "C:\Users\YourUserName.m2")
Delete the "repository" folder.
Re-open Eclipse.
Click on the Maven project that has an issue and go to "Project" --> "Clean".
Right-click on the project and go to "Maven" --> "Update Project...".
Close Eclipse.
Open Eclipse.
Click on the project folder in the "Project Explorer" window (usually on the left).
Hit the "F5" key a few times to Refresh your project.
Done!
These steps worked for me in Eclipse Luna. Please let me know if I can help further.
My issue was that eclipse could not find the mvn.bat file within the installation directory. The solution is to create a mvn.bat file with the following code:
"%~dp0\mvn.cmd" %*
Save that file. Place it inside the [Maven Installation Folder]\bin directory.