ANT and Netbeans GUI project as executable JAR could not find Main class - user-interface

I receive could not ind Main class error message when trying to run jar file.
I am using Netbeans 6.9.1 with GUI framework and part of my ANT file is:
<target name="makeJar" depends="compile">
<delete file="${build.home}/izvrsniProgram.jar"/>
<jar update="true" destfile="${build.home}/izvrsniProgram.jar" basedir="${build.classes}">
<zipfileset dir="${lib}" includes="**/*.jar"/>
<manifest>
<attribute name="Main-Class" value="oat.DesktopApplication2 "/>
<attribute name="stos" value="jeste"/>
</manifest>
</jar>
</target>
<target name="runJAR">
<java jar="${build.home}/izvrsniProgram.jar"/>
</target>
Manifest file is in JAR, ANT_HOME is already set, "lib" contains GUI jar framework.
Please help me solve this issue... because I think of it day and night and could not find what did I do wrong.

The thing that catches my eye is that you are calling the 'zipfileset' task inside of the 'jar' task. If you are trying to compress the jar file, you can achieve that by using the "compress" and "level" attributes on the 'jar' task.
From the manual page for the 'jar' task on the Ant site...
compress - Not only store data but
also compress them, defaults to true.
Unless you set the keepcompression
attribute to false, this will apply to
the entire archive, not only the files
you've added while updating.
level - Non-default level at which file
compression should be performed. Valid
values range from 0 (no
compression/fastest) to 9 (maximum
compression/slowest). Since Ant 1.7
or if you are just trying to add your dependent jars as one zip archive (why?), you could try to zip the jars into your build directory first, then include the zipped file with a 'fileset'.

Related

Return a custom data type from Ant to Maven

I have an Ant script called from Maven to perform some tasks. One such task is to read a text file linewise and use its content to perform text replacements on a huge set of files. The text file will be in the following format on each line:
name#URL#Title
Ant task for this is as follows:
<target name="update-urls" depends="load-ant-contrib">
<loadfile property="file" srcfile="${mapping.file}"/>
<foreach param="file.entry" list="${file}" delimiter="${line.separator}" target="update-template"></foreach>
</target>
<!--Get the name,url and title of each line-->
<target name="update-template">
<propertyregex property="name"
input="${file.entry}"
regexp="(.*)#(.*)#(.*)$"
select="\1"/>
<propertyregex property="url"
input="${file.entry}"
regexp="(.*)#(.*)#(.*)$"
select="\2"/>
<propertyregex property="title"
input="${file.entry}"
regexp="(.*)#(.*)#(.*)$"
select="\3"/>
<echo>${template.name}</echo>
<!--Use title and url to match and replace the URL with the URL in text file-->
<replaceregexp byline="true"
match="(<title>${title} *</title>.*)${url} *"
replace="\1../modified-path/${name}.zip"
flags="g"
encoding="utf-8"
>
<!--Following are the files on which replacement has to happen-->
<fileset dir="${huge.set.of.files}/items">
<include name="**/info.xml"/>
</fileset>
</replaceregexp>
</target>
Since this needs to work on huge set of files, the above solution is not very efficient. I have coded a mutithreaded solution for it in Java which takes up multiple regex expressions(name, value pairs) at once.I've integrated it into my maven project as a mojo.
I'm having trouble with two things:
Framing a data-type to contain a list of name, url, title triplets in Ant.
If I'm successful with step 1., how to return this data structure to POM from where the Ant task got called and decode this data structure to be able to access each element's name, url and title separately..
Can someone guide me on how to go about this..

When causing a makefile to change directory and run ant in that new directory error "JAVA_HOME is not defined correctly"

Even if you have Java and/or ant installed through the windows installers, you still need to set your environment variables. Make sure you are linking your java to a JDK rather than a JRE, my guess as a newbie is that when you are compiling your own code you should always use the JDK as it has all the tools you need.
Original post:
This is all happening on Windows. I call make. It checks out a "code" folder from svn into the directory that makefile is in. Inside "code", is a build.xml. I want my makefile to change to that directory and then run ant on it. I am getting the error in my command prompt:
C:\Users\Ryan\Desktop\maketest>make
svn co (address removed)
Checked out revision 107.
cd code; ant clean compile jar run
uname: not found
basename: not found
dirname: not found
which: not found
Error: JAVA_HOME is not defined correctly.
We cannot execute java
make: *** [runant] Error 1
I checked here http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_5.html#SEC46 and it seems that this should be do-able in my makefile:
runant:
cd code; ant clean compile jar run
as this will open the command in a subshell but it will also run ant in that subshell.
This all works fine if I manually change into the code folder and run ant. I only get this JAVA_HOME not defined correctly error when I try to do this all from a single makefile.
makefile:
commands = checkoutcode checkoutdocs runant
svnCode = https://version-control.adelaide.edu.au/svn/SEPADL15S2UG7/code/
svnDocs = https://version-control.adelaide.edu.au/svn/SEPADL15S2UG7/updateDocs
ifdef version
REVISION = -r$(version)
endif
all: full
full: checkoutcode checkoutdocs runant
# ensure you use a single tab for the commands being run under that name
checkoutcode:
svn co $(svnCode) $(REVISION)
checkoutdocs:
svn co $(svnDocs) $(REVISION)
#change directory into the code folder and compile the code
runant:
cd code; ant clean compile jar run
build.xml:
<project>
<!-- add some property names to be referenced later. first one is lib folder to hold all libraries -->
<property name="lib.dir" value="lib"/>
<!-- images directory used to compile with the images and also add them to the jar -->
<property name="src/images.dir" value="images"/>
<!-- ensure the classpath can see all classes in the lib folder by adding **/*.jar -->
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<!-- "Target" attribute is what we will write as a parameter to ant in the command prompt or terminal -->
<!-- eg. "ant clean" will run the commands inside the target tags, which is just to delete the directory
"build" -->
<target name="clean">
<delete dir="build"/>
<echo message="Cleaned "/>
</target>
<!-- compile command. creates a directory for the classes to be stored in, instead of the root folder
and then compiles everything in the src folder, using the classpath properties we set earlier -->
<target name="compile">
<mkdir dir="build/classes"/>
<javac includeantruntime="false" srcdir="src" destdir="build/classes" classpathref="classpath"/>
<echo message="Compiled "/>
</target>
<!-- jar command. this creates an executable jar file called Robot.jar which can run the program in full.
it uses the images and it uses the lejos libraries and embeds them into the jar -->
<target name="jar">
<jar destfile="Robot.jar" basedir="build/classes">
<fileset dir="src/images" />
<manifest>
<attribute name="Main-Class" value="Main"/>
</manifest>
<!-- this line adds everything in the lib folder to the classes being added to the jar,
ie. the lejos classes ev3 and pc -->
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
</jar>
<echo message="Created JAR "/>
</target>
<!-- run command. runs the program. Running the program in the command prompt or terminal is good
because it allows you to see any exceptions as they happen, rather than hiding them in eclipse -->
<target name="run">
<java jar="Robot.jar" fork="true"/>
<echo message="Run "/>
</target>
</project>
I am required to run this on different machines without any extra configuration performed, and will not be able to confirm the location of Java on those machines - the only guarantee I will get is that Java is installed and the environment variables work.
Just answering to allow you to mark as solved.
Even if you have installed Java with the oracle installer, you still need to create environements variables.
Even if you have Java and/or ant installed through the windows installers, you still need to set your environment variables. Make sure you are linking your java to a JDK rather than a JRE, my guess as a newbie is that when you are compiling your own code you should always use the JDK as it has all the tools you need.

Ant - Using external file to use in patternset

In Ant, we use patternset to include or exclude some set of file using a pattern such as
<unzip src="${tomcat_src}/tools-src.zip"
dest="${tools.home}">
<patternset>
<include name="**/*.java"/>
<exclude name="**/Test*.java"/>
</patternset>
</unzip>
Is Ant capable of taking this patternset from an external file say txt or xml?
Seeing around the Ant the wiki does not mention of such usuage, but i am thinking otherwise.
Consider using includesfile/excludesfile or includes/excludes attributes of patternset.
In case of includes/excludes, you can use values of properties stored in your normal property file.

TeamCity: Scan all files for text

I currently use CC.NET to run an NAnt build file. In the NAnt script, I use the grep task to scan for TODO/BUG/HACK comments, and that report gets folded into the main build report. I'd like to know if that is something already built into TeamCity someway?
Or should I just create another build step to run the same NAnt script. If that is the case, where do I dump the results of that scan and how do I then pull that XML dump into the TeamCity build results? This is what my NAnt target looks like:
<target name="todoScan" description="Generate report on TODO items remaining in code">
<grep output="${base.report.dir}\${projectname}_todoscan.xml" pattern="(?'Type'TODO|BUG|HACK): (?'Text'[^\n\r]*)">
<fileset basedir="${projectdir}">
<include name="**\*.vb" />
<include name="**\*.js" />
<include name="**\*.aspx" />
<include name="**\*.ascx" />
<exclude name="**\*-vsdoc.js" />
<exclude name="**\jquery-1.3.2.js" />
</fileset>
</grep>
</target>
I am not aware of any built-in TeamCity functionality that will perform that operation.
As long as you write the file to an accessible directory you can include it in the artifacts published using the "Artifact paths" field under "1. General Settings". The file will then be accessible from the artifacts tab on the dashboard.
If you like you can then add a new tab to the dashboard that will display your file on each build if you go to "Administration", "Server Configuration", "Report Tabs" and click "Create a new report tab".
I was actually in the same situation, coming from Jenkins where I used a plugin to show things like IDEA/TODO/MUDO. Since I also moved to TeamCity recently, I made a plugin for this. It's very new and very basic, but does what it needs to do for me. If you're interested, it's available on GitHub: Todo TeamCity plugin.

Generate Checksum for directories using Ant build command

I tried to generate the checksum for directory using ant.
I have tried the below command, but it generates recursively inside each folder for each file.
<target name="default" depends="">
<echo message="Generating Checksum for each environment" />
<checksum todir="${target.output.dir}" format="MD5SUM" >
<fileset dir="${target.output.dir}" />
</checksum>
</target>
I just want to generate one checksum for particular directory using Ant command.
How do I do that?
You want to use the totalproperty attribute. As per the documentation this property will hold a checksum of all the checksums and file paths.
e.g.
<target name="hash">
<checksum todir="x" format="MD5SUM" totalproperty="sum.of.all">
<fileset dir="x"/>
</checksum>
<echo>${sum.of.all}</echo>
</target>
Some other general notes.
This is not idempotent. Each time you run it you will get a new value because it includes the previous hash file in the new hash (and then writes a new hash file). I suggest that you change the todir attribute to point elsewhere
It's a good idea to name your targets meaningfully. See this great article by Martin Fowler for some naming ideas
You don't need the depends attribute if there's no dependency.

Resources