You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Carlos Ibarra <ca...@adinet.com.uy> on 2008/10/23 18:33:00 UTC
I need your help about the Maven Embedded
Dear,
I need your help about the problem I described below.
I tried to use maven embedded when excute snippet code the application throw
the following exception.
If I need post this problem in other place, please inform me and If need
another information don't doubt and contact me.
==============================================================================================================
The Code
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.junit.Test;
public class MavenEmbedderTest {
@Test
public void executeIsolated() throws Exception{
ConfigurationValidationResult configurationValidationResult;
File userFileSettingsXML = MavenEmbedder.DEFAULT_USER_SETTINGS_FILE;
File baseDir = new File("/home/carlos/Temp/Prueba/");
//String[] goals = new String[] { "mvn
projecthelp:effective-settings"};
String[] goals = new String[] { "mvn archetype:generate
-DarchetypeGroupId=org.phpmaven -DarchetypeArtifactId=php5-web-archetype
-DarchetypeVersion=1.0-BETA-1 -DgroupId=org.sample -DartifactId=my-app"};
if(!baseDir.exists()) throw new Exception("The directory not
exists");
System.out.println(baseDir.toString());
if(!MavenEmbedder.DEFAULT_USER_SETTINGS_FILE.exists()) throw new
Exception("The file not exists");
System.out.println(userFileSettingsXML.toString());
DefaultConfiguration defaultConfiguration= (DefaultConfiguration)
new DefaultConfiguration()
.setUserSettingsFile(userFileSettingsXML)
.setClassLoader(Thread.currentThread().getContextClassLoader());
configurationValidationResult =
MavenEmbedder.validateConfiguration(defaultConfiguration);
if(!configurationValidationResult.isValid())throw new Exception("The
configuration file is wrong.");
System.out.println("Create MavenExecutionRequest");
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setBaseDirectory(baseDir)
.setGoals(Arrays.asList(goals))
.setShowErrors(true)
.addActiveProfile("profile-php-maven")
.setShowErrors(true)
.setUsePluginUpdateOverride(true)
.setInteractiveMode( false )
.setUsePluginUpdateOverride( true )
.setUpdateSnapshots( true )
.setReactorFailureBehavior( "fn" )
;
MavenEmbedder maven = new MavenEmbedder(defaultConfiguration);
MavenExecutionResult result = maven.execute(request);
List exceptions = result.getExceptions();
if (!((exceptions == null) || exceptions.isEmpty())) {
System.out.println("Encountered " + exceptions.size() + "
exception(s).");
Iterator it = exceptions.iterator();
while (it.hasNext()) {
Exception exception = (Exception) it.next();
exception.printStackTrace(System.err);
}
}
}
}
==============================================================================================================
When I run throw the follow exception.
/home/carlos/Temp/Prueba
/home/carlos/.m2/settings.xml
Create MavenExecutionRequest
[INFO] Searching repository for plugin with prefix: 'mvn archetype'.
[INFO] org.apache.maven.plugins: checking for updates from
release-repo1.php-maven.org
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from
release-repo1.php-maven.org
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] Attempting to resolve a version for plugin:
org.apache.maven.plugins:maven-mvn archetype-plugin using meta-version:
LATEST
[INFO] artifact org.apache.maven.plugins:maven-mvn archetype-plugin:
checking for updates from release-repo1.php-maven.org
[INFO] artifact org.apache.maven.plugins:maven-mvn archetype-plugin:
checking for updates from central
[WARNING]
DEPRECATION: The POM for the artifact
'org.apache.maven.plugins:maven-mvn archetype-plugin:pom' was invalid or not
found on any repositories.
This may not be supported by future versions of Maven and should be
corrected as soon as possible.
Error given: POM 'org.apache.maven.plugins:maven-mvn
archetype-plugin' not found in repository: Unable to determine the latest
version
org.apache.maven.plugins:maven-mvn archetype-plugin:pom:LATEST
for project org.apache.maven.plugins:maven-mvn archetype-plugin
[INFO] Using version: LATEST of plugin: org.apache.maven.plugins:maven-mvn
archetype-plugin
[INFO] artifact org.apache.maven.plugins:maven-mvn archetype-plugin:
checking for updates from release-repo1.php-maven.org
[INFO] artifact org.apache.maven.plugins:maven-mvn archetype-plugin:
checking for updates from central
Encountered 1 exception(s).
org.apache.maven.InvalidTaskException: Failed to load one or more lifecycle
definitions which may contain task: 'mvn archetype:generate
-DarchetypeGroupId=org.phpmaven -DarchetypeArtifactId=php5-web-archetype
-DarchetypeVersion=1.0-BETA-1 -DgroupId=org.sample -DartifactId=my-app'.
at
org.apache.maven.lifecycle.TaskValidationResult.generateInvalidTaskException(TaskValidationResult.java:78)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:183)
at
org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:854)
at
org.cygno.bridgemaven.MavenFacadeTest.executeIsolated(MavenFacadeTest.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.apache.maven.lifecycle.LifecycleLoaderException: Failed to
find plugin for prefix: mvn archetype. Reason: Cannot find plugin with
prefix: mvn archetype
at
org.apache.maven.lifecycle.binding.DefaultMojoBindingFactory.parseMojoBinding(DefaultMojoBindingFactory.java:60)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptorForDirectInvocation(DefaultLifecycleExecutor.java:873)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.isTaskValid(DefaultLifecycleExecutor.java:701)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:179)
... 22 more
Caused by: org.apache.maven.plugin.loader.PluginLoaderException: Cannot find
plugin with prefix: mvn archetype
at
org.apache.maven.plugin.loader.DefaultPluginPrefixLoader.findPluginForPrefix(DefaultPluginPrefixLoader.java:98)
at
org.apache.maven.lifecycle.binding.DefaultMojoBindingFactory.parseMojoBinding(DefaultMojoBindingFactory.java:56)
... 25 more
==============================================================================================================
The file settings.xml is
<settings>
<profiles>
<profile>
<id>profile-php-maven</id>
<pluginRepositories>
<pluginRepository>
<id>release-repo1.php-maven.org</id>
<name>PHP-Maven 2 Release
Repository</name>
<url>
http://repo1.php-maven.org/release<https://cygno.com/exchweb/bin/redir.asp?URL=http://repo1.php-maven.org/release>
</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>snapshot-repo1.php-maven.org
</id>
<name>PHP-Maven 2 Snapshot
Repository</name>
<url>
http://repo1.php-maven.org/snapshot<https://cygno.com/exchweb/bin/redir.asp?URL=http://repo1.php-maven.org/snapshot>
</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>release-repo1.php-maven.org</id>
<name>PHP-Maven 2 Release
Repository</name>
<url>
http://repo1.php-maven.org/release<https://cygno.com/exchweb/bin/redir.asp?URL=http://repo1.php-maven.org/release>
</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>snapshot-repo1.php-maven.org
</id>
<name>PHP-Maven 2 Snapshot
Repository</name>
<url>
http://repo1.php-maven.org/snapshot<https://cygno.com/exchweb/bin/redir.asp?URL=http://repo1.php-maven.org/snapshot>
</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>profile-php-maven</activeProfile>
</activeProfiles>
</settings>
==============================================================================================================
Thanks and regards Carlos