Sharing test resourcing between modules issue - java

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?

Related

Seperate spring.factories into multiple files

In Spring Boot, you can do the following:
src/main/resources/META-INF/spring.factories
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration,\
org.springframework.boot.autoconfigure.admin.CConfiguration,\
org.springframework.boot.autoconfigure.admin.DConfiguration,\
org.springframework.boot.autoconfigure.admin.EConfiguration,\
org.springframework.boot.autoconfigure.admin.FConfiguration,\
Which is very nice. However after a year of development the list of auto configuration is now > 15 lines, which makes it hard to manage.
Would like to know if it is possible to separate the spring.factories into multiple files? Preferably would like to keep the whole project in one JAR.
Or maybe there is another ways to help organize the EnableAutoConfiguration that I am not aware of?
Thanks in advance!
While using spring-boot we use multiple "starters", each with an auto-configuration and spring.factories file.
So, one way could be to split your project into modules - one for each auto-configuration, define a dedicated spring.factories file in the module, and import all the modules as a runtime dependency in the main application module.
You can use maven or gradle to manage the multi-module project and the dependencies among them:
Gradle: https://guides.gradle.org/creating-multi-project-builds/
Maven: https://www.baeldung.com/maven-multi-module
Example:
root
moduleA
src/main/resources/META-INF/spring.factories
moduleB
src/main/resources/META-INF/spring.factories
and so on...
I have found a solution for this question.
Note: This exact solution assume that you only used EnableAutoConfiguration in your spring.factiores, it would crash if you use more than one type of config inside spring.factories.
One can do:
src/main/resources/META-INF/spring.factories
src/main/resources/META-INF/spring-2.factories
src/main/resources/META-INF/spring-3.factories
src/main/resources/META-INF/spring-4.factories
and merge this into one file.
Note, I am using Maven Antrun but I suspect Gradle would also have a similar feature.
In your pom.xml, add the following:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>default-ci</id>
<goals>
<goal>run</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<target>
<replace token='org.springframework.boot.autoconfigure.EnableAutoConfiguration=' value=','
dir="${project.build.directory}/classes/META-INF">
<include name="spring-*.factories"/>
</replace>
<concat destfile="${project.build.directory}/classes/META-INF/spring.factories" overwrite="yes" append="yes">
<fileset dir="${project.build.directory}/classes/META-INF" includes="spring-*.factories" />
</concat>
</target>
</configuration>
</execution>
</executions>
</plugin>
And in spring.factories is the normal config:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration
But in spring-2.factories and others, you start with ,\ instead of the default statement:
spring-2.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.CConfiguration
spring-3.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.DConfiguration
After all that, the outcome spring.factories in your output class directories will be a very nice:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration,\
org.springframework.boot.autoconfigure.admin.CConfiguration,\
org.springframework.boot.autoconfigure.admin.DConfiguration

maven-antrun-plugin skips an execution

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" />

Can Hibernate Schema generation be used to generate DDL without database connection

I'd like to use Hibernate' schema generation to generate DDL for a database that I cannot access directly from my PC, just using hibernate config files. I'd like to skip, if possible, the installation of a local oracle database. Can hibernate generate DDL for a "theoretical" database of the appropriate dialect, version, etc., or is this a pipe dream?
Are there other tools that can do this?
You can either use an In-memory database during testing phase;
hibernate.hbm2ddl.auto="update"
Or you can generate your DDL using the hibernatetool from Maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-test-sql-scripts</id>
<phase>generate-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<property name="maven_test_classpath" refid="maven.test.classpath"/>
<path id="hibernate_tools_path">
<pathelement path="${maven_test_classpath}"/>
</path>
<property name="hibernate_tools_classpath" refid="hibernate_tools_path"/>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"/>
<mkdir dir="${project.build.directory}/test-classes/hsqldb"/>
<hibernatetool destdir="${project.build.directory}/test-classes/hsqldb">
<classpath refid="hibernate_tools_path"/>
<jpaconfiguration persistenceunit="testPersistenceUnit"
propertyfile="src/test/resources/META-INF/spring/jdbc.properties"/>
<hbm2ddl drop="false" create="true" export="false"
outputfilename="create_db.sql"
delimiter=";" format="true"/>
<hbm2ddl drop="true" create="false" export="false"
outputfilename="drop_db.sql"
delimiter=";" format="true"/>
</hibernatetool>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
This Maven plugin will generate the following DDL files:
create_db.sql (containing all DDL statements for creating the DB)
drop_db.sql (containing all DDL statements for dropping the DB)
As of hibernate-tools 5.3 you can also use the integrated hibernate-tools-maven-plugin. There you should also find documentation on how to use it.
Unfortunatelly the maven-site with detailed description of the parameters/goals for it is not yet published but a little bit older version of it is available here.
There would be a PR (#842) that would allow for the site to be generated... unfortunatelly it hasn't found its way in yet.

Maven: zip resources and save into specific folder

For a project I need to zip a number of resource files and put this archive inside the project source (src/main/resources). The idea is that this archive then ends up in the EAR and goes to the deployment server, where it is picked up by a script for further processing. Convoluted, I know, but those are the constraints we are working with.
I've created an Assembly plugin configuration file that creates the zip, but this zip is placed by default in a target/ folder.
The assembly plugin has an outputDirectory option, but this only changes the filestructure of the contents of the zip, not the location where the zip is saved.
Is there a way to specify where the assembly plugin saves the created zip? Or is there a better way altogether to zip resources?
there are two outputDirectory configuration, one represents the file path inside your assembled package,
another one represents directory where your assembled package would be output
you are looking for second one
Please add the following code in pom.xml , provide the path in outputDirectory tag :
<execution>
<id>assembly-execution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zipFileName</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${project.basedir}/zip.xml</descriptor>
</descriptors>
<outputDirectory>${project.basedir}/src/main/resources</outputDirectory>
</configuration>
</execution>

Generating custom manifests with Maven and multiple specially-named classpaths

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.

Categories

Resources