I'm looking to introduce Jbehave in my project, and I am preparing a simple POC.
Using: jbehave 3.9.3, ant 1.9.2, IDE eclipse kepler.
I can successfully run the tests from within Eclipse (I've also annotated my test class with #RunWith(JUnitReportingRunner.class) ).
I have, however, some issues when I try running the same via ant.
this is the ant file I'm using:
<property name="src.dir" value="${basedir}/bdd/jbtest"/>
<property name="jbehave.version" value="3.9.3"/>
<target name="clean">
<delete dir="target" />
</target>
<target name="setup">
<artifact:dependencies filesetId="dependency.fileset" useScope="test">
<dependency groupId="org.jbehave" artifactId="jbehave-ant" version="${jbehave.version}"/>
<dependency groupId="org.jbehave" artifactId="jbehave-core" version="${jbehave.version}" classifier="resources" type="zip"/>
<dependency groupId="org.jbehave.site" artifactId="jbehave-site-resources" version="3.1.1" type="zip"/>
</artifact:dependencies>
<mkdir dir="target" />
<mkdir dir="target/classes" />
<mkdir dir="target/lib" />
<copy todir="target/lib">
<fileset refid="dependency.fileset" />
<mapper type="flatten" />
</copy>
<!-- copy todir="${src.dir}">
<fileset dir="../core/src/main/java">
</fileset>
</copy> -->
<copy todir="target/classes">
<fileset dir="${src.dir}">
<include name="**/*.story" />
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
<path id="story.classpath">
<fileset dir="${basedir}/lib" includes="**/*.jar" />
<pathelement location="${basedir}/bin" />
</path>
<classloader classpathref="story.classpath" />
<pathconvert targetos="unix" property="story.classpath.unix" refid="story.classpath">
</pathconvert>
<echo>Using classpath: ${story.classpath.unix}</echo>
</target>
<target name="compile" depends="setup">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="bin" debug="on" debuglevel="lines,source" includes="**/*.java,**/*.xml">
<classpath refid="story.classpath" />
</javac>
</target>
<target name="reports-resources" depends="setup">
<unzip src="${org.jbehave:jbehave-core:zip:resources}" dest="${basedir}/target/jbehave/view/" />
<unzip src="${org.jbehave.site:jbehave-site-resources:zip}" dest="${basedir}/target/jbehave/view/" />
</target>
<target name="run-stories-as-embeddables" depends="compile, reports-resources">
<taskdef name="runStoriesAsEmbeddables" classname="org.jbehave.ant.RunStoriesAsEmbeddables" classpathref="story.classpath" />
<runStoriesAsEmbeddables sourceDirectory="${src.dir}" includes="**/Myjb.java" excludes="**/examples*" batch="false" ignoreFailureInStories="true" ignoreFailureInView="true" generateViewAfterStories="true"
systemproperties="java.awt.headless=true,project.dir=${basedir}" />
</target>
<target name="run-stories-as-paths" depends="compile, reports-resources" >
<taskdef name="runStoriesAsPaths" classname="org.jbehave.ant.RunStoriesAsPaths" classpathref="story.classpath" />
<runStoriesAsPaths sourceDirectory="${src.dir}"
includes="**/*.story" batch="false" ignoreFailureInStories="true" ignoreFailureInView="true" generateViewAfterStories="true"
systemproperties="java.awt.headless=true,project.dir=${basedir}"
>
</runStoriesAsPaths>
</target>
<target name="stepdoc" depends="compile">
<taskdef name="reportStepdocs" classname="org.jbehave.ant.ReportStepdocs" classpathref="story.classpath" />
<reportStepdocs embedderClass="org.jbehave.examples.core.CoreEmbedder" />
<taskdef name="reportRenderer" classname="org.jbehave.ant.ReportRendererTask" classpathref="story.classpath" />
<reportRenderer outputDirectory="${basedir}/target/jbehave"
formats="txt,html" templateProperties="defaultFormats=stats"
ignoreFailure="true"/>
</target>
<target name="build" depends="run-stories-as-paths,stepdoc" />
</project>
issue #1: I can't specify the format
run-stories-as-paths:
[runStoriesAsPaths] Running stories as paths using embedder Embedder[storyMapper=StoryMapper,storyRunner=StoryRunner,embedderMonitor=AntEmbedderMonitor,classLoader=EmbedderClassLoader[urls=[],parent=java.net.URLClassLoader#1a8fa0f0],embedderControls=UnmodifiableEmbedderControls[EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=true,ignoreFailureInView=true,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,failOnStoryTimeout=false,threads=1]],embedderFailureStrategy=<null>,configuration=org.jbehave.core.configuration.MostUsefulConfiguration#5556d74f,candidateSteps=<null>,stepsFactory=<null>,metaFilters=<null>,systemProperties={java.awt.headless=true, project.dir=D:danielewsjbtest},executorService=<null>,executorServiceCreated=false,storyManager=<null>]
[runStoriesAsPaths] Found story paths: [Example.story, Sample.story]
[runStoriesAsPaths] Processing system properties {java.awt.headless=true, project.dir=D:danielewsjbtest}
[runStoriesAsPaths] System property 'java.awt.headless' set to 'true'
[runStoriesAsPaths] System property 'project.dir' set to 'D:danielewsjbtest'
[runStoriesAsPaths] Using controls UnmodifiableEmbedderControls[EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=true,ignoreFailureInView=true,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,failOnStoryTimeout=false,threads=1]]
[runStoriesAsPaths] Generating reports view to 'D:\daniele\ws\jbtest\target\jbehave' using formats '[]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports-with-totals.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
[runStoriesAsPaths] Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending)
I did not find a way to pass the format as I'm doing in the java class and that get's ignored, so it does not generate any report.
issue #2 story finding exception
when I run
ant -f jb_ant.xml -lib lib run-stories-as-paths
just after the output shown above, I get an exception
BUILD FAILED
D:\daniele\ws\jbtest\jb_ant.xml:74: org.jbehave.core.io.StoryResourceNotFound: Story path 'Example.story' not found by class loader EmbedderClassLoader[urls=[],parent=java.net.URLClassLoader#1a8fa0f0]
at org.jbehave.core.io.LoadFromClasspath.resourceAsStream(LoadFromClasspath.java:44)
at org.jbehave.core.io.LoadFromClasspath.loadResourceAsText(LoadFromClasspath.java:29)
at org.jbehave.core.io.LoadFromClasspath.loadStoryAsText(LoadFromClasspath.java:38)
at org.jbehave.core.embedder.StoryRunner.storyOfPath(StoryRunner.java:192)
at org.jbehave.core.embedder.StoryManager.storyOfPath(StoryManager.java:49)
at org.jbehave.core.embedder.StoryManager.runningStoriesAsPaths(StoryManager.java:101)
at org.jbehave.core.embedder.StoryManager.runStories(StoryManager.java:78)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:203)
at org.jbehave.ant.RunStoriesAsPaths.execute(RunStoriesAsPaths.java:16)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
which is puzzling me because jbehave had just listed the found the story while executing the task.
I can post the both the Java classes and stories if this may help diagnose the problem.
Any ideas what am I doing wrong?
After a while, I found an answer to these issues:
the org.jbehave.core.io.StoryResourceNotFound exception was resolved by implementing a StoryFinder Class (code below)
to generate the reports, I had to implement an Embedder class (code below) and specify the formats there (apparently there is no way to pass this directly to the Ant tasks.
Hope this helps anyone else with similar problems.
StoryFinder
package jbtest;
import org.jbehave.core.io.StoryFinder;
import java.util.*;
public class MyStoryFinder extends StoryFinder {
#Override
protected List<String> scan(String basedir, List<String> includes,
List<String> excludes) {
//List<String> defaultStories = super.scan(basedir, includes, excludes);
//String myStories = System.getProperty("com.sarang.stories");
return Arrays.asList("jbtest/Example.story,jbtest/Sample.story".split(","));
}
}
Embedder
package jbtest;
import java.text.SimpleDateFormat;
import java.util.Properties;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.embedder.Embedder;
import org.jbehave.core.embedder.EmbedderControls;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.jbehave.core.steps.ParameterConverters;
import org.jbehave.core.steps.SilentStepMonitor;
public class MyEmbedder extends Embedder {
#Override
public EmbedderControls embedderControls() {
return new EmbedderControls().doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
}
#Override
public Configuration configuration() {
Class<? extends MyEmbedder> embedderClass = this.getClass();
Properties viewResources = new Properties();
viewResources.put("decorateNonHtml", "true");
return new MostUsefulConfiguration()
.useStoryReporterBuilder(
new StoryReporterBuilder()
.withDefaultFormats()
.withViewResources(viewResources).withFormats(Format.CONSOLE, Format.HTML, Format.XML)
.withFailureTrace(true)
) ;
}
#Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new ExampleSteps(), new SampleSteps());
}
}
Then I modified the Ant task as follows:
<target name="run-stories-as-paths" depends="compile, reports-resources" >
<taskdef name="runStoriesAsPaths" classname="org.jbehave.ant.RunStoriesAsPaths" classpathref="story.classpath" />
<runStoriesAsPaths
sourceDirectory="${src.dir}"
includes="**/*.story"
ignoreFailureInStories="true"
ignoreFailureInView="true"
generateViewAfterStories="true"
storyfinderclass="jbtest.MyStoryFinder"
verbosefailures="true"
embedderclass="jbtest.MyEmbedder"
>
</runStoriesAsPaths>
</target>
Related
I am using JDK 1.7, eclipse 4.2.2, JUnit 4.8.1, ant 1.9.2, windows8 64 bit** When I am running my build.xml, all targets run fine but the target with name as run is not running fine.
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntExample" default="setclasspath" basedir=".">
<!-- Properties Initialization -->
<property environment="env"/>
<property name="ws.home" value="${basedir}" />
<property name="ws.jar" value="${basedir}/lib" />
<property name="test.dest" value="${basedir}/build" />
<property name="test.src" value="${basedir}/src" />
<property name="test.reportsDir" value="E:\Reports" />
<!-- Path Initialization -->
<path id="testcase.path">
<pathelement location="${ws.jar}"/>
<pathelement path="${classes}"/>
<fileset dir="${ws.jar}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- Target Setclasspath -->
<target name="setclasspath" unless="testcase.path">
<path id="classpath_jars">
<fileset dir="${ws.jar}">
<include name="**/*.jar"/>
</fileset>
</path>
<pathconvert pathsep=";" property="testcase.path" refid="classpath_jars"/>
</target>
<!-- Target init -->
<target name="init" depends="setclasspath">
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows"/>
</condition>
</target>
<!-- Target clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- Target compile -->
<target name="compile" depends="init,clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}">
<include name="**/*"/>
</fileset>
</delete>
<mkdir dir="${test.dest}"/>
<javac debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.7"
classpath="${testcase.path}"/>
</target>
<!-- Target run -->
<target name="run" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}">
<include name="**/*"/>
</fileset>
</delete>
<mkdir dir="${test.reportsDir}"/>
<java jar="${ws.jar}" fork="yes" spawn="yes"/>
<junit fork="yes" haltonfailure="no" printsummary="yes" >
<classpath refid="testcase.path" />
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<include name="anttestcase/Login.class"/>
</fileset>
</batchtest>
<formatter type="xml"/>
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TESTS-*.xml"/>
</fileset>
<report todir="${test.reportsDir}"/>
</junitreport>
</target>
</project>`
When I am running my build with command prompt, i am getting the below error:
C:\Users\Ashish Rathore\workspace\AntExample>ant run
Buildfile: C:\Users\Ashish Rathore\workspace\AntExample\build.xml
run:
[junit] WARNING: multiple versions of ant detected in path for junit [junit]
jar:file:/H:/ant1.9/apache-ant-1.9.2-bin/apache-ant-1.9.2/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit]and
jar:file:/C:/Users/Ashish%20Rathore/workspace/AntExample/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit]Running anttestcase.Login [junit]Tests run: 1, Failures: 0,
Errors: 1, Skipped: 0, Time elapsed: 0 sec [junit] Test
anttestcase.Login FAILED [junitreport] Processing
E:\Reports\TESTS-TestSuites.xml to C:\Users\ASHISH~1\Ap
pData\Local\Temp\null1158960870 [junitreport] Loading stylesheet
jar:file:/H:/ant1.9/apache-ant-1.9.2-bin/apache
-ant-1.9.2/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/j
unit-frames.xsl [junitreport] Transform time: 1223ms [junitreport]
Deleting: C:\Users\ASHISH~1\AppData\Local\Temp\null1158960870
BUILD SUCCESSFUL Total time: 5 seconds
Error message in TEST-anttestcase.Login.xml in my Reports
error type="java.lang.ClassNotFoundException" message="anttestcase.Login">
java.lang.ClassNotFoundException: anttestcase.Login at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:423) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at
java.lang.ClassLoader.loadClass(ClassLoader.java:356) at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:188)
My Login.java test case
package anttestcase;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
public class Login {
#Rule public ErrorCollector errCollector=new ErrorCollector();
#BeforeClass public static void setUp() throws Exception {
System.out.println("opening Url");
}
#AfterClass public static void tearDown() throws Exception {
}
#Test public void enterCredentials() {
try {
Assert.assertEquals("A", "B");
System.out.println("Enter Username and Password");
} catch(Throwable t) {
errCollector.addError(t);
System.out.println("Caught");
}
}
#Test public void authenticityCheck() {
System.out.println("Login Successfully");
}
}
You must add the compiled classes to the class path of the junit task.
<junit fork="yes" haltonfailure="no" printsummary="yes" >
<classpath>
<path refid="testcase.path">
<pathelement location="${test.dest}"/>
</classpath>
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<include name="anttestcase/Login.class"/>
</fileset>
</batchtest>
<formatter type="xml"/>
</junit>
On Github there's an example ant project, which uses JUnit: https://github.com/mplacona/java-junit-template-project Have a look at it's build.xml.
I need to change the values of an ANT-script list in real time.
This is the situation;
I have these properties:
x.y.6.1=something1
x.y.6.2=something2
x.y.6.3=something3
list=6.1,6.2
I want the list to become list=something1;something2
This is the gist of the code;
<target name="target1">
<foreach list="${list}" target="target2" param="var" delimiter="," />
</target>
<target name="target2">
<propertycopy name="var" from="x.y.${var}" silent="true"/>
</target>
Now, the propertycopy part works, however, it will not keep the new value.
I tried many variations, none which worked.
I am using ant-contrib.
Help would be much appreciated!
Adam
The target attribute of your foreach should be the name of the target called.
I guess here it should be <foreach list="${list}" target="agent_version_to_path" param="var" delimiter="," />
If I'm wrong, post your target2 and explain what you're trying to do.
Edit:
Ok for your edit, did you already try override="yes"?
And cannot you change your name of property (var) it is quite confusing!
I'm not a fan of the ant-contrib tasks. Have you considered embedding a scripting language instead?
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
properties["list"].split(",").each {
println properties["x.y.${it}"]
}
</groovy>
Update
Here's a more complete example that loops and calls another target:
$ ant
Buildfile: build.xml
process:
doSomething:
[echo] something1
doSomething:
[echo] something2
BUILD SUCCESSFUL
Total time: 0 seconds
build.xml
<project name="demo" default="process">
<property file="build.properties"/>
<path id="build.path">
<pathelement location="lib/groovy-all-2.1.5.jar"/>
</path>
<target name="process" description="Process values in a list">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
properties["list"].split(",").each {
properties.var = properties["x.y.${it}"]
ant.ant(target:"doSomething")
}
</groovy>
</target>
<target name="doSomething">
<echo>${var}</echo>
</target>
</project>
I have solved the problem, in an icky way, but it works great!
<project name="Test" default="main">
<property file="agent.properties" />
<property file="temp_updates.txt" />
<taskdef name="propertycopy" classname="net.sf.antcontrib.property.PropertyCopy" />
<taskdef name="foreach" classname="net.sf.antcontrib.logic.ForEach" />
<target name="main">
<property name="Agent Updates" value="6.1,6.2" />
<antcall target="create_temp_files" />
<antcall target="agent_updates_target" />
<propertycopy name="custom.agent.release.group" from="updates" silent="true" override="true" />
</target>
<target name="agent_updates_target">
<foreach list="${Agent Updates}" target="agent_version_to_path" param="var" delimiter="," />
</target>
<target name="agent_version_to_path">
<propertycopy name="var" from="agent.installer.${var}" silent="true" override="true"/>
<echo message="${var};" file="temp_updates.txt" append="true" />
</target>
<target name="create_temp_files">
<echo message="updates=" file="temp_updates.txt" />
</target>
</project>
on another file, "agent.properties" I had that;
agent.installer.6.3=something3
agent.installer.6.2=something2
agent.installer.6.1=something1
agent.installer.6.0=...
agent.installer.5.6=...
agent.installer.5.0.12=...
agent.installer.5.0.11=...
agent.installer.5.0.9.5=...
agent.installer.3.8=...
agent.installer.3.7=...
As a result, a new file "temp_updates.txt" was created, having
updates=something1;something2;
Which I then loaded into the actual program.
May not be pretty, but it works quite well.
Thank you Skoll and Mark O'Connor for all your help, I used those ideas to come up with this one. I would rate you, but I can't :( Sorry!
I have created one JavaFX application that have many TableView to show content, application works fine if I run Jar file. As I need to distribute application to my clients so my code should be obfuscated. I am using Proguard-4.8 for obfuscation of my code.
I have created one sample TableView build script using Ant that obfuscate sample jar.
Before Obfuscation complied jar only -
After Obfuscation Jar -
I have uploaded my complete build script project at -
http://neelamsharma.s3.amazonaws.com/SampleObfuscationBuildScript.zip
I have completely run it. You will find -
build.xml -
http://neelamsharma.s3.amazonaws.com/SampleObfuscationBuildScript/build.xml
Compiled Jar without obfuscation - http://neelamsharma.s3.amazonaws.com/SampleObfuscationBuildScript/Sample.jar
Obfuscated Jar - http://neelamsharma.s3.amazonaws.com/SampleObfuscationBuildScript/obfuscated/SampleObfuscated.jar
Proguard.map - http://neelamsharma.s3.amazonaws.com/SampleObfuscationBuildScript/obfuscated/ObfuscatedProguard.map
Source Java Class - http://neelamsharma.s3.amazonaws.com/SampleObfuscationBuildScript/src/TableViewWithButton.java
Other things is that -
This is my build.xml file -
<project name="sample" default="cleanBuildPackage" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property environment="env"/>
<property name="WorkingFolder" location="."/>
<property name="ClassPath" location="${env.JAVA_HOME}/jre/lib/jfxrt.jar;${env.JAVA_HOME}/lib/ant-javafx.jar;${WorkingFolder}/lib/proguard.jar;"/>
<property name="dist" value="dist"/>
<property name="main.class" value="TableViewWithButton"/>
<property name="app.name" value="Sample"/>
<target name="init">
<echo message="Java installation directory: ${java.home}"/>
<!-- Create the time stamp -->
<tstamp/>
<delete dir="${WorkingFolder}/build"/>
<delete dir="${dist}"/>
<mkdir dir="${dist}"/>
<mkdir dir="${WorkingFolder}/build"/>
</target>
<target name="CompilingSample" depends="init">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant" classpath=".;${env.JAVA_HOME}/jre/lib/jfxrt.jar"/>
<javac classpath="${ClassPath};" srcdir="${WorkingFolder}/src" destdir="${WorkingFolder}/build"/>
</target>
<target name="CreatingSampleJar" depends="CompilingSample" description="generate the distribution" >
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant" classpath="${env.JAVA_HOME}/lib/ant-javafx.jar"/>
<fx:jar destfile="${WorkingFolder}/${app.name}.jar">
<fx:application mainClass="${main.class}"/>
<fileset dir="${WorkingFolder}/build"/>
</fx:jar>
</target>
<target name="Ofuscating" depends="CreatingSampleJar" >
<taskdef resource="proguard/ant/task.properties" classpath="${WorkingFolder}/lib/proguard.jar" />
<mkdir dir="obfuscated"/>
<proguard printmapping="obfuscated/ObfuscatedProguard.map"
renamesourcefileattribute="SourceFile" ignorewarnings="true">
-dontshrink
-dontoptimize
-libraryjars "${java.home}/lib/rt.jar"
-libraryjars "${java.home}/lib/javaws.jar"
-libraryjars "${env.JAVA_HOME}/lib/ant-javafx.jar"
-libraryjars "${env.JAVA_HOME}/jre/lib/jfxrt.jar"
-injars ${WorkingFolder}/${app.name}.jar
-outjars ${WorkingFolder}/Obfuscated.jar
-ignorewarnings
<keepattribute name="InnerClasses" />
<keepattribute name="SourceFile" />
<keepattribute name="LineNumberTable" />
<keepattribute name="Deprecated" />
<keepattribute name="*Annotation*" />
<keepattribute name="Signature" />
-adaptresourcefilecontents **.fxml,**.properties,META-INF/MANIFEST.MF,images/*,publicCerts.store,.version
<!--
If I am adding this then I am able to see TableView Contents, but it do not obfuscate all public classes and their methods.
<keep access="public">
<method access="public protected" />
</keep>
-->
-keepclassmembernames class * {
#javafx.fxml.FXML *;
}
-keepclasseswithmembers public class com.javafx.main.Main, TableViewWithButton {
public static void main(java.lang.String[]);
}
</proguard>
</target>
<target name="Movejar" depends="Ofuscating">
<move
file="${WorkingFolder}/Obfuscated.jar"
tofile="obfuscated/${app.name}Obfuscated.jar" verbose="true" overwrite="true" />
</target>
<target name="cleanBuildPackage" depends="Movejar">
<fx:deploy width="800" height="600" nativeBundles="all" outdir="${dist}" outfile="${app.name}">
<fx:info title="${app.name}"/>
<fx:application name="${app.name}" mainClass="${main.class}"/>
<fx:resources>
<fx:fileset dir="${dist}" includes="*.jar"/>
</fx:resources>
</fx:deploy>
</target>
</project>
In build.xml if I add this lines then I am able to see TableView Contents, but it do not obfuscate all public classes and their methods.
<keep access="public">
<method access="public protected" />
</keep>
I need my project completely obfuscated. Is there other way to obfuscate jar file without keeping public classes UN-obfuscated so that I am able to see TableView text completely.
Thanks,
Neelam Sharma
I suggest trying to use the long form of PropertyValueFactory:
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Test, String>,
ObservableValue<String>>() {
public ObservableValue<String> call(TableColumn.CellDataFeatures<Test, String> t) {
// t.getValue() returns the Test instance for a particular TableView row
return t.getValue().testProperty();
// or
return new SimpleStringProperty(t.getValue().getMessage());
}
});
I am trying to write a build.xml file for my project. When I run build.xml as an Ant project, I get the following error:
D:\workspace\LogAlerter\src\com\j32bit\alerter\launcher\LogAlerter.java:9:
error: package org.apache.log4j does not exist
[javadoc] import org.apache.log4j.Logger;
I have imported log4j in LogAlerter.Java. Here is my build.xml file:
<?xml version="1.0"?>
<project name="LogAlerter" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<property name="libs.dir" location="lib" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="build.classpath">
<fileset dir="${libs.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir" >
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" includeantruntime="false">
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<packageset dir="${src.dir}" defaultexcludes="yes">
<include name="**" />
</packageset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\LogAlerter.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="LogAlerter.Main" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
Try adding a classpath ref to your javadoc task:
<javadoc packagenames="src"
sourcepath="${src.dir}"
destdir="${docs.dir}"
classpathref="build.classpath">
What the warning is telling you is that you've not provided the full classpath to the javadoc task. Try adding a similar classpath ref to that in your compile task and see where that leads.
Importing is fine but make sure it is available at run time for the JavaDoc tool. log4j.jar should be present in your build.classpath.
Make use of the classpathref inside the docs target like so:
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}" classpathref="build.classpath">
In an ant script, I would like to compile only certain packages e.g.
com.example.some_package.foo
com.example.some_package.bar
This is what I want to do, but it doesn't seem to work, because property substitution doesn't seem to work in the <include> tag:
<property name="ROOT_PKG_PATH" location="com/example/some_package"/>
...
<target name="compile-client" depends="init">
<javac srcdir="${srcDir}"
destdir="${buildDir}"
debug="on"
target="1.5"
classpathref="build.classpath">
<include name="${ROOT_PKG_PATH}/foo/**" />
<include name="${ROOT_PKG_PATH}/bar/**" />
</javac>
</target>
How can I get around this without having to retype the entire package path of each package?
Use the value attribute on the property, instead of location:
<property name="ROOT_PKG_PATH" value="com/example/some_package"/>
Example
I'm able to conditionally compile one of my java classes:
./src/some_package/demo1/Demo.java
./src/some_package/demo2/Demo.java
./build/classes/somepackage/demo1/Demo.class
./build.xml
Using the following ANT file:
<project name="demo" default="compile">
<property name="prop" value="some_package/demo1"/>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes">
<include name="${prop}/**"/>
</javac>
</target>
</project>