I am trying to use Jarbundler to package my Java application to be used on Mac.
As the application is a maven based application I used mvn ant:ant command to convert it to ant; However, when I run it returns an error as following:
Error: Could not find or load main class com.myproject.swing.Main
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyApp" default="package" basedir=".">
<import file="maven-build.xml"/>
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="MyApp">
<bundleapp outputdirectory="dist"
name="MyApp"
displayname="MyApp"
identifier="com.myproject.swing.Main"
mainclassname="com.myproject.swing.Main">
<classpath file="dist/MyApp.jar" />
</bundleapp>
</target>
<!-- ====================================================================== -->
<!-- Help target -->
<!-- ====================================================================== -->
<!-- <target name="help">
<echo message="Please run: $ant -projecthelp"/>
</target> -->
</project>
*The main class is located in following address
src > main > java > com > myproject > swing > Main
Compiler compliance level is 1.8
Related
I am new to jacoco and trying to add jacoco coverage for a web application. i saw some links and came to know that we have to add javaagent below are the things that i did.
build.xml
<?xml version="1.0" ?>
<project xmlns:jacoco="antlib:org.jacoco.ant" name="Example Ant Build with JaCoCo" default="rebuild">
<description>
Example Ant build file that demonstrates how a JaCoCo coverage report can be itegrated into an existing build in three simple steps.
</description>
<property name="src.dir" location="./src"/>
<property name="result.dir" location="./target"/>
<property name="result.classes.dir" location="${result.dir}/classes"/>
<property name="result.report.dir" location="${result.dir}/site/jacoco"/>
<property name="result.exec.file" location="${result.dir}/jacoco.exec"/>
<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="../../../lib/jacocoant.jar"/>
</taskdef>
<target name="clean">
<delete dir="${result.dir}"/>
</target>
<target name="compile">
<mkdir dir="${result.classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" includeantruntime="false"/>
</target>
<target name="test" depends="compile">
<!--
Step 2: Wrap test execution with the JaCoCo coverage task
-->
<jacoco:coverage destfile="${result.exec.file}" includes="*">
<java classname="com.antspringmvc.exp.Math" fork="true" >
<classpath path="${result.classes.dir}"/>
</java>
</jacoco:coverage>
</target>
<target name="report" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!--
This task needs the collected execution data and ...
-->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}"/>
<csv destfile="${result.report.dir}/report.csv"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>
</target>
<target name="rebuild" depends="clean,compile,test,report"/>
</project>
I have added the below code to my tomcat:
if ""%1"" == ""stop"" goto skip_agent
set "JAVA_OPTS=%JAVA_OPTS% -javaagent: C:\Users\kk\Desktop\Personal\jars\jacocoagent.jar=destfile=C:\Users\kk\Desktop\Personal\WorkSpace\JacocoExample\target\jacoco.exec,append=true,output=tcpserver,address=localhost,port=8080,includes=*"
i thought after stopping the server the report will be generated but that has not happened.
am i missing something in the configuration
From your build.xml seems that you expect JaCoCo agent to generate jacoco.exec file, however according to
if ""%1"" == ""stop"" goto skip_agent
set "JAVA_OPTS=%JAVA_OPTS% -javaagent: C:\Users\kk\Desktop\Personal\jars\jacocoagent.jar=destfile=C:\Users\kk\Desktop\Personal\WorkSpace\JacocoExample\target\jacoco.exec,append=true,output=tcpserver,address=localhost,port=8080,includes=*"
you configure agent with output=tcpserver, which means quoting documentation at http://www.jacoco.org/jacoco/trunk/doc/agent.html :
The agent listens for incoming connections on the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
When I run my code in the console, it runs fine. It also runs fine on eclipse. But when I try to build on Jenkins, it is asking for a src folder:
"C:\Program Files (x86)\Jenkins\Work space\job1\src" does not exist!
build.xml
<project name="Sample Ant build" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<!-- set global properties for build -->
<property name="basedir" value="." />
<property name="lib" value="${basedir}/lib" />
<property name="src" value="${basedir}/src" />
<property name="bin" value="${basedir}/bin" />
<property name="report-dir" value="${basedir}/Test-Report" />
<property name="testng-report-dir" value="${report-dir}/TestNGreport" />
<!-- ====== Set the classpath ==== -->
<path id="classpath">
<pathelement location="${bin}" />
<fileset dir="C:\WebDriver\Selenium">
<include name="*.jar" />
</fileset>
</path>
<!-- Delete directories -->
<target name="delete-dir">
<delete dir="${bin}" />
<delete dir="${report-dir}" />
</target>
<!-- Creating directories -->
<target name="create" depends="delete-dir">
<mkdir dir="${bin}" />
<mkdir dir="${report-dir}" />
</target>
<!-- Compile the java code from ${src} into ${bin} -->
<target name="compile" depends="create">
<javac srcdir="${src}" classpathref="classpath" includeAntRuntime="No" destdir="${bin}" />
<echo> /* Compiled Directory Classes */ </echo>
</target>
<!-- Runs the file and generates Reportng report for TestNG-->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="classpath" />
<target name="testng-execution" depends="compile">
<mkdir dir="${testng-report-dir}" />
<testng outputdir="${testng-report-dir}" classpathref="classpath" useDefaultListeners="true">
<xmlfileset dir="${basedir}" includes="testng.xml" />
</testng>
</target>
Eclipse uses a workspace, Jenkins uses a workspace (and in our case, TFS also uses a workspace). They are not the same thing. (Your query is missing some details to answer authoritatively, some some assumptions were made)
Your build.xml script sets BASEDIR to ".", or the working directory. For a Jenkins job, that is as below - See Administering Jenkins:
JENKINS_HOME
+- workspace (working directory for the version control system)
+- [JOBNAME] (sub directory for each job)
In your case, JENKINS_HOME\workspace\[JOBNAME] is C:\Program Files (x86)\Jenkins\Work space\job1.
My money is that is not where your Eclipse workspace is mapped to.
I would make the following recommendations:
Develop your code and test it in Your Eclipse IDE. When satisfied, commit to your version control system (VCS).
Setup Jenkins to pull code from your VCS into the local workspace of your job and build there. As it's separate to your working copy it helps isolate changes and ensures you have committed everything to source control so your builds come from a know, reproducible source.
Set JEKNINS_HOME to a location outside of C:\Program Files ...; it's bad practice to place data (like source files and a build) in a location from installation binaries. Lots of goods reasons to do so, including security, easier space management, etc.
Choose an appropriate location and set the directory configurations for the Master (Jenkins | Manage Jenkins | Configure System; the first 3 values)
IF using distributed builds (master/node), within your node configuration (Jenkins | Manage Jenkins | Manage Nodes | Configure => Remote Root directory ) to an appropriate location
I wrote some Nutch plugin with using different extension points such as Protocol, Parser and etc. These plugins work perfectly inside eclipse. But in order to use them on hadoop cluster it should be built by using ANT. My problem is, I wrote some classes in some new packages inside core folder(src). These classes are shared cross different developed plugins. My problem is at build time of developed plugins, ANT can not find the mentioned shared classes, so I am unable to complete the build process successfully. For better understanding of my problem Here is build.xml of one of my plugins:
<project name="filter-news" default="jar-core">
<import file="../build-plugin.xml"/>
<!-- Build compilation dependencies -->
<target name="deps-jar">
<ant target="jar" inheritall="false" dir="../lib-xml"/>
</target>
<!-- Add compilation dependencies to classpath -->
<path id="plugin.deps">
<fileset dir="${nutch.root}/build">
<include name="**/lib-xml/*.jar" />
</fileset>
</path>
<!-- Deploy Unit test dependencies -->
<!-- Deploy Unit test dependencies -->
<!-- for junit test -->
</project>
ivy.xml:
<ivy-module version="1.0">
<info organisation="org.apache.nutch" module="${ant.project.name}">
<license name="Apache 2.0"/>
<ivyauthor name="Apache Nutch Team" url="http://nutch.apache.org"/>
<description>
Apache Nutch
</description>
</info>
<configurations>
<include file="../../..//ivy/ivy-configurations.xml"/>
</configurations>
<publications>
<!--get the artifact from our module name-->
<artifact conf="master"/>
</publications>
<dependencies>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.31"/>
<dependency org="net.sourceforge.htmlcleaner" name="htmlcleaner" rev="2.2"/>
<dependency org="commons-jxpath" name="commons-jxpath" rev="1.3"/>
</dependencies>
</ivy-module>
plugin.xml:
<plugin id="filter-news" name="Apache Nutch XML/HTML Parser/Indexing Filter" version="1.4" provider-name="nutch.org">
<runtime>
<library name="filter-news.jar">
<export name="*"/>
</library>
<library name="ant-1.7.0.jar"/>
<library name="ant-launcher-1.7.0.jar"/>
<library name="jdom-1.1.jar"/>
<library name="commons-jxpath-1.3.jar"/>
<library name="htmlcleaner-2.2.jar"/>
<library name="mysql-connector-java-5.1.31.jar"/>
</runtime>
<requires>
<import plugin="nutch-extensionpoints"/>
</requires>
<extension id="org.apache.nutch.parse" name="Nutch XML/HTML Html parser filter" point="org.apache.nutch.parse.HtmlParseFilter">
<implementation id="com.ictcert.nutch.filter.news.NewsHtmlFilter" class="com.ictcert.nutch.filter.news.NewsHtmlFilter" />
</extension>
<extension id="org.apache.nutch.indexer" name="Nutch XML/HTML Indexing Filter" point="org.apache.nutch.indexer.IndexingFilter">
<implementation id="com.ictcert.nutch.filter.news.NewsIndexingFilter" class="com.ictcert.nutch.filter.news.NewsIndexingFilter"/>
</extension>
</plugin>
When I try to build this plugin ant can not find all of the class dependencies related to com.ictcert.nutch package which is located in core part of nutch (src). While for other classes located in org.apache.nutch I have not such problem. Would you please tell me what is wrong with my configuration that the default packages could be found by ANT but the new ones could not.
As far as I know from my experience the implementation id should have the same package structure as your extension point. Can you try that and see if it solves your problem.
From my build.xml:
<?xml version="1.0" encoding="utf-8" ?>
<project name="myapp" default="package-core" basedir=".."
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:antcontrib="antlib:net.sf.antcontrib">
<target name="bootstrap">
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="build.path"/>
</target>
<target name="resolve" depends="bootstrap">
<ivy:settings url="${ivy.settings.home}"/>
<ivy:cleancache/>
<ivy:resolve file="build/${ivy.xml}"/>
<ivy:retrieve pattern="${gen.lib.main.dir}/[artifact]-[revision].[ext]" conf="main"/>
<ivy:report todir="${gen.staging.dir}" />
</target>
...omitted for brevity
<target name="publish" depends="compile">
<ivy:publish resolver="default-resolver" pubrevision="0.2.0" overwrite="true" update="true">
<artifacts pattern="${gen.dist.pub.dir}/[artifact].[ext]" />
</ivy:publish>
</target>
My ivy.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="myapp" module="myapp"/>
<configurations>
<conf name="main" description="provides main dependencies for the client JAR"/>
</configurations>
<dependencies>
<!-- Main dependencies. -->
<dependency org="google" name="guava" rev="14.0" conf="main->*"/>
<dependency org="google" name="guice" rev="3.0" conf="main->*"/>
</dependencies>
</ivy-module>
My ivy-settings.xml:
<ivysettings>
<properties file="ivy-settings.properties"/>
<settings defaultResolver="default-resolver"/>
<latest-strategies>
<latest-lexico/>
</latest-strategies>
<credentials host="${ivy.repo.root}" realm="${ivy.std.repo.realm}"
username="${ivy.std.repo.username}" password="${ivy.std.repo.password}"/>
<resolvers>
<chain name="default-resolver" returnFirst="true">
<url name="std-repo">
<ivy pattern="${ivy.repo.root}/${ivy.module.pattern}"/>
<artifact pattern="${ivy.repo.root}/${ivy.artifact.pattern}"/>
</url>
</chain>
</resolvers>
<modules>
<module organisation="myapp" name="*" resolver="default-resolver"/>
</modules>
</ivysettings>
Question:
When I run the resolve target, I successfully pull down the Guava and Guice JARs (and all their dependencies). So I know I have this set up, at least partially correct.
But when I run the publish target, I get the following error:
[jar] Building jar: /home/myuser/sandbox/dsi/workbench/eclipse/workspace/myapp/gen/dist/myapp-server
publish:
[ivy:publish] :: loading settings :: url = jar:file:/home/myuser/sandbox/dsi/workbench/eclipse/4.2/eclipse/plugins/org.apache.ivy.eclipse.ant_2.3.0.final_20130110142753/ivy.jar!/org/apache/ivy/core/settings/ivysettings.xml
BUILD FAILED
/home/myuser/sandbox/dsi/workbench/eclipse/workspace/myapp/build/build-core.xml:289: no organisation provided for ivy publish task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>
Any ideas? Thanks in advance!
You have to call 'publish' and 'resolve' in the same Ant session. If you call them separately it won't work and you'll get this error message.
For instance, you could let the 'publish' target depend on the 'resolve' target:
<target name="publish" depends="resolve,compile">
...
</target>
Hope this helps,
Maarten
My Ant code
<?xml version="1.0" encoding="UTF-8"?>
<project default="plugin_export" name="build">
<target name="plugin_export">
<pde.exportPlugins destination="C:\" exportSource="false" exportType="directory" plugins="MyPlugin" useJARFormat="true" allowbinarycycles="true" filename="MyPlugin.jar" qualifier="X" />
<waitfor maxwait="15" maxwaitunit="minute">
<copy todir="j:\eclipse-rcp-juno-SR1-win32\dropins\">
<fileset dir="c:\plugins\">
<include name="*" />
</fileset>
</copy>
</waitfor>
</target>
</project>
it doesn't work, because I get
windows_build.xml:8: waitfor doesn't support the nested "copy" element.
pde.exportPlugins part is auto-generated by eclipse and it runs background process that creates jar with a plugin.
I would like to copy that plugin into 3 instances of eclpse I do use and put it in the dropins folder.
How to do it ?
To get things done after your build has finished, you may use a buildlistener.Kev Jackson implemented a very useful exec-listener in his presentation =http://people.apache.org/~kevj/ossummit/extending-ant.html (sources are included in the presentation).
For each build result ( BUILD SUCCESSFUL | BUILD FAILED ) it provides a taskcontainer
you can put all your stuff in that should run AFTER Build has finished :
<exec-listener onSuccess="true">
<echo>Executing after BUILD SUCCESSFUL...</echo>
<exec executable="..">
<arg value="..."/>
</exec>
<mail ... />
..other tasks
</exec-listener>
<exec-listener onSuccess="false">
<echo>Executing after BUILD FAILED...</echo>
<exec executable="..">
<arg value="..."/>
</exec>
<mail ... />
..other tasks
</exec-listener>