Using jarbundler ant task to add dependencies to the app - macos

I have a Netbeans Java project. When I build my project it create a directory dist and dist/lib. It stores the Jar of the file in dist and other jar files on which the main jar file depends, in the lib directory.
Now I want to create a release for OSX. For that I am using the jarbundler ant task like this
<target name="mac">
<mkdir dir="release"/>
<taskdef name="jarbundler"
classname="net.sourceforge.jarbundler.JarBundler" />
<jarbundler dir="release"
name="MyApp"
mainClass="controller.MyApp"
jar="dist/MyApp.jar" />
</target>
This creates the app with the jar, but how do I add the dependent libraries to the app.

This is what is needed
The jar attribute should be replaced with jarfileset like this.
<target name="mac">
<mkdir dir="release"/>
<taskdef name="jarbundler"
classname="net.sourceforge.jarbundler.JarBundler" />
<jarbundler dir="release"
name="MyApp"
mainClass="controller.MyApp">
<jarfileset dir="dist">
<include name="**/*.jar" />
</jarfileset>
</jarbundler>
</target>

Related

create executable jar including external jar file from Netbeans 8.0.2 and java 8

I want to create executable jar file which includes my external jar files,
I am using Netbeans 8.0.2 and Java 8
I tried updating build.xml using solution provided on internet and stackoverflow,
But external jars files are not getting included into my single executable jar file.
I have tried this too
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="myProject"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
I have also tried this
How to build a fat jar using Netbeans
it created a single jar file but it doesn't include my external dependency.
Can anyone help me on how can I include my external jars into single executable jar using Netbeans 8.0.2 and java8
I have finally found the answer,
I used below configuration in build.xml
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="DocumentProtector"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar} mainclass ${main.class}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
after clean+build
right click build.xml and goto Other target and click on package-for-store
but after doing this I was getting wrong main class
so after little research i found the solution to change main class
go to project folder -> nbproject and open project.properties file
and change main.class to you mail class file name with package name
like this main.class=com.test.package.MainClass
and clean+build and again
right click build.xml and goto Other target and click on package-for-store

Exclude a file or a list of files from being copied during Maven build process

How to exclude a file from being copied during maven build process :
<copy todir="target/classes/META-INF/config" overwrite="true" failonerror="false">
<fileset dir="src/main/resources/" />
<!-- something like <fileset dir="src/main/resources/" excludes="fileA.properties" /> for excluding fileA.properties from being copied to the target folder -->
</copy>

How to convert an ant snippet to Gradle

Hi I am completely new to Gradle. Can anyone please help me as to how I can convert this ant task into Gradle. I am trying to see if I can learn by example.
<property file="build.properties"/>
<path id="classpath">
<fileset dir="${ear.dir}/EarContent/APP-INF">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete file="${dist.dir}/*.jar" failonerror="false"/>
<delete failonerror="false">
<fileset dir="${build.dir}">
<include name="**/*.class" />
</fileset>
</delete>
</target>
<target name="init">
<mkdir dir="${dist.dir}"/>
<mkdir dir="${build.dir}/classes"/>
</target>
<target name="jar" depends="clean, init">
<javac srcdir="${src.dir}" destdir="${build.dir}/classes" debug="on">
<classpath refid="classpath"/>
</javac>
<jar destfile="${dist.dir}/phIntegration.jar">
<fileset dir="${build.dir}/classes" />
</jar>
</target>
I'm not convinced that trying move ANT build 1-1 to Gradle is a good learning exercise, although Gradle provides good integration with ANT.
Generally speaking, the build.gradle file for your project shall like somewhat like that:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'CLASSPATH_DIR', include: ['**/*.jar'])
//if you want you can use JARS from your filesystem as a classpath
//but you probably should use Ivy or Maven dependency management systems
}
sourceSets {
main {
java 'src/main/java'
//tweak the location of your source code, by default Gradle looks for sources in `src/main/java`
}
}
Once you invoke gradle clean build it will compile your sources and create a jar file containing the sources in build/libs directory. You can change the JARS name by adding the rootProject.name='your project name' in the settings.gradle directory.
The snippet uses Java plugin and the default behaviour of Gradle. If you want you can tweak its behaviour by using Delete Task or Jar Task.
If you define properly inputs/outputs of a task the init task won't be necessary since Gradle will take care of directories recreation if they're not existent. (Default tasks do that, if you start writing your own tasks you most probably will have to take care of that by your own)

srcdir attributes must be set

Im trying to migrate my code from ant to gradle and imported my build.xml in build.gradle and some of my tasks work fine.
However there are some tasks when i run them it says
Execution failed for task ':compile'.
srcdir attribute must be set!
Pasting a snippet of my Build.xml and the compile task below is failing.
<project basedir="." default="deploy" name="FitNesse">
<property name="fitnesse.target" value="/build/test-fitnesse"/>
<patternset id="test.patternset">
<include name="**/*Test*.java"/>
</patternset>
<propertyset id="test.propertyset">
<propertyref name="basedir"/>
<propertyref name="test.patternset"/>
</propertyset>
<fileset id="classpath.fitnesse" dir="./libs">
<include name="antlr-2.7.7.jar"/>
<include name="asm-4.1.jar"/>
<include name="asm-analysis-4.1.jar"/>
<include name="asm-commons-4.1.jar"/>
<include name="asm-tree-4.1.jar"/
><target name="compile" description="Compile java sources" depends="clean">
<mkdir dir="build/classes"/>
<javac includeantruntime="false"/>
<javac srcdir="src/main/java" destdir="build/classes" debug="on">
<classpath refid="classpath.compile"/>
<compilerarg value="-processorpath"/>
<compilerarg value="-AmethodConstraintsSupported=true"/>
</javac>
</target>
Source folder structure
/src/main/java/com/xebia/inc/xeb
I had changed my src folder structure from ant "src" to a gradle project "/src/main/java/com/xebia/incubator/xebium". and lib folder to libs
Please help. I'm kind of novice to this.
Thanks,
The full error message should give you the line number and it's most probably the line that contains
<javac includeantruntime="false"/>
which looks like a copy-paste error.

Izpack installer for non-java applications

Can the Izpack installer be used to install a non-java application?
Thanks,
Abdulfattah.
It should be. It will bundle everything together in a jar file. For the pack tag of the install file, call the following:
<pack name="PROJECTPACKNAME" required="yes" preselected="yes"
installGroups="New Application">
<description>PROJECT install</description>
<file src="#{DIRECTORYNAME.dir}" targetdir="$INSTALL_PATH" />
</pack>
For DIRECTORYNAME, you have to declare a property in your build file, ie:
<property name="DIRECTORYNAME.dir" value="/apps/MyProjectName"/>
then have a target in the build file:
<target name="SftWreBundle" depends="init" description="build the software bundle">
<taskdef name="izpack" classpath="${izpack.dir}/lib/standalone-compiler.jar" classname="com.izforge.izpack.ant.IzPackTask" />
<izpack input="install.xml" output="${dist}/${product.short.name}-${product.version}-install.jar"
installerType="standard" inheritAll="true"
basedir="${basedir}" compression="deflate" compressionlevel="9" />
</target>
You may want to clean your working directory before running this target.

Resources