I'm following along with the tutorial at oracle and am getting this error message when I try to run the jar file output after the code is compiled.
Error: Could not find or load main class HelloWorld
To setup a java development environment, I went to oracle and downloaded their Java SE Development Kit and dropped it into /usr/lib/jvm/jdk1.8.0_45 and then pointed to it in the build.xml file as was indicated.
In following the tutorial, I have a project folder with the following code/script:
(example/src/HelloWorld.java)
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
(example/build.xml)
<?xml version="1.0" encoding="UTF-8" ?>
<project name="JavaFX Hello World Example" default="default" basedir="."
xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property name="JAVA_HOME" value="/usr/lib/jvm/jdk1.8.0_45"/>
<property name="build.src.dir" value="src"/>
<property name="build.classes.dir" value="classes"/>
<property name="build.dist.dir" value="dist"/>
<target name="default" depends="clean,compile">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath="${JAVA_HOME}/lib/ant-javafx.jar"/>
<fx:application id="HelloWorldID"
name="JavaFXHelloWorldApp"
mainClass="HelloWorld"/>
<fx:resources id="appRes">
<fx:fileset dir="${build.dist.dir}" includes="HelloWorld.jar"/>
</fx:resources>
<fx:jar destfile="${build.dist.dir}/HelloWorld.jar">
<fx:application refid="HelloWorldID"/>
<fx:resources refid="appRes"/>
<fileset dir="${build.classes.dir}"/>
</fx:jar>
<fx:deploy width="300" height="250"
outdir="." embedJNLP="true"
outfile="helloworld">
<fx:application refId="HelloWorldID"/>
<fx:resources refid="appRes"/>
<fx:info title="JavaFX Hello World Application"
vendor="Oracle Corporation"/>
</fx:deploy>
</target>
<target name="clean">
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.dist.dir}"/>
<delete>
<fileset dir="${build.classes.dir}" includes="**/*"/>
<fileset dir="${build.dist.dir}" includes="**/*"/>
</delete>
</target>
<target name="compile" depends="clean">
<javac includeantruntime="false"
srcdir="${build.src.dir}"
destdir="${build.classes.dir}"
fork="yes"
executable="${JAVA_HOME}/bin/javac"
source="1.8"
debug="on">
</javac>
</target>
</project>
Here's some very light debugging info which may expose the problem:
$ java -jar HelloWorld.jar
Error: Could not find or load main class HelloWorld
$ jar tvf HelloWorld.jar
0 Mon Apr 27 00:57:58 CDT 2015 META-INF/
113 Mon Apr 27 00:57:58 CDT 2015 META-INF/MANIFEST.MF
1014 Mon Apr 27 00:57:58 CDT 2015 HelloWorld$1.class
1436 Mon Apr 27 00:57:58 CDT 2015 HelloWorld.class
(HwlloWorld.jar META-INF/MANIFEST.MF)
Manifest-Version: 1.0
JavaFX-Version: 8.0
Class-Path:
Created-By: JavaFX Packager
Main-Class: HelloWorld
What's missing?
The message "Could not find or load main class HelloWorld" means that Java was not able to find the HelloWorld class in its classpath. I suspect this may be due to the Class-Path entry being empty in the manifest file:
Class-Path:
You may want to try overriding this entry to set the classpath to the root of the Jar by adding the following in the Ant buildfile (this is similar to the example in this link):
<fx:jar destfile="${build.dist.dir}/HelloWorld.jar">
<fx:application refid="HelloWorldID"/>
<fx:resources refid="appRes"/>
<fileset dir="${build.classes.dir}"/>
<manifest>
<attribute name="Class-Path" value="."/>
</manifest>
</fx:jar>
I have a working ant build for my Javafx application(it's 2.2, but it might work for you), the application is tested on win and linux.
These are the key differences:
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
Moreover when I check the manifest file, I see something like this:
JavaFX-Application-Class: packagename.MainClass
JavaFX-Class-Path: packagename/MainClass.class
These are automatically added and I don't have Main-Class and Class-Path.
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>
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());
}
});
How can i replace all matching lines? I wanna replace all matching lines in *xml file.
Script snippet which is below just only replace one line
Thanks in advance.
brgds
<?xml version="1.0" encoding="windows-1252" ?>
<project default="init" basedir=".">
<property file="build.properties"/>
<target name="init">
<tstamp/>
<loadfile property="jndiurl"
srcfile="${src.model}/META-INF/persistence.xml">
<filterchain>
<linecontains>
<contains value="hibernate.jndi.url"></contains>
</linecontains>
</filterchain>
</loadfile>
<replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
value="${hibernate.jndi.url.live}${line.separator}"/>
<echo>${hibernate.jndi.url.live}</echo>
<loadfile property="providerurl"
srcfile="${src.structure}/com/arsivist/structure/connection.properties">
<filterchain>
<linecontains>
<contains value="providerurl"></contains>
</linecontains>
</filterchain>
</loadfile>
<replace file="${src.structure}/com/arsivist/structure/connection.properties"
token="${providerurl}"
value="${providerurl.live}${line.separator}"/>
<echo>${providerurl.live}</echo>
<loadfile property="ucmusername"
srcfile="${src.roketsanutil}/com/arsivist/util/ucmConnection.properties">
<filterchain>
<linecontains>
<contains value="username"></contains>
</linecontains>
</filterchain>
</target>
</project>
Instead of trying to edit files in place, wouldn't it be simpler to use the copy task as a templating system, it supports a filterset which can be used to substitute production values.
Example
.
├── build.xml
└── src
└── resources
└── persistence.xml
build.xml
<project name="demo" default="template">
<target name="template">
<copy todir="build/META-INF">
<fileset dir="src/resources" includes="*.xml"/>
<filterset>
<filter token="HIBERNATE.HBM2DDL.AUTO" value="create-drop"/>
</filterset>
</copy>
</target>
<target name="clean">
<delete dir="build"/>
</target>
</project>
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="sample">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="#HIBERNATE.HBM2DDL.AUTO#"/>
</properties>
</persistence-unit>
</persistence>
That snippet works for me:
<?xml version="1.0" encoding="windows-1252" ?>
<project default="init" basedir=".">
<property file="build.properties"/>
<target name="init">
<tstamp/>
<loadfile property="jndiurl"
srcfile="${src.model}/META-INF/persistence.xml">
<filterchain>
<linecontains>
<contains value="hibernate.jndi.url"></contains>
</linecontains>
<headfilter lines="1"/>
</filterchain>
</loadfile>
<echo>${jndiurl}</echo>
<replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
value="${hibernate.jndi.url.live}${line.separator}"/>
<echo>${hibernate.jndi.url.live}</echo>
</project>
I've created a custom action with as a eclipse project. I packaged it in a jar and I put it in: alfresco-3.4.d/tomcat/webapps/alfresco/WEB-INF/lib
I started Alfresco and I created a rule with my custom action. When a file is created in this folder then the rule is triggered.
But when I create a file, the unique available type is "content", my custom content types don't show in select list. My problem is I need these custom types.
I have tested starting Alfresco without my jar and all types are availables.
My project structure is wrong?:
src.main.java
-executer
·UrlActionExecuter.java
·UrlActionHandler.java
src.main.resources
-alfresco.extension
·url-actions-context.xml
·web-client-config-custom.xml
·webclient.properties
src.main.webapp
-jsp.actions
·url-action-executer.jsp
or build.xml?:
<?xml version="1.0"?>
<project name="Action Url" default="package" basedir=".">
<property name="project.dir" value="."/>
<property name="build.dir" value="${project.dir}/build"/>
<property name="package.file" value="${build.dir}/Action-url.jar"/>
<path id="class.path">
<dirset dir="${build.dir}" />
<fileset dir="../../lib/server" includes="**/*.jar"/>
</path>
<target name="compile">
<mkdir dir="${build.dir}" />
<javac classpathref="class.path" srcdir="${project.dir}/src" destdir="${build.dir}" />
</target>
<target name="package" >
<jar destfile="${package.file}">
<fileset dir="${build.dir}"/>
</jar>
</target>
</project>
Thanks everybody!
Your custom types should described in the model file and then you should import your model to the alfresco, for example:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="custom_dictionaryBootstrap"
parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<value>alfresco/module/mymodule/model/mymodel.xml</value>
</list>
</property>
<property name="labels">
<list>
<value>alfresco/module/mymodule/messages/system</value>
</list>
</property>
</bean>
</beans>