2010-04-09 132 views
1

我在使用Maven的原型時遇到了一些麻煩,因此我需要覆蓋一些原型。我啓動一個執行原型的指令:在原型已經存在的目錄中生成。覆蓋Maven中的原型

是否有一個參數讓我覆蓋現有的原型?

我有搜索行家definitve指導,但它指出,唯一接受的參數是: -DgroupId -DartifactId -Dversion -DpackageName -DarchetypeGroupId -DarchetypeArtifactId -DarchetypeVersion -DinteractiveMode

我可以只搜索目錄並刪除文件,但這個過程會自動完成(所以沒有人蔘與,不涉及大腦),我不希望他的機器刪除周圍的東西。

謝謝大家!

編輯:我差點忘了,這裏是一些行家跟蹤:

[INFO] Scanning for projects... 
[INFO] Searching repository for plugin with prefix: 'archetype'. 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Maven Default Project 
[INFO] task-segment: [archetype:generate] (aggregator-style) 
[INFO] ------------------------------------------------------------------------ 
[INFO] Preparing archetype:generate 
[INFO] No goals needed for project - skipping 
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. 
[INFO] Setting property: velocimacro.messages.on => 'false'. 
[INFO] Setting property: resource.loader => 'classpath'. 
[INFO] Setting property: resource.manager.logwhenfound => 'false'. 
[INFO] [archetype:generate {execution: default-cli}] 
[INFO] Generating project in Batch mode 
[INFO] Archetype defined by properties 
[INFO] ---------------------------------------------------------------------------- 
[INFO] Using following parameters for creating OldArchetype: archetype-foo-lib:1.0 
[INFO] ---------------------------------------------------------------------------- 
[INFO] Parameter: groupId, Value: foo.tecnologia 
[INFO] Parameter: packageName, Value: foo.tecnologia 
[INFO] Parameter: basedir, Value: C:\temp\Desarrollo 
[INFO] Parameter: package, Value: foo.tecnologia 
[INFO] Parameter: version, Value: 1.0 
[INFO] Parameter: artifactId, Value: Foo-Lib-Test 
[ERROR] Directory Foo-Lib-Test already exists - please run from a clean directory 
org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: Directory Foo-Lib-Test already exists - please run from a clean directory 
    at org.apache.maven.archetype.old.DefaultOldArchetype.createArchetype(DefaultOldArchetype.java:242) 
    at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.processOldArchetype(DefaultArchetypeGenerator.java:253) 
    at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:143) 
    at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:286) 
    at org.apache.maven.archetype.DefaultArchetype.generateProjectFromArchetype(DefaultArchetype.java:69) 
    at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute(CreateProjectFromArchetypeMojo.java:184) 
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) 
    at com.foo.model.CSMavenCli.main(CSMavenCli.java:391) 
    at com.foo.model.MavenAdmin.generateArchetype(MavenAdmin.java:399) 
    at com.foo.model.ValidarPom.validarPom(ValidarPom.java:167) 
    at com.foo.prueba.GenerarPOM.execute(GenerarPOM.java:93) 
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) 
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) 
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) 
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) 
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305) 
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) 
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) 
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) 
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873) 
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) 
    at java.lang.Thread.run(Unknown Source) 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] : org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: Directory Foo-Lib-Test already exists - please run from a clean directory 
Directory Foo-Lib-Test already exists - please run from a clean directory 
[INFO] ------------------------------------------------------------------------ 
[INFO] For more information, run Maven with the -e switch 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1 second 
[INFO] Finished at: Fri Apr 09 10:01:33 CEST 2010 
[INFO] Final Memory: 15M/28M 
[INFO] ------------------------------------------------------------------------ 
+1

@Random爲什麼你需要覆蓋?使用快速啓動archtype,然後根據您的需要定製項目,並儘可能遵循maven標準,如src/main/java資源src/main/resources中的java文件等。 – ant 2010-04-09 08:09:45

+0

@ c0mrade我有一個程序創建指令archetype:由程序用戶從給定值生成。用戶很容易重新生成原型(例如,更改一些值並重新生成原型)。我想知道我是否可以簡單地覆蓋生成的項目。 – Random 2010-05-20 11:37:13

+1

我希望能夠做同樣的事情 - 使用maven原型完全重新生成代碼,但覆蓋現有的。似乎沒有辦法做到這一點。 – user2800708 2015-09-02 10:52:34

回答

1

我猜你會檢查出原型的來源。例如

http://svn.apache.org/viewvc/maven/archetype/tags/maven-archetype-quickstart-1.1

應用更改並運行mvn安裝

這麼說,你應該通常不會做進一步的參考這樣

http://maven.apache.org/guides/mini/guide-creating-archetypes.html

+0

我不需要更改archtetype,只需覆蓋由原型生成的proyect。所以當我再次生成它(在同一個目錄中)時,它不會崩潰,但會覆蓋現有的工程。 – Random 2010-05-20 11:39:56

+0

等待:您正在尋找的可能是mvn install:http://maven.apache.org/plugins/maven-install-plugin/index.html – 2010-05-20 11:55:09

1

我想在重新生成時覆蓋文件一個原型 - 類似於你的要求,用戶可以用不同的參數重新生成一個項目。在我的情況下,我從模型生成一個完整的REST堆棧,當我對原型本身進行更改時,我想迭代地重新生成所有代碼。

我想這樣做的部分原因是讓IntelliJ項目文件在regens之間保持完整 - 這樣我就不必將生成的項目重新導入到IntelliJ中。

maven原型插件不會覆蓋文件,也沒有啓用該選項的選項。

我找到的解決方案是刪除生成的項目下的所有文件,除了IntelliJ.iml項目文件,並保留.idea和所有目錄完好無損。然後,原型插件將工作。我從腳本中調用原型插件並在其中執行刪除操作。如果「PP」是包含該項目重新生成目錄的名稱:

# This should leave IntelliJ project files intact accross regens. 
find pp -type d -name 'target' -exec rm -fR {} \; 
find pp -type d -name 'generated' -exec rm -fR {} \; 
find pp -type f -not -path '*/.idea/*' -not -name '*.iml' -exec rm {} \; 

您應該能夠拿出一些這方面的變化,以達到你想要的東西。