You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by mraible <ma...@raibledesigns.com> on 2009/04/24 11:24:08 UTC

Is it possible to add files to an archetype from other directories?

I'd like to hand-craft an archetype that consists of a single pom.xml and
pulls it's sources from other modules/directories in my project. Is that
possible?

In case anyone needs a more detailed explanation why, here goes...

I'm working on AppFuse, which contains many different archetypes and
"stacks" of frameworks. In the 2.0.x form, we used WARs and overlays and
have found it difficult for users to understand. Rather than pulling in WARs
(and reading their classpaths with the warpath plugin), I'd rather include
all the WAR source in an archetype. This evening, using the war-plugin and
Jetty's support for multiple source directories, I was able to modify things
so all the web/** projects can pull files from web/common/** and build their
WARs as normal, without needing to copy common files to all the modules.

If I want to use a similar setup with archetypes, I need to create a pom.xml
and an archetype descriptor, then slurp in all the files from web/common and
web/framework. If it's not possible to use ../.. notation in an archetype
descriptor, what's the best way to include these common files for new users?

Thanks,

Matt

P.S. I also tried using mvn archetype:create-from-project, but that doesn't
work b/c it 1) keeps the hierarchy of parent pom, which most users probably
won't like and 2) there's no way to automate the building/deploying of these
generated archetypes.
-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-add-files-to-an-archetype-from-other-directories--tp23212840p23212840.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Is it possible to add files to an archetype from other directories?

Posted by mraible <ma...@raibledesigns.com>.
I was able to solve this by changing from maven-archetype-core to
archetype-common and using the new API. Full changelog on moving from old to
new is at:

http://source.appfuse.org/changelog/appfuse/?cs=3228



mgainty wrote:
> 
> 
> Encountered: <EOF> after : "" means you have a null value followed by EOF
> when reading the xml
> Here are the examples I have seen for getTestFile
>         File f1 = getTestFile(
> "src/test/resources/projects/grandchild-check/child/pom.xml");
>         getProject( f1 );
> //The key is to acquire the pom.xml
> 
> If you are getting Security permissions try using
> filename.getCanonicalFile()
> http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#getCanonicalFile()
> 
> does this help?
> Martin 
> ______________________________________________ 
> Disclaimer and Confidentiality/Verzicht und Vertraulichkeitanmerkung /
> Note de déni et de confidentialité 
> This message is confidential. If you should not be the intended receiver,
> then we ask politely to report. Each unauthorized forwarding or
> manufacturing of a copy is inadmissible. This message serves only for the
> exchange of information and has no legal binding effect. Due to the easy
> manipulation of emails we cannot take responsibility over the the
> contents.
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
> Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
> dient lediglich dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le
> destinataire prévu, nous te demandons avec bonté que pour satisfaire
> informez l'expéditeur. N'importe quelle diffusion non autorisée ou la
> copie de ceci est interdite. Ce message sert à l'information seulement et
> n'aura pas n'importe quel effet légalement obligatoire. Étant donné que
> les email peuvent facilement être sujets à la manipulation, nous ne
> pouvons accepter aucune responsabilité pour le contenu fourni.
> 
> 
> 
> 
> 
> 
>> Date: Mon, 27 Apr 2009 14:36:13 -0700
>> From: matt@raibledesigns.com
>> To: users@maven.apache.org
>> Subject: Re: Is it possible to add files to an archetype from other 
>> directories?
>> 
>> 
>> I was able to code a workaround using Ant to create the project then
>> "archetype:create-from-project" to create it. The nice thing about using
>> Ant
>> to do this was I was also able to modify errors in the create process to
>> make working archetypes.
>> 
>> After doing this, I've discovered that the code I was using to
>> materialize
>> archetypes automatically no longer works. The code is below and the error
>> I'm experiencing is as follows:
>> 
>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>> 	at
>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>> Caused by: org.apache.velocity.exception.ParseErrorException: Lexical
>> error:
>> org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line
>> 102,
>> column 93.  Encountered: <EOF> after : ""
>> 	at org.apache.velocity.Template.process(Template.java:141)
>> 	at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:423)
>> 	at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:341)
>> 	at
>> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
>> 	at
>> org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:440)
>> 	at
>> org.apache.maven.archetype.DefaultArchetype.processTemplate(DefaultArchetype.java:904)
>> 
>> 
>>     protected void createTestProject(String archetypeArtifactId, String
>> archetypeVersion) throws Exception {
>>         MavenProject project = getMavenProject();
>>         FileUtils.deleteDirectory(getTestFile("target/" +
>> project.getArtifactId()));
>> 
>>         Map<String, String> parameters = new HashMap<String, String>();
>> 
>>         parameters.put("groupId", project.getGroupId());
>>         parameters.put("artifactId", project.getArtifactId());
>>         parameters.put("version", "1.0-SNAPSHOT");
>>         parameters.put("basedir",
>> getTestFile("target").getAbsolutePath());
>> 
>>         Archetype archetype = (Archetype) lookup(Archetype.ROLE);
>> 
>>         ArtifactRepositoryLayout layout =
>>                 (ArtifactRepositoryLayout)
>> container.lookup(ArtifactRepositoryLayout.ROLE, "default");
>> 
>>         String mavenRepoLocal = "file://" +
>> System.getProperty("user.home")
>> + System.getProperty("file.separator") +
>>                 ".m2" + System.getProperty("file.separator") +
>> "repository";
>>         ArtifactRepository localRepository = new
>> DefaultArtifactRepository("local", mavenRepoLocal, layout);
>> 
>>         List<ArtifactRepository> remoteRepositories = new
>> ArrayList<ArtifactRepository>();
>>         /*String mavenRepoRemote = "http://repo1.maven.org/maven2";
>>         ArtifactRepository remoteRepository = new
>> DefaultArtifactRepository("remote", mavenRepoRemote, layout);
>> 
>>         remoteRepositories.add(remoteRepository);*/
>> 
>>         String archetypeGroupId = "org.appfuse.archetypes";
>>         archetype.createArchetype(archetypeGroupId, archetypeArtifactId,
>> archetypeVersion, localRepository,
>>                 remoteRepositories, parameters);
>>     }
>> 
>> Any ideas?
>> 
>> Thanks,
>> 
>> Matt
>> 
>> Grant Rettke wrote:
>> > 
>> > On Fri, Apr 24, 2009 at 4:24 AM, mraible <ma...@raibledesigns.com>
>> wrote:
>> >> I'd like to hand-craft an archetype that consists of a single pom.xml
>> and
>> >> pulls it's sources from other modules/directories in my project. Is
>> that
>> >> possible?
>> > 
>> > That seems to go against the grain of Maven.
>> > 
>> > Does Maven make stuff like this easy?
>> > 
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> > For additional commands, e-mail: users-help@maven.apache.org
>> > 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Is-it-possible-to-add-files-to-an-archetype-from-other-directories--tp23212840p23265718.html
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>> 
> 
> _________________________________________________________________
> Rediscover Hotmail®: Get quick friend updates right in your inbox. 
> http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009
> 

-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-add-files-to-an-archetype-from-other-directories--tp23212840p23266743.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Is it possible to add files to an archetype from other directories?

Posted by Martin Gainty <mg...@hotmail.com>.
Encountered: <EOF> after : "" means you have a null value followed by EOF when reading the xml
Here are the examples I have seen for getTestFile
        File f1 = getTestFile( "src/test/resources/projects/grandchild-check/child/pom.xml");
        getProject( f1 );
//The key is to acquire the pom.xml

If you are getting Security permissions try using filename.getCanonicalFile()
http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#getCanonicalFile()

does this help?
Martin 
______________________________________________ 
Disclaimer and Confidentiality/Verzicht und Vertraulichkeitanmerkung / Note de déni et de confidentialité 
This message is confidential. If you should not be the intended receiver, then we ask politely to report. Each unauthorized forwarding or manufacturing of a copy is inadmissible. This message serves only for the exchange of information and has no legal binding effect. Due to the easy manipulation of emails we cannot take responsibility over the the contents.
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.






> Date: Mon, 27 Apr 2009 14:36:13 -0700
> From: matt@raibledesigns.com
> To: users@maven.apache.org
> Subject: Re: Is it possible to add files to an archetype from other  directories?
> 
> 
> I was able to code a workaround using Ant to create the project then
> "archetype:create-from-project" to create it. The nice thing about using Ant
> to do this was I was also able to modify errors in the create process to
> make working archetypes.
> 
> After doing this, I've discovered that the code I was using to materialize
> archetypes automatically no longer works. The code is below and the error
> I'm experiencing is as follows:
> 
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
> 	at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
> Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error:
> org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 102,
> column 93.  Encountered: <EOF> after : ""
> 	at org.apache.velocity.Template.process(Template.java:141)
> 	at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:423)
> 	at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:341)
> 	at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
> 	at
> org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:440)
> 	at
> org.apache.maven.archetype.DefaultArchetype.processTemplate(DefaultArchetype.java:904)
> 
> 
>     protected void createTestProject(String archetypeArtifactId, String
> archetypeVersion) throws Exception {
>         MavenProject project = getMavenProject();
>         FileUtils.deleteDirectory(getTestFile("target/" +
> project.getArtifactId()));
> 
>         Map<String, String> parameters = new HashMap<String, String>();
> 
>         parameters.put("groupId", project.getGroupId());
>         parameters.put("artifactId", project.getArtifactId());
>         parameters.put("version", "1.0-SNAPSHOT");
>         parameters.put("basedir", getTestFile("target").getAbsolutePath());
> 
>         Archetype archetype = (Archetype) lookup(Archetype.ROLE);
> 
>         ArtifactRepositoryLayout layout =
>                 (ArtifactRepositoryLayout)
> container.lookup(ArtifactRepositoryLayout.ROLE, "default");
> 
>         String mavenRepoLocal = "file://" + System.getProperty("user.home")
> + System.getProperty("file.separator") +
>                 ".m2" + System.getProperty("file.separator") + "repository";
>         ArtifactRepository localRepository = new
> DefaultArtifactRepository("local", mavenRepoLocal, layout);
> 
>         List<ArtifactRepository> remoteRepositories = new
> ArrayList<ArtifactRepository>();
>         /*String mavenRepoRemote = "http://repo1.maven.org/maven2";
>         ArtifactRepository remoteRepository = new
> DefaultArtifactRepository("remote", mavenRepoRemote, layout);
> 
>         remoteRepositories.add(remoteRepository);*/
> 
>         String archetypeGroupId = "org.appfuse.archetypes";
>         archetype.createArchetype(archetypeGroupId, archetypeArtifactId,
> archetypeVersion, localRepository,
>                 remoteRepositories, parameters);
>     }
> 
> Any ideas?
> 
> Thanks,
> 
> Matt
> 
> Grant Rettke wrote:
> > 
> > On Fri, Apr 24, 2009 at 4:24 AM, mraible <ma...@raibledesigns.com> wrote:
> >> I'd like to hand-craft an archetype that consists of a single pom.xml and
> >> pulls it's sources from other modules/directories in my project. Is that
> >> possible?
> > 
> > That seems to go against the grain of Maven.
> > 
> > Does Maven make stuff like this easy?
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/Is-it-possible-to-add-files-to-an-archetype-from-other-directories--tp23212840p23265718.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 

_________________________________________________________________
Rediscover Hotmail®: Get quick friend updates right in your inbox. 
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009

Re: Is it possible to add files to an archetype from other directories?

Posted by mraible <ma...@raibledesigns.com>.
I was able to code a workaround using Ant to create the project then
"archetype:create-from-project" to create it. The nice thing about using Ant
to do this was I was also able to modify errors in the create process to
make working archetypes.

After doing this, I've discovered that the code I was using to materialize
archetypes automatically no longer works. The code is below and the error
I'm experiencing is as follows:

org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
	at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error:
org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 102,
column 93.  Encountered: <EOF> after : ""
	at org.apache.velocity.Template.process(Template.java:141)
	at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:423)
	at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:341)
	at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
	at
org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:440)
	at
org.apache.maven.archetype.DefaultArchetype.processTemplate(DefaultArchetype.java:904)


    protected void createTestProject(String archetypeArtifactId, String
archetypeVersion) throws Exception {
        MavenProject project = getMavenProject();
        FileUtils.deleteDirectory(getTestFile("target/" +
project.getArtifactId()));

        Map<String, String> parameters = new HashMap<String, String>();

        parameters.put("groupId", project.getGroupId());
        parameters.put("artifactId", project.getArtifactId());
        parameters.put("version", "1.0-SNAPSHOT");
        parameters.put("basedir", getTestFile("target").getAbsolutePath());

        Archetype archetype = (Archetype) lookup(Archetype.ROLE);

        ArtifactRepositoryLayout layout =
                (ArtifactRepositoryLayout)
container.lookup(ArtifactRepositoryLayout.ROLE, "default");

        String mavenRepoLocal = "file://" + System.getProperty("user.home")
+ System.getProperty("file.separator") +
                ".m2" + System.getProperty("file.separator") + "repository";
        ArtifactRepository localRepository = new
DefaultArtifactRepository("local", mavenRepoLocal, layout);

        List<ArtifactRepository> remoteRepositories = new
ArrayList<ArtifactRepository>();
        /*String mavenRepoRemote = "http://repo1.maven.org/maven2";
        ArtifactRepository remoteRepository = new
DefaultArtifactRepository("remote", mavenRepoRemote, layout);

        remoteRepositories.add(remoteRepository);*/

        String archetypeGroupId = "org.appfuse.archetypes";
        archetype.createArchetype(archetypeGroupId, archetypeArtifactId,
archetypeVersion, localRepository,
                remoteRepositories, parameters);
    }

Any ideas?

Thanks,

Matt

Grant Rettke wrote:
> 
> On Fri, Apr 24, 2009 at 4:24 AM, mraible <ma...@raibledesigns.com> wrote:
>> I'd like to hand-craft an archetype that consists of a single pom.xml and
>> pulls it's sources from other modules/directories in my project. Is that
>> possible?
> 
> That seems to go against the grain of Maven.
> 
> Does Maven make stuff like this easy?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-add-files-to-an-archetype-from-other-directories--tp23212840p23265718.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Is it possible to add files to an archetype from other directories?

Posted by Grant Rettke <gr...@acm.org>.
On Fri, Apr 24, 2009 at 4:24 AM, mraible <ma...@raibledesigns.com> wrote:
> I'd like to hand-craft an archetype that consists of a single pom.xml and
> pulls it's sources from other modules/directories in my project. Is that
> possible?

That seems to go against the grain of Maven.

Does Maven make stuff like this easy?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org