I'm trying to build up some documentation for my Wicket Web Application. I have created a page to grab all of my mounted pages and display them in /sitemap.xml.
In the vein of documentation I've added a new tag to the file <siteMap:Description>
now I want to fill that description with the javadoc entry that describes the class file.
I know there is know direct way to access them at runtime. So Instead I'm hoping to copy them at compile time into a List where they will then be accessible from runtime. How would I do that?
I'm using Maven for my build.
EDIT
I should probably Also mention that I do have an AntTask Already defined as part of my build process to save the compile Dates/times to a property file.
It seems to me an Task to scan my Class and then put the information into a file is probably the way to go. Problem is I'm not sure how to proceed.
My Ant-Task is defined like in my pom.xml so:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>set-build-time</id>
<phase>process-sources</phase>
<configuration>
<tasks>
<tstamp>
<format property="build.timestamp" pattern="yyyy/MM/dd HH:mm:ss"/>
<format property="build.time" pattern="HH:mm:ss" />
<format property="build.date" pattern="MM/dd/yyyy" />
<format property="build.year" pattern="yyyy"/>
</tstamp>
<replaceregexp byline="true">
<regexp pattern="copyYear\=.*" />
<!--suppress MavenModelInspection -->
<substitution expression="copyYear=${build.year}" />
<fileset dir="src/main/java/" includes="**/*.properties" />
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="buildTime\=.*" />
<!--suppress MavenModelInspection -->
<substitution expression="buildTime=${build.date} ${build.time}" />
<fileset dir="src/main/java/" includes="**/*.properties" />
</replaceregexp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
After doing more research I determined I was barking up the wrong tree.
I since I was trying to get Javadoc comments A Doclet was the better answer.
So I implemented a custom doclet and wired it up to run automatically as described in
the follow up question and answer below.
How can I compile and run my Custom Doclet class in my project?
Related
In my maven project, I want all my datetime entries should be generated as java.util.date instead of XMLGregorianCalendar. As you might know XMLGregorianCalendar gets generated by default.
We can take example project provided here.
Here in the CustomersOrders.xsd, you can see attriute ShippedDate is of type dateTime.
<xs:attribute name='ShippedDate' type='xs:dateTime' />
To convert its data type into java.util.date, I'm following approach provided in documentation here. i.e. by using external binding file, like:
Customer.xjb
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<javaType name="java.util.date" xmlType="xs:datetime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate"
/>
</globalBindings>
</bindings>
Then I mapped Customer.xjb file in pom.xml like:
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- the package for the generated java classes -->
<generatePackage>com.dimitrisli.jaxb.producedClasses</generatePackage>
<!-- If the following not specified all xsd in resources are included -->
<schemaIncludes>
<include>sampleJaxb/CustomersOrders.xsd</include>
</schemaIncludes>
<!-- if you don't want old output -->
<removeOldOutput>true</removeOldOutput>
<!-- if you want verbosity -->
<!-- verbose>true</verbose -->
<xjbSources>
<xjbSource>sampleJaxb/Customers.xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>
But when I do mvn clean install, I'm still not able to see any difference in ShippedDate, which is still being generated as XMLGregorianCalendar.
Please suggest what am I missing.
Thank You
If you use the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin then you should use bindingIncludes instead of xjbSources (it's for org.codehaus.mojo:jaxb2-maven-plugin).
<bindingIncludes>
<include>sampleJaxb/Customers.xjb</include>
</bindingIncludes>`
Also, you have to implement a custom adapter for java.util.Date like you have seen in the tutorial or convert to java.util.Calendar:
<javaType name="java.util.Calendar" xmlType="xsd:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />`
Hope it helps!
I added to my Maven project the solution advised in this Stack Overflow question. The only difference to the suggested solution that I introduced was to replace the <tasks /> with the <target /> (the issue I am experiencing appears with either).
Everything works excellent on the testing side. When I run my tests the correct (test-persistence.xml) persistence file is being used. However when I am doing clean install or even hit run from my IDE (Netbeans 8.2) only the first target (copy-test-persistence) is being executed. The second execution is being entered after the tests (see the build output below), but target is not executed. What I do get after every clean install and when running the app on the server is that the contents of the test-persistence.xml are in the persistence.xml file. The right content remains in the persistence.xml.proper created in the first target.
--- maven-antrun-plugin:1.8:run (copy-test-persistence) # RimmaNew ---
Executing tasks
main:
[copy] Copying 1 file to /my-project-home/target/classes/META-INF
[copy] Copying 1 file to /my-project-home/target/classes/META-INF
Executed tasks
...
--- maven-antrun-plugin:1.8:run (restore-persistence) # RimmaNew ---
Executing tasks
main:
Executed tasks
You will notice that 0 tasks are executed under restore-persistence. Strangely enough in the created /target/antrun folder there's a build-main.xml file which includes the skipped task:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<copy file="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml.proper" tofile="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml"/>
</target>
</project>
It would be appreciated if you could give me a hint as I can't get my head around this. As it is common I am posting my current pom.xml:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-test-persistence</id>
<phase>process-test-resources</phase>
<configuration>
<target>
<!--backup the "proper" persistence.xml-->
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml.proper" />
<!--replace the "proper" persistence.xml with the "test" version-->
<copy file="${project.build.testOutputDirectory}/META-INF/test-persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>restore-persistence</id>
<phase>prepare-package</phase>
<configuration>
<target>
<!--restore the "proper" persistence.xml-->
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The issue has got to do with how Ant's copy task work:
By default, files are only copied if the source file is newer than the destination file, or when the destination file does not exist.
This is the problem here. Ant detects that the target file already exists, and that it is not newer. There is a granularity to determine "newer", and by default, it is 1 second, or 2 seconds on DOS systems. So what happens is that, during the build, the persistence.xml is copied by Maven into the build directory, its last modified date is changed (the Resources Plugin doesn't keep it), and then your own copy is just few milliseconds later. Thus, the copied persistence.xml.proper will never be newer because this all happens during the default granularity.
You can force the copy by setting the overwrite parameter to true with
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
overwrite="true"/>
Or you could use the move task instead, since you probably don't need to keep the .proper file anyway:
<move file="${project.build.outputDirectory}/META-INF/persistence.xml.proper"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
I'm trying to implement a Maven build process for YAJSW (Yet Another Java Service Wrapper). The part I'm currently working on is generating a custom manifest for the jar to ape the format used in the currently hard-coded MANIFEST.MF file, like so:
Manifest-Version: 1.0
Class-Path-Wrapper-Core:
./wrapperApp.jar
./lib/core/yajsw/ahessian.jar
.
.
.
./lib/core/regex/jrexx-1.1.1.jar
Class-Path-Wrapper-Extended:
./lib/extended/commons/commons-httpclient-3.0.1.jar
./lib/extended/commons/commons-codec-1.3.jar
.
.
./lib/extended/abeille/formsrt.jar
Class-Path-App:
./wrapper.jar
.
.
./lib/core/commons/commons-logging-1.1.jar
Main-Class: org.rzo.yajsw.boot.WrapperExeBooter
I've managed to produce suitably formatted classpaths using the dependency:build-dep task like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-classpath</id>
<phase>generate-sources</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<attach>true</attach>
<localRepoProperty>.</localRepoProperty>
<pathSeparator>$${pathDelim}</pathSeparator>
<outputFile>${basedir}/target/assembly/classPath</outputFile>
</configuration>
</execution>
</executions>
</plugin>
N.B. the $${pathDelim} part was arrived at after much experimentation with escaping, antrun and properties. Initially I tried to add newlines directly using the pathSeparator parameter. I found that the only way I could do this was to use $${line.separator}. Seems there's an extra layer of de-escaping that happens somewhere in the pipeline.
This code successfully generates a classPath file in the required format. Now I had to merge this into a MANIFEST.MF file.
On reviewing all the options, I've done this using an Antrun task :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<property name="cp.props"
value="${basedir}/target/assembly/classPath.properties" />
<concat destfile="${cp.props}">
<string>wrapper.core.classpath=</string>
<filelist dir="${basedir}/target/assembly" files="classPath" />
</concat>
<property file="${cp.props}" />
<echo file="${MANIFEST}"
message="Manifest-Version: 1.0${line.separator}Class-Path-Wrapper-Core: ${line.separator}
${wrapper.core.classpath}${line.separator}
${line.separator}
Class-Path-Wrapper-Extended: ${line.separator}
${wrapper.core.classpath}${line.separator}
${line.separator}
Class-Path-App: ${line.separator}
${wrapper.core.classpath}${line.separator}
${line.separator}
Main-Class: org.rzo.yajsw.boot.WrapperExeBooter${line.separator}" />
<replace file="${MANIFEST}" token="${pathDelim}" value=" " />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
This produced more or less the correct output in the MANIFEST.MF file:
Manifest-Version: 1.0
Class-Path-Wrapper-Core:
./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ...
Class-Path-Wrapper-Extended:
./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ...
Class-Path-App:
./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ...
Main-Class: org.rzo.yajsw.boot.WrapperExeBooter
which I then pointed to in the jar plugin settings:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3</version>
<configuration>
<useDefaultManifestFile>false</useDefaultManifestFile>
<archive> <manifestFile>${MANIFEST}</manifestFile> </archive>
</configuration>
</plugin>
However, looking in the resultant jar, it seems to have flattened the output, like so:
Manifest-Version: 1.0 Class-Path-Wrapper-Core: ./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ./commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar ./commons-lang/commons-lang/2.6/commons-lang-2.6.jar ./commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ./commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar ./commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar ./org/apache/commons/commons-cli/2.0-SNAPSHOT/commons-cli-2.0-SNAPSHOT.jar ./commons-io/commons-io/1.3.1/commons-io-1.3.1.jar ./org/apache/commons/commons-vfs/2.0-SNAPSHOT/commons-vfs-2.0-SNAPSHOT.jar ./commons-httpclient/commons-httpclient/3.0/commons-httpclient-3.0.jar ./commons-codec/commons-codec/1.2/commons-codec-1.2.jar ./org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar ./org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar ./regexp/regexp/1.3/regexp-1.3.jar ./org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar ./net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar ./net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar ./io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar ./jrexx/jrexx/1.1.1/jrexx-1.1.1.jar ./org/rzo/ahessian/yajsw.11.0/ahessian-yajsw.11.0.jar ./org/quartz-scheduler/quartz/1.8.0/quartz-1.8.0.jar ./javax/transaction/jta/1.1/jta-1.1.jar ./org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar ./org/slf4j/slf4j-log4j12/1.5.10/slf4j-log4j12-1.5.10.jar ./log4j/log4j/1.2.14/log4j-1.2.14.jar ./org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar ./oro/oro/2.0.8/oro-2.0.8.jar ./com/caucho/hessian/4.0.7/hessian-4.0.7.jar ./com/jgoodies/forms/1.2.0/forms-1.2.0.jar ./net/java/dev/glazedlists/glazedlists_java15/1.8.0/glazedlists_java15-1.8.0.jar ./com/jeta/abeille/forms/1.0/forms-1.0.jar ./org/codehaus/mojo/properties-maven-plugin/1.0-alpha-1/properties-maven-plugin-1.0-alpha-1.jar ./org/apache/maven/maven-model/2.0.4/maven-model-2.0.4.jar ./org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar ./org/apache/maven/maven-project/2.0.4/maven-project-2.0.4.jar ./org/apache/maven/maven-settings/2.0.4/maven-settings-2.0.4.jar ./org/apache/maven/maven-profile/2.0.4/maven-profile-2.0.4.jar ./org/apache/maven/maven-artifact-manager/2.0.4/maven-artifact-manager-2.0.4.jar ./org/apache/maven/maven-repository-metadata/2.0.4/maven-repository-metadata-2.0.4.jar ./org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar ./org/apache/maven/maven-artifact/2.0.4/maven-artifact-2.0.4.jar ./org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar ./junit/junit/3.8.1/junit-3.8.1.jar ./classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar ./org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar Class-Path-Wrapper-Extended: ./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ./commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar ./commons-lang/commons-lang/2.6/commons-lang-2.6.jar ./commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ./commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar ./commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar ./org/apache/commons/commons-cli/2.0-SNAPSHOT/commons-cli-2.0-SNAPSHOT.jar ./commons-io/commons-io/1.3.1/commons-io-1.3.1.jar ./org/apache/commons/commons-vfs/2.0-SNAPSHOT/commons-vfs-2.0-SNAPSHOT.jar ./commons-httpclient/commons-httpclient/3.0/commons-httpclient-3.0.jar ./commons-codec/commons-codec/1.2/commons-codec-1.2.jar ./org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar ./org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar ./regexp/regexp/1.3/regexp-1.3.jar ./org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar ./net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar ./net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar ./io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar ./jrexx/jrexx/1.1.1/jrexx-1.1.1.jar ./org/rzo/ahessian/yajsw.11.0/ahessian-yajsw.11.0.jar ./org/quartz-scheduler/quartz/1.8.0/quartz-1.8.0.jar ./javax/transaction/jta/1.1/jta-1.1.jar ./org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar ./org/slf4j/slf4j-log4j12/1.5.10/slf4j-log4j12-1.5.10.jar ./log4j/log4j/1.2.14/log4j-1.2.14.jar ./org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar ./oro/oro/2.0.8/oro-2.0.8.jar ./com/caucho/hessian/4.0.7/hessian-4.0.7.jar ./com/jgoodies/forms/1.2.0/forms-1.2.0.jar ./net/java/dev/glazedlists/glazedlists_java15/1.8.0/glazedlists_java15-1.8.0.jar ./com/jeta/abeille/forms/1.0/forms-1.0.jar ./org/codehaus/mojo/properties-maven-plugin/1.0-alpha-1/properties-maven-plugin-1.0-alpha-1.jar ./org/apache/maven/maven-model/2.0.4/maven-model-2.0.4.jar ./org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar ./org/apache/maven/maven-project/2.0.4/maven-project-2.0.4.jar ./org/apache/maven/maven-settings/2.0.4/maven-settings-2.0.4.jar ./org/apache/maven/maven-profile/2.0.4/maven-profile-2.0.4.jar ./org/apache/maven/maven-artifact-manager/2.0.4/maven-artifact-manager-2.0.4.jar ./org/apache/maven/maven-repository-metadata/2.0.4/maven-repository-metadata-2.0.4.jar ./org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar ./org/apache/maven/maven-artifact/2.0.4/maven-artifact-2.0.4.jar ./org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar ./junit/junit/3.8.1/junit-3.8.1.jar ./classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar ./org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar Class-Path-App: ./commons-daemon/commons-daemon/1.0.10/commons-daemon-1.0.10.jar ./commons-configuration/commons-configuration/1.7-SNAPSHOT/commons-configuration-1.7-SNAPSHOT.jar ./commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar ./commons-lang/commons-lang/2.6/commons-lang-2.6.jar ./commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ./commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar ./commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar ./org/apache/commons/commons-cli/2.0-SNAPSHOT/commons-cli-2.0-SNAPSHOT.jar ./commons-io/commons-io/1.3.1/commons-io-1.3.1.jar ./org/apache/commons/commons-vfs/2.0-SNAPSHOT/commons-vfs-2.0-SNAPSHOT.jar ./commons-httpclient/commons-httpclient/3.0/commons-httpclient-3.0.jar ./commons-codec/commons-codec/1.2/commons-codec-1.2.jar ./org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar ./org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar ./org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar ./regexp/regexp/1.3/regexp-1.3.jar ./org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar ./net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar ./net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar ./io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar ./jrexx/jrexx/1.1.1/jrexx-1.1.1.jar ./org/rzo/ahessian/yajsw.11.0/ahessian-yajsw.11.0.jar ./org/quartz-scheduler/quartz/1.8.0/quartz-1.8.0.jar ./javax/transaction/jta/1.1/jta-1.1.jar ./org/slf4j/slf4j-api/1.5.10/slf4j-api-1.5.10.jar ./org/slf4j/slf4j-log4j12/1.5.10/slf4j-log4j12-1.5.10.jar ./log4j/log4j/1.2.14/log4j-1.2.14.jar ./org/apache/velocity/velocity/1.6.3/velocity-1.6.3.jar ./oro/oro/2.0.8/oro-2.0.8.jar ./com/caucho/hessian/4.0.7/hessian-4.0.7.jar ./com/jgoodies/forms/1.2.0/forms-1.2.0.jar ./net/java/dev/glazedlists/glazedlists_java15/1.8.0/glazedlists_java15-1.8.0.jar ./com/jeta/abeille/forms/1.0/forms-1.0.jar ./org/codehaus/mojo/properties-maven-plugin/1.0-alpha-1/properties-maven-plugin-1.0-alpha-1.jar ./org/apache/maven/maven-model/2.0.4/maven-model-2.0.4.jar ./org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar ./org/apache/maven/maven-project/2.0.4/maven-project-2.0.4.jar ./org/apache/maven/maven-settings/2.0.4/maven-settings-2.0.4.jar ./org/apache/maven/maven-profile/2.0.4/maven-profile-2.0.4.jar ./org/apache/maven/maven-artifact-manager/2.0.4/maven-artifact-manager-2.0.4.jar ./org/apache/maven/maven-repository-metadata/2.0.4/maven-repository-metadata-2.0.4.jar ./org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar ./org/apache/maven/maven-artifact/2.0.4/maven-artifact-2.0.4.jar ./org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar ./junit/junit/3.8.1/junit-3.8.1.jar ./classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar ./org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar Main-Class: org.rzo.yajsw.boot.WrapperExeBooter
Archiver-Version: Plexus Archiver
Created-By: 20.0-b11 (Sun Microsystems Inc.)
Any idea how to fix this?
P.S.On further inspection, it appears this flattening is mostly a natural consequence of the jar-building process, and happened in the original Gradle build too. However, I still have all the classpaths on one line, and need to keep them separate... I wonder if this is as a result of the merging of multiple discrete manifests by Gradle?
Looks like the indentation in the POM file was causing spaces to appear in the generated MANIFEST.MF file, and those spaces were being interpreted as indication of line continuation.
I've rejigged the antrun section as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<property name="cp.props"
value="${basedir}/target/assembly/classPath.properties" />
<property name="ls" value="${line.separator}"/>
<concat destfile="${cp.props}">
<string>wrapper.core.classpath=</string>
<filelist dir="${basedir}/target/assembly" files="classPath" />
</concat>
<property file="${cp.props}" />
<echo file="${MANIFEST}"
message="Manifest-Version: 1.0
${ls}Class-Path-Wrapper-Core: ${ls} ${wrapper.core.classpath}${ls}
${ls}Class-Path-Wrapper-Extended: ${ls} ${wrapper.core.classpath}${ls}
${ls}Class-Path-App: ${ls} ${wrapper.core.classpath}${ls}
${ls}Main-Class: org.rzo.yajsw.boot.WrapperExeBooter${ls}" />
<replace file="${MANIFEST}" token="${pathDelim}" value=" " />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
YAJSW seems a bit happier now when referencing the classpaths in the .jar, although I haven't got it quite right yet. Still, pretty happy with this outcome! Hope all my findings are of use to someone - I couldn't find this info on SO or in the Maven docs.
I want to share test resources between 2 modules A and B. In A test resources I have directory with some files. Like this
-dir
----f1
----f2
I've done all according to Share test resources between maven projects . Now from B test I can access to resources using syntax like:
this.getClass().getClassLoader().getResource("dir/f1")
And it's works perfectly fine. But I don't want hardcore all file names like f1 or f2. What I really want is getting all files from directory. Like
File foo = new File(this.getClass().getClassLoader().getResource("dir").getFile());
assert foo.isDirectory()
foo.list()
...
But when I create foo in such way it even doesn't exist (foo.exist() returns false).
How can I deal with it?
Update. Alternative solution using ant
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<configuration>
<target>
<fileset id="d" dir="${basedir}/src/test/resources/dir" includes="*"/>
<pathconvert property="d" refid="d">
<map from="${basedir}/src/test/resources/" to=""/>
</pathconvert>
<touch file="${basedir}/src/test/resources/d/listOfCharts.txt"/>
<echo file="${basedir}/src/test/resources/d/listOfCharts.txt" message="${charts}"/>
</target>
</configuration>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The approach you talk about creates a JAR which can be used in later tests. You can't list the contents of a Jar this way. You need to use Jar you need to read it as a Jar specially
How do I list the files inside a JAR file?
So im trying to use Hibernate Tools to reverse engineer my database and I am just getting into using Freemarker templates to weak the code it generates. The problem is I want to change the name of the DAO classes it generates. By default the DAO classes are named in the form PersonHome however to change the name to PersonDAO i modified the dao/daohome.ftl.
While this did change the generated class name to PersonDAO the java file was still called PersonHome.java.
Is there a place I can also change the generated file name to match the source code?
Ok well I have got to the bottom of it myself. It seems while hibernate tools does support changing the filename the feature is not exposed in the Hibernate tools plugin for Eclipse which is frustrating. Instead I have had to create an ant build script to run the reverse engineering like follows.
<project name="Reverse Engineer" basedir=".">
<path id="toolslib">
<path location="lib/hibernate3.jar" />
<path location="lib/hibernate-tools.jar" />
<path location="lib/freemarker.jar" />
...
<path location="${jdbc.driver.jar}" />
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
<hibernatetool destdir="src">
<jdbcconfiguration
configurationfile="src/hibernate.cfg.xml"
packagename="my.package.name"
revengfile="hibernate.reveng.xml">
</jdbcconfiguration>
<hbmtemplate destdir="src"
templatepath="templates"
template="dao/daohome.ftl"
filepattern="{package-name}/{class-name}DAO.java">
<property key="ejb3" value="false" />
<property key="jdk5" value="true" />
<property key="sessionFactoryName" value="my.HibernateSessionFactory" />
</hbmtemplate>
</hibernatetool>
Use "Generic Exporter <hibernatetemplate>" tool instead of "DAO Code(.java)".
Along with it set the following attributes in the
templatename[customtemplate.ftl] for this we may use the existing daohome.ftl which is available in hibernate-tools.jar.
filePattern as ${package-name}\${class-name}DAO.java
and required properties like sessionFactoryName.
I didn't look closely at this but I think you'll have to modify the DAONewExporter class (see HBX-343 for some inspiration).
I am adding the bits that were missing.
Use case:
Modify DAO names class generated by hibernate tools
Solution:
I used mvn with ant to do this.A roundabout way but its easier for those who have mvn set up.
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask">
<classpath>
<fileset dir="${basedir}/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<target name="gen_hibernate"
description="generate hibernate classes">
<hibernatetool destdir="${basedir}/src/main/java">
<jdbcconfiguration
configurationfile="${basedir}/hibernate.cfg.xml"
packagename="com.bcbsmt.eie.framework.dto"
revengfile="${basedir}/hibernate.reveng.xml">
</jdbcconfiguration>
<hbmtemplate destdir="${basedir}/src/main/java"
templatepath="${basedir}/src/main/resources/template"
template="dao/daohome.ftl"
filepattern="{package-name}/{class-name}DAO.java">
<property key="ejb3" value="false" />
<property key="jdk5" value="true" />
</hbmtemplate>
<hbmtemplate destdir="${basedir}/src/main/java"
templatepath="${basedir}/src/main/resources/template"
template="pojo/Pojo.ftl"
filepattern="{package-name}/{class-name}.java">
<property key="ejb3" value="false" />
<property key="jdk5" value="true" />
</hbmtemplate>
</hibernatetool>
</target>
maven POM:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.bcbsmt
HibernateAnnnotationSample
0.0.1-SNAPSHOT
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>install</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml">
<target name="gen_hibernate" />
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Jars needed:
These jars should be in ${basedir}/lib folder.Versions are as per your wish
asm-1.5.3.jar
cglib-2.1_3.jar
commons-collections-20030418.083655.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
freemarker-2.3.8.jar
hibernate-3.3.2.jar
hibernate-annotations-3.5.6-Final.jar
hibernate-tools-3.2.4.GA.jar
jtidy-r8-20060801.jar
log4j-1.2.17.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
sqljdbc-4.0.jar