Creating archetype using jcodemodel - maven

I am trying to create a maven archetype in which I am trying to autogenerate the code in a java class. I have came across jcodemodel to generate java class. Anyone kindly guide me hoe to do it and where do i need to use jcodemodel in archetype inorder to generate a class file in specific folder with a given name from user?
The archetype gets the input such as servicename, artifactid from user while generating code.

Maven archetypes can use velocity templates to create code, one simple example beeing to create to correct package definitions. The JBoss Wiki contains a simple example of a template containing conditional logic.
If you already have a generator using codemodel, the generate goal of the archetype plugin contains a goals parameter the execute additional plugins after creation. You could let the archetype create only the directory structure, wrap your generator into a maven plugin and then execute on the newly created project.

Related

Maven archetype from project with parameters

I want to create archetype from project. But this archetype need to be parametrized. I added my custom parameter to archetype-metadata.xml but it is removed from generated archetype(/target/generated-sources/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml).
<requiredProperties>
<requiredProperty key="custom_parameter"/>
...
What i'm doing wrong?
The second thing is that i need to edit some xml files. In archetype it should contain my paramter(${custom_parameter}). Can it be done by, for example, groovy during archetype generation?
You used the archetype:create-from-project goal? Then you need to specify the parameter propertyFile (http://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html#propertyFile) to specify the replacements during the creation of your archetype.
I do not completely understand your second point, but as far as I know you cannot run code during the generation of a project from an archetype. You can specify custom properties, though (as above), but this is pure text replacement thing. Maybe you can achieve more elaborate things through the embedded Velocity engine.

Modifying existing modules with archetype update

I have a project which was designed using a custom archetype to build modules under parent project as follows -
Details - The archetype implements a <configuration> in the <build> phase with a <mainClass> let's say Generator that builds the classes under the pojos and service packages into a single target folder and hence enabling to create the final JAR for the user module as user-1.0.0.jar
There's some requirement in terms of separately exposing the pojos without the intervention of service code that has left me brainstorming -
Is there a way to modify the existing archetype or module structure to get two separate JARs for the packages pojos and service as user-pojos-1.0.0.jar and user-service-1.0.0.jar?
One way I possibly know is to move the code in two different module and building their jars but then for multiple existing modules under the parent and a thought over the same name modules under the parent, wouldn't be preferable.
Is there a way to modify the currently obtained user-1.0.0.jar created and separate out it into the two JARs required same as above?

cannot find service.jar file custom portlet liferay

I am using liferay 6.2 & built a maven portlet and working fine, I want to use its tables to store data for another portlet so that I need its services in this portlet.
But we can't access it externally so i find a way something like: required-deployment-contexts=Portlet-Project1 inside liferay-plugin-package.properties, then found its works for Ant only.
I was also finding the xxx-portlet-service.jar but didn't able to, so that i could manually put it in other portlet's lib folder i.e inside tomcat-webapps-xxxportlet-WEB-INF.
Just want to find how to use xxxLocalService.util in other in maven portlet
The best approach you can implement is a plugin to manage all the interaction with the DB.
First of all you must create a Service with a maven project and include it into your pom.xml in each portlet that you need. Then you can invoke its methods whenever you want because each portlet will store the dependencies.
Create Service Plugin into jar file
Rebuild with mvn clean liferay:build-service
Custom your own methods to manage the iteraction with the DB (LocalServiceUtilImpl and rebuild).
Include this plugin into pom.xml portlets
Rebuild your portlet.
The JAR will be placed in your .m2 folder, then each time that you rebuild your Service Plugin will be updated.
If i understood your question correctly, You need to create service builder project using maven and then you can add as dependency in other project wherever you need access to use xxxLocalServicutil class.
You can follow below link to create maven service builder project.
http://www.liferay-guru.com/how-to-use-liferay-servicebuilder-archetype/
As you mentioned in your question.
was also finding the xxx-portlet-service.jar but didn't able to, so
that i could manually put it in other portlet's lib folder
To answer this, manually putting .jar file in lib directory will not help when you are working with maven project

Library to create and upload jar dynamically to maven repository

I have service based environment in which I have to create a jar and upload it dynamically to maven repository and return the dependency tree for it. Is there any library which will create a jar file and upload that jar file to maven repository and will return me dependecny of uploaded jar. Right now Im creating it with maven goals in eclipse but I don't want that.
Thanks,
If you don't want to use the command line or IDE, have you looked at the Maven API? There's also an 'undocumented' Maven embedder project.
Below are some links that may help you get started, pick the approach that is easier for you, while meeting your requirements:
https://github.com/jenkinsci/lib-jenkins-maven-embedder/blob/master/src/main/java/hudson/maven/MavenEmbedder.java
http://maven.apache.org/ref/3.0.2/maven-embedder/apidocs/org/apache/maven/cli/MavenCli.html
http://q4e.googlecode.com/svn-history/r819/trunk/plugins/maven/core/src/org/devzuz/q/maven/embedder/internal/EclipseMaven.java
http://developers-blog.org/blog/def../2009/09/18/How-to-resolve-an-artifact-with-maven-embedder

how to generate multi module archetype from generated one?

hey everyone,
I have generated mono module maven project from a generated one by following that link : http://maven.apache.org/guides/mini/guide-creating-archetypes.html
so i want any one had any idea about the structure of the archetype i must had in my archetype to generate another multi-module archetype from it
You just create your skeleton or model multi module project and then run
mvn archetype:create-from-project
and in the target/generated-sources/archetype/
http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-multi-module-project.html

Resources