maven-antrun-plugin generating emty ddl file - pom.xml

I would like to generate schema sql script with maven.
Here is my persistance file :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="mypersistance"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.archive.autodetection" value="class"></property>
</properties>
<description>Persistance descriptor</description>
<class>test.sofiane.beans.Code</class>
</persistence-unit>
</persistence>
hibernate configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="mySessionFactory">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.default_schema">public</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
</session-factory>
</hibernate-configuration>
plugin in the pom
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<!-- Hibernatetool will generate everything before running tests -->
<phase>compile</phase>
<configuration>
<target>
<echo message="Ant target, through maven-antrun-plugin, started" />
<property name="maven_compile_classpath" refid="maven.compile.classpath" />
<property name="maven_test_classpath" refid="maven.test.classpath" />
<path id="hibernatetool.path">
<pathelement path="${maven_compile_classpath}" />
<pathelement path="${maven_test_classpath}" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernatetool.path" />
<property name="generatedByHibernate.outputDirectory"
value="${project.build.directory}/generated/hibernatetool" />
<mkdir dir="${generatedByHibernate.outputDirectory}" />
<hibernatetool destdir="${generatedByHibernate.outputDirectory}">
<classpath>
<path location="${project.build.directory}/classes/test/sofiane/beans" />
</classpath>
<configuration
configurationfile="${project.build.directory}/classes/hibernate.cfg.xml" />
<hbm2ddl export="true" drop="true" create="true"
outputfilename="helloworld.ddl" format="true" />
</hibernatetool>
<echo message="Ant target, through maven-antrun-plugin, terminated" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The pom works fine and generate helloworld.ddl but empty unfortunately !
Any idea please ?

My first advice is that you should better use the hibernate3-maven-plugin instead of the maven-antrun-plugin because it includes everything that you need and is a lot more simple to use than all the configuration that you had to write with the maven-antrun-plugin (see here for more information about the hibernate3-maven-plugin).
And then, to fix your problem, I think that you can find the answer to your problem in this post and in the answer because it seems that all the elements given will lead you to make your configuration work good.
And don't forget to bind the run of the hibernate3-maven-plugin after the compile phase, on the process-classes phase for example (see Lifecycle Reference) and then just run mvn process-classes.

Related

jboss equivalent or corresponding ant taskdef ejbgen,xdoclet?

i have schema's which needs to be parsed and that should create ejb stubs and jboss related deployment descriptor files .
Could anyone please suggest me which tool (for instance :xdoclet jaxb,its for weblogic) generates jboss deployment descriptor files along with ejb needed interfaces .I have been trying with the below code snippet but couldnt able to generate artifacts .
<taskdef name="ejbdoclet" classname="xdoclet.modules.ejb.EjbDocletTask" classpathref="xdoclet.classpath" />
<taskdef name="ejbdoclet" classname="xdoclet.modules.jboss.ejb.JBossSubTask" classpathref="xdoclet.classpath" />
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="compile.classpath" />
</taskdef>
your help on this matter is highly appreciable .Thanks in Advance .
Seems like you are using ANT, I've used something like this for the build.xml. The compile task must depend on this.
<target name="createDeployDescriptor" description="create DeployDescriptor using XDoclet">
<taskdef classname="xdoclet.modules.ejb.EjbDocletTask" classpathref="xdoclet.classpath" name="ejbdoclet" />
<ejbdoclet destdir="${classes.dir}/META-INF" mergedir="etc/xdoclet/merge" excludedtags="#version,#author" ejbspec="2.1" force="true">
<fileset dir="${src.dir}">
<include name="**/*Bean.java" />
<exclude name="**/*test*" />
</fileset>
<remoteinterface destDir="${src.gen.dir}" />
<localinterface destDir="${src.gen.dir}" />
<homeinterface destDir="${src.gen.dir}" />
<localhomeinterface destDir="${src.gen.dir}" />
<!-- valueobject templateFile="etc/resources/xdoclet/valueobject.xdt" pattern="{0}" / -->
<!-- generate the primary key classes for the entities -->
<entitypk destDir="${src.gen.dir}" />
<utilobject destDir="${src.gen.dir}" kind="physical" cacheHomes="true" includeGUID="${xdoclet.ejb.include.guid}" pattern="{0}Locator" templateFile="etc/xdoclet/locator.xdt" />
<deploymentdescriptor validatexml="true">
<configParam name="Description" value="Deploymentdescriptor for WFink EJB2.1" />
</deploymentdescriptor>
<jboss version="4.0" mergeDir="etc/xdoclet/merge" />
</ejbdoclet>
</target>
Also Maven is possible with this:
<build>
<plugins>
<!-- use XDoclet to generate the EJB2 artifacts, the plugin version is defined in the root pom -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xdoclet-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xdoclet</goal>
</goals>
<configuration>
<tasks>
<ejbdoclet destdir="${project.build.outputDirectory}">
<fileset dir="${project.build.sourceDirectory}" includes="**/*Bean.java" />
<localinterface destDir="${project.build.directory}/generated-sources/xdoclet" />
<localhomeinterface destDir="${project.build.directory}/generated-sources/xdoclet" />
<remoteinterface destDir="${project.build.directory}/generated-sources/xdoclet" />
<homeinterface destDir="${project.build.directory}/generated-sources/xdoclet" />
<utilobject kind="physical" destDir="${project.build.directory}/generated-sources/xdoclet" />
<deploymentdescriptor destDir="${project.build.outputDirectory}/META-INF" />
<jboss version="4.0" destDir="${project.build.outputDirectory}/META-INF" datasource="java:jboss/datasources/ExampleDS" />
</ejbdoclet>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
....
</plugins>
</build>
You should consider that both are out of date, for JBossAS7, WildFly and EAP6+ the generated jboss.xml descriptor is ignored and you need to add by hand a jboss-ejb3.xml which configure the JBoss specific settings.
For simple use you should not need this

Configure Sonar for Delphi with sub-modules

I can get Delphi analysis working on single projects, so the plugin works.
I can get Submodules analysis set up as per my previous question but no delphi analysis is performed.
refer to Configuration of build.xml file for Sonar modules with Ant for reference.
If I include the (I believe) required delphi configuration in the master build file it only works if I include the sonar.sources line.
BUT, when I include that line it is attempting to analyse all delphi code and is ignorning the submodules.
How (assuming it can be done) do I configure this to work or do I have to run each project completely separately?
Master Build File
<?xml version="1.0" encoding="UTF-8"?>
<project name = "EXO" default = "sonar" basedir = "." xmlns:sonar="antlib:org.sonar.ant">
<echo>Root Project</echo>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<property name="sonar.host.url" value="http://localhost:9000" />
<property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />
<target name="sonar">
<sonar:sonar key="EXO.key" version="0.1">
<property key="sonar.sources" value="." />
<property key="sonar.language" value="delph" />
</sonar:sonar>
</target>
</project>
Sub Project Build File
<?xml version="1.0" encoding="UTF-8"?>
<project name="CRM" default="all" basedir=".">
<echo>CRM Module</echo>
<property name="sonar.language" value="delph" />
<property name="sonar.projectKey" value="EXO:CRM" />
<property name="sonar.sources" value="." />
<target name="all" />
</project>

Configuration of build.xml file for Sonar modules with Ant

I am setting up a Sonar project (using the delphi plugin), for simplicity sake assume there are two modules I want to report on.
Each module is in it's own sub-folder and each has it's own build.xml file.
At this point I can successfully run the sonar tasks and generate reports for each module as an independent project.
My problem is with configuring the "master" build.xml file.
The module build.xml file looks like this:
<?xml version="1.0"?>
<project name = "CRM" default = "sonar" basedir = ".">
<!-- Add the Sonar task -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<target name="sonar">
<property name="sonar.projectKey" value="EXO:CRM" />
<property name="sonar.host.url" value="http://localhost:9000" />
<sonar:sonar workDir="." key="CRM.key" version="0.1" xmlns:sonar="antlib:org.sonar.ant">
<property key="sonar.sources" value="." /> <!-- project sources directories (required) -->
<property key="sonar.language" value="delph" /> <!-- project language -->
<property key="sonar.delphi.codecoverage.excluded" value=".\tests" /> <!-- code coverage excluded directories -->
<property key="sonar.importSources" value="true" /> <!-- should we show sources or not? -->
<property key="sonar.delphi.sources.excluded" value="" /> <!-- excluded directories -->
<property key="sonar.delphi.sources.include" value=".\includes" /> <!-- include directories, "," separated -->
<property key="sonar.delphi.sources.include.extend" value="true" /> <!-- should we extend includes in files? -->
</sonar:sonar>
</target>
</project>
The "Master" build.xml looks like this:
<?xml version="1.0"?>
<project name = "EXO" default = "sonar" basedir = ".">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<target name="sonar">
<property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />
<sonar:sonar workDir="." key="EXO.key" version="0.1" xmlns:sonar="antlib:org.sonar.ant">
<!-- project sources directories (required) -->
<property key="sonar.sources" value="." />
<property key="sonar.language" value="delph" />
<property key="sonar.importSources" value="true" />
<property key="sonar.delphi.sources.excluded" value="" />
<property key="sonar.delphi.sources.include" value=".\includes" />
<property key="sonar.delphi.sources.include.extend" value="true" />
</sonar:sonar>
</target>
</project>
It is always scanning all sources (required value) i.e. it is not respecting my modules.
The only way I can get this to work currently is by limiting the source code like this
<property key="sonar.sources" value="./crm/,./exonet6000/" />
I'm sure I must be mis-configuring something obvious here.
EDIT: I have now what I believe is a more consistent set of files based on examples here https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/java-ant-modules
Master build file:
<?xml version="1.0" encoding="UTF-8"?>
<project name = "EXO" default = "sonar" basedir = "." xmlns:sonar="antlib:org.sonar.ant">
<echo>Root Project</echo>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="c:/ANT/lib" />
</taskdef>
<property name="sonar.host.url" value="http://localhost:9000" />
<property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />
<target name="sonar">
<sonar:sonar key="EXO.key" version="0.1">
</sonar:sonar>
</target>
</project>
and one of the submodule files
<?xml version="1.0" encoding="UTF-8"?>
<project name="CRM" default="all" basedir=".">
<echo>CRM Module</echo>
<property name="sonar.language" value="delph" />
<property name="sonar.projectKey" value="EXO:CRM" />
<property name="sonar.sources" value="." />
<target name="all" />
</project>
At this point the sonar process is completing successfully BUT no actual anlysis is being done. A key point is that I am not seeing the echo of the submodule so I suspect these build tasks are not actually running.
If you look at this sample project using Ant and multimodules, I'd say that you should not specify any property inside the tag in your master build.xml file, and let the submodules specify those properties.
I've got a project with many submodules. My sonar target looks like this:
<target name="sonar" depends="build.dependencies" description="collect code metrics">
<property name="m1" value="a/build.xml,b/build.xml,c/build.xml,d/build.xml"/>
... more properties defining modules...
<property name="sonar.modules" value="${m1},${m2},${m3},${m4},${m5},${m6}..."/>
<property name="sonar.projectName" value="MyProject"/>
<sonar:sonar key="my:project" version="${version}" xmlns:sonar="antlib:org.sonar.ant">
</sonar:sonar>
</target>
No property definitions in the sonar:sonar task at all, and it is working as I want it to.
Sources are defined in the submodule build.xml files. (Actually, in a base-build.xml that all our build.xml files include... but that's an Ant thing not directly related to Sonar.)

How integrate a jar with a custom action in Alfresco

I've created a custom action with as a eclipse project. I packaged it in a jar and I put it in: alfresco-3.4.d/tomcat/webapps/alfresco/WEB-INF/lib
I started Alfresco and I created a rule with my custom action. When a file is created in this folder then the rule is triggered.
But when I create a file, the unique available type is "content", my custom content types don't show in select list. My problem is I need these custom types.
I have tested starting Alfresco without my jar and all types are availables.
My project structure is wrong?:
src.main.java
-executer
·UrlActionExecuter.java
·UrlActionHandler.java
src.main.resources
-alfresco.extension
·url-actions-context.xml
·web-client-config-custom.xml
·webclient.properties
src.main.webapp
-jsp.actions
·url-action-executer.jsp
or build.xml?:
<?xml version="1.0"?>
<project name="Action Url" default="package" basedir=".">
<property name="project.dir" value="."/>
<property name="build.dir" value="${project.dir}/build"/>
<property name="package.file" value="${build.dir}/Action-url.jar"/>
<path id="class.path">
<dirset dir="${build.dir}" />
<fileset dir="../../lib/server" includes="**/*.jar"/>
</path>
<target name="compile">
<mkdir dir="${build.dir}" />
<javac classpathref="class.path" srcdir="${project.dir}/src" destdir="${build.dir}" />
</target>
<target name="package" >
<jar destfile="${package.file}">
<fileset dir="${build.dir}"/>
</jar>
</target>
</project>
Thanks everybody!
Your custom types should described in the model file and then you should import your model to the alfresco, for example:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="custom_dictionaryBootstrap"
parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<value>alfresco/module/mymodule/model/mymodel.xml</value>
</list>
</property>
<property name="labels">
<list>
<value>alfresco/module/mymodule/messages/system</value>
</list>
</property>
</bean>
</beans>

How to parameterize a path in ANT?

I have the following defined in a file called build-dependencies.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<path id="common-jars">
<fileset file="artifacts/project-1/jar/some*.jar" />
<fileset file="artifacts/project-2/jar/someother*.jar" />
</path>
...
</project>
I include it at the top of my build.xml file. Now I need to make the artifacts folder a parameter so it can be changed during execution of different targets.
Having this...
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<path id="common-jars">
<fileset file="${artifacts}/project-1/jar/some*.jar" />
<fileset file="${artifacts}/project-2/jar/someother*.jar" />
</path>
...
</project>
...and defining an "artifacts" property (and changing it) in the target does not work because it seems that the property substitution happens when the path is defined in build-dependencies.xml
How can I solve this? One way I was thinking was to have a parameterized macro and call that before the path is actually used, but that seems not elegant. Something like this:
<macrodef name="create-common-jars">
<attribute name="artifacts"/>
<sequential>
<path id="common-jars">
<fileset file="#{artifacts}/project-1/jar/some*.jar" />
<fileset file="#{artifacts}/project-2/jar/someother*.jar" />
</path>
</sequential>
</macrodef>
EDIT: Ivy and command line parameters are not an option.
You don't want a parameterized path. You want a PatternSet. You can define the patternset at the top-level and then just refer to it in individual targets when you need it. For your example:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<patternset id="common-jars">
<include name="project-1/jar/some*.jar" />
<include name="project-2/jar/someother*.jar" />
</patternset>
...
<path id="instrumented-jars">
<fileset dir="instrumented">
<patternset refid="common-jars" />
</fileset>
</path>
...
<path id="standard-jars">
<fileset dir="not-instrumented">
<patternset refid="common-jars" />
</fileset>
</path>
...
</project>
I'd recommend using ivy to manage your classpath dependencies. Ivy has a neat concept called configurations that allows you to group collections of artifacts based on their usage.
Here's an adaption from one of my own build files:
<target name="retrieve" description="3rd party dependencies">
<ivy:resolve/>
<ivy:cachepath pathid="build.path" conf="build"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
</target>
The configurations are managed in the ivy.xml file (Would replace your build-dependencies.xml file)
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="HelloWorld"/>
<configurations>
<conf name="build" description="jars needed for build" />
<conf name="runtime" extends="build" description="jars needed at runtime" />
</configurations>
<dependencies>
<dependency org="org1" name="project1" rev="1.0" conf="build->default"/>
<dependency org="org2" name="project2" rev="1.0" conf="build->default"/>
<dependency org="org3" name="project3" rev="1.0" conf="runtime->default"/>
<dependency org="org4" name="project4" rev="1.0" conf="runtime->default"/>
</dependencies>
</ivy-module>
The jar artifacts associated with each project would be downloaded and cached automatically from the on-line maven repositories or you can create your own local repository to hold collections of locally owned artifacts.
Lets call your file build.xml. So you execute it by running ant command. In the first case the artifacts names is hardcoded in the property defined on the third line below
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
<property name="artifacts" value="first-value" />
...
<path id="common-jars">
<fileset file="artifacts/project-1/jar/some*.jar" />
<fileset file="artifacts/project-2/jar/someother*.jar" />
</path>
...
</project>
Now when you want to change it and use another value for that artifacts property, we run the script thus
ant -Dartifacts=new-value
This will override the hardcoded artifacts value in build.xml
If working in terms of ant targets you can do something similar, in the target on first line define the property, and if you want to overwrite the default value then pass the property as a parameter when that target is called.
Your comment reminded me of something else. Have your developers create a artifacts-dir-name.xml file. It will have only one line:
<?xml version="1.0" encoding="UTF-8"?>
<project name="artifacts-file">
<property name="artifacts" value="new-value" />
</project>
Now in your build.xml file, before the line where artifacts property is defined, import that file thus:
<import file="artifacts-dir-name.xml" optional="true" />
Now in Eclipse if this file exists, then the property is read from it and artifacts is set to "new-value", else the property is read from build.xml and is set to "first-value". All the developers need to do is to ensure artifacts-dir-name.xml file exists in that directory. This can run within Eclipse too.
is using environment variables an option (if they are set when eclipse is launched they will be picked up)? If so, have each one set ARTIFACTS and this should work:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
<property environment="env"/>
<path id="common-jars">
<fileset file="${env.ARTIFACTS}/project-1/jar/some*.jar" />
<fileset file="${env.ARTIFACTS}/project-2/jar/someother*.jar" />
</path>
</project>
OK, I think there is no other obvious way for me to do what I am trying to do, except use a macro that takes a parameter and creates the path with the appropriate artifacts folder.
To give a bit of context, why I was trying to what I wanted is to have "instrumented" and "not-instrumented" artifacts in separate folders. And in my "targets" I could just vary the artifacts mode. So what I do now is I have a macro: <initialise-build-settings artifacts-mode="instrumented" /> that sets up all the paths and other variables.
Thanks for your answers guys.
You can do this with different dependencies:
setpath.xml:
<project name="setpath">
<target name="setCommonJars">
<path id="common-jars">
<fileset file="${param1}/some*.jar" />
<fileset file="${param1}/someother*.jar" />
</path>
</target>
</project>
build.xml:
<project name="Test path" basedir=".">
<import file="./setpath.xml" />
<target name="buildT1" depends="setT1,setCommonJars">
<property name="jar-str" refid="common-jars" />
<echo message="buildT1: ${jar-str}" />
</target>
<target name="buildT2" depends="setT2,setCommonJars">
<property name="jar-str" refid="common-jars" />
<echo message="buildT2: ${jar-str}" />
</target>
<target name="setT1">
<property name="param1" value="t1" />
</target>
<target name="setT2">
<property name="param1" value="t2" />
</target>
</project>
If you call target buildT1 then the t1 directory will be used, if you call buildT2 then the t2 directory will be used.

Resources