Css is not working after deployment of a JavaFX app in Eclipse - css

If I deploy a JavaFX app from Eclipse then it won't load the CSS file for some reason, though the app works as expected inside Eclipse.
Main class:
public class Main extends Application {
Stage primaryStage;
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
showMain();
}
public void showMain(){
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("Mainwindow.fxml"));
AnchorPane ap = loader.load();
ap.getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
Scene scene = new Scene(ap);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
The css is:
#CHARSET "UTF-8";
.button{
-fx-background-color: blue;
}
The fxml:
<AnchorPane prefHeight="381.0" prefWidth="446.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<Button layoutX="14.0" layoutY="14.0" mnemonicParsing="false" text="Button" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="14.0" />
</children>
</AnchorPane>
In the build.xml I just set the obligatory things. I don't convert the css into bss. I sign it and that's all.
The build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="JavaFXTester6_Web" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<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"/>
</target>
<target name="setup-staging-area">
<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />
<mkdir dir="externalLibs" />
<mkdir dir="project" />
<copy todir="project">
<fileset dir="/home/zooey/LinuxEclipse/linuxWorkspace/JavaFXTester6_Web">
<include name="src/**" />
</fileset>
</copy>
<mkdir dir="projectRefs" />
</target>
<target name='do-compile'>
<delete dir="build" />
<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />
<!-- Copy project-libs references -->
<copy todir="build/libs">
<fileset dir="externalLibs">
</fileset>
</copy>
<!-- Copy project references -->
<!-- Copy project sources itself -->
<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*"/>
</fileset>
</copy>
<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="UTF-8">
<classpath>
<fileset dir="build/libs">
<include name="*"/>
</fileset>
</classpath>
</javac>
<!-- Copy over none Java-Files -->
<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
<delete file="dist"/>
<delete file="deploy" />
<mkdir dir="dist" />
<mkdir dir="dist/libs" />
<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="JavaFXTester6_Web.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
</fx:resources>
<fx:application id="fxApplication"
name="Test"
mainClass="application.Main"
/>
<mkdir dir="build/classes/META-INF" />
<fx:jar destfile="dist/JavaFXTester6_Web.jar">
<fx:application refid="fxApplication"/>
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes"/>
<manifest>
<attribute name="Implementation-Vendor" value="ZA"/>
<attribute name="Implementation-Title" value="Test"/>
<attribute name="Implementation-Version" value="1.0"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<fx:signjar //intentionally removed >
<fileset dir='dist'>
<include name='**/*.jar' />
</fileset>
</fx:signjar>
<mkdir dir="deploy" />
<!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
<fx:deploy
embedJNLP="false"
extension="false"
width="400" height="400"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="JavaFXTester6_Web"
placeholderref="webtest"
placeholderid="webtest"
updatemode="background" >
<fx:info title="JavaFXTester6_Web" vendor="ZA"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
<fx:permissions elevated="true"/>
</fx:deploy>
</target>
The file system I get after running the build.xml:
The same in my file browser:
I couldn't fin any solutions, everybody mentions the conversion from css to bss, but I tried both (so with Main.class.getResource(style.bss)... too) and no solution. I have unfortunately no more ideas. Can you help? Thank you!

The problem is because of the #CHARSET "UTF-8"; in your css file.
JavaFX cannot parse it and will throw a parse exception.
Remove the CHARSET declaration from the css and try again.

I have the same problem. It all works fine in Eclipse but when I compile and run the jar, the CSS is ignored. Extracting the complied jar shows the CSS file and images in the same folder as the Java class files.
FXML
<stylesheets>
<URL value="#Style.css" />
</stylesheets>
CSS
-fx-background-image: url("background.jpg");
Okay, I figured it out. The CSS file and the image file need to be in the root directory of the jar. In Eclipse the CSS file and image files are in the package with the Java files, but when you compile they need to go in the src folder outside of the package.
You do not need the line;
Java
ap.getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
The FXML file should tell the program where to find the CSS file, and the CSS file tells the program where to find images.

Related

How to loop macrodef in Ant script?

Currently, I am writing an Ant Script that removes the signatures of signed Jar files.
Removing the signature for a single jar file was successful using the script below.
<project name="unsign">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="ant-lib/ant-contrib-0.6.jar" />
<property name="jarPath" location="C:\Users\Administrator\Desktop\tempDir" />
<property name="resultPath" location="C:\Users\Administrator\Desktop\tempDir-result" />
<target name="unsignJar">
<unsignjar jarFile="${jarPath}/com.google.guava_15.0.0.v201403281430.jar" />
</target>
<macrodef name="unsignjar" description="Unsign a jar file">
<attribute name="jarfile" description="Jar file to unsign " />
<sequential>
<copy toFile="#{jarFile}_MANIFEST.tmp">
<resources>
<zipentry zipfile="#{jarFile}" name="META-INF/MANIFEST.MF" />
</resources>
</copy>
<replaceregexp file="#{jarFile}_MANIFEST.tmp" match="\nName:(.+?)\nSH" replace="SH" flags="gis" byline="false" />
<replaceregexp file="#{jarFile}_MANIFEST.tmp" match="SHA(.*)" replace="" flags="gis" byline="false" />
<jar jarfile="#{jarFile}.tmp" manifest="#{jarFile}_MANIFEST.tmp">
<zipfileset src="#{jarFile}">
<include name="**" />
<exclude name="META-INF/*.SF" />
<exclude name="META-INF/*.DSA" />
<exclude name="META-INF/*.RSA" />
</zipfileset>
</jar>
<!-- Removing the temporary manifest -->
<delete file="#{jarFile}_MANIFEST.tmp" />
<!-- Swapping the original Jar file with the temporary one -->
<move file="#{jarFile}.tmp" tofile="#{jarFile}" overwrite="true" />
</sequential>
</macrodef>
</project>

Unable to create third index in elastic search for logging using NLog in Asp.net core

Hello Everyone,
I am new to the elk stack and trying to do logging using elastic search. I want to create different index for different different services in api. I am able to create two indexes of different services but can not do the same for third index.
Following is my nconfig file
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Trace" internalLogFile="c:\temp1\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<extensions>
<add assembly="NLog.Targets.ElasticSearch"/>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<target xsi:type="File" name="f" fileName="${basedir}/logs/log.txt"
archiveFileName="${basedir}/logs/archives/log.txt"
archiveAboveSize="5242880"
archiveEvery="Day"
archiveNumbering = "Rolling"
maxArchiveFiles="3"
layout="${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch" name="elastic" index="aquaparallelapi"
uri="http://localhost:9200"
layout ="API:aquaparallelapi|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</target>
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch" name="elastic1" index="aquaparallelapiprogress"
uri="http://localhost:9200"
layout ="API:aquaparallelapi|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</target>
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch" name="elastic2" index="aquaparallelapitestcase"
uri="http://localhost:9200"
layout ="API:aquaparallelapi|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</target>
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<logger enabled="true" name="*" minlevel="Debug" writeTo="f" />
<logger enabled="true" name="*" minlevel="Debug" writeTo="elastic" />
<logger enabled="true" name="AquaParallelAPI.Controllers.ProgressController" minlevel="Debug" writeTo="elastic1" />
<logger enabled="true" name="AquaParallelAPI.Controllers.TestCaseController" minlevel="Debug" writeTo="elastic2" />
</rules>
</nlog>
As you can see above indexes aquaparallelapi and aquaparallelapiprogress is created and gives the desired result but index aquaparallelapitestcase is not created. When I tried to do
http://localhost:9200/aquaparallelapitestcase
then
{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index [aquaparallelapitestcase]","resource.type":"index_or_alias","resource.id":"aquaparallelapitestcase","index_uuid":"_na_","index":"aquaparallelapitestcase"}],"type":"index_not_found_exception","reason":"no such index [aquaparallelapitestcase]","resource.type":"index_or_alias","resource.id":"aquaparallelapitestcase","index_uuid":"_na_","index":"aquaparallelapitestcase"},"status":404}
Please let me know where I am wrong?

Error when creating JavaFX jar file from codes written in Groovy

I tried to create a standalone jar file from source codes written in Groovy, using the following build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build" default="build" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property name="groovy" value="C:/groovy-2.4.5"/>
<property name="source" value="source"/>
<property name="binary" value="binary"/>
<property name="distribution" value="distribution"/>
<property name="data" value="data"/>
<property name="name" value="application"/>
<property name="class" value="ziphil.main.Launcher"/>
<path id="groovy.classpath">
<fileset dir="${groovy}/embeddable/"/>
</path>
<path id="compile.class.path">
<fileset dir="${groovy}/lib/"/>
</path>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.classpath"/>
<target name="clean">
<mkdir dir="${binary}"/>
<mkdir dir="${distribution}"/>
<delete>
<fileset dir="${binary}" includes="**/*"/>
<fileset dir="${distribution}" includes="**/*"/>
</delete>
</target>
<target name="compile" depends="clean">
<groovyc srcdir="${source}" destdir="${binary}" classpathref="compile.class.path" encoding="UTF-8"/>
<copy todir="${binary}/${data}">
<fileset dir="${source}/${data}"/>
</copy>
</target>
<target name="build" depends="compile">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${java}/lib/ant-javafx.jar"/>
<fx:application id="id" name="${name}" mainClass="${class}"/>
<fx:resources id="appRes">
<fx:fileset dir="${distribution}" includes="${name}.jar"/>
</fx:resources>
<fx:jar destfile="${distribution}/${name}.jar">
<fx:application refid="id"/>
<fx:resources refid="appRes"/>
<fileset dir="${binary}"/>
</fx:jar>
</target>
<target name="run" depends="build">
<java jar="${distribution}/${name}.jar" fork="true"/>
</target>
</project>
But I had an error saying that the main class was not found when trying to run the created jar file (in run target of the XML above). What should I do to resolve this error?
You may have to add to the runtime classpath all the jars that your application depends on. I guess that you need at least to include compile.class.path to your runtime classpath :
<target name="run" depends="build">
<java jar="${distribution}/${name}.jar" fork="true" classpathref="compile.class.path"/>
</target>

Compiling SASS using jRuby

I'm using jruby to compile scss files to css using ant build script.
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="compileSCSS" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<path id="JRuby">
<fileset file="libs/jruby-complete-1.7.18.jar"/> <!-- Location of JRuby jar file -->
</path>
<target name="compileSCSS">
<echo message="Compiling scss files..." />
<property name="filesIn" value="style.scss" />
<property name="fileOutDir" value="output/" />
<property name="root" value="." />
<script language="ruby" classpathref="JRuby">
<![CDATA[
require './libs/sass/lib/sass'
require './libs/sass/lib/sass/exec'
files = Dir.glob($project.getProperty('filesIn'))
files.each do |file|
opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
opts.parse
end
]]>
</script>
<echo message="Done compiling SCSS source files." />
</target>
</project>
This is my build script. I'm using jruby 1.7.8 and SASS source code from github (version 3.4.9).
Its throwing exception :
javax.script.ScriptException: org.jruby.embed.EvalFailedException:
(NameError) uninitialized constant Sass::Exec::Sass
Please help. What could be the Issue?

loading jars during splash screen

I have a main application which is referencing to 4-5 external jar files. So while compiling the project netbeans ide(javafx application) takes long time. Therefore I want to design a splash screen and which will be displayed till all jars gets loaded.
My JNLP file is
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="Black.jnlp">
<information>
<title>Black</title>
<vendor>RATTAN</vendor>
<description>Sample JavaFX 2.0 application.</description>
<offline-allowed/>
</information>
<resources>
<jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
</resources>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="Black.jar" size="3393158" download="eager" />
<jar href="lib/commons-io-1.3.2.jar" size="95655" download="eager" />
<jar href="lib/commons-lang-2.0.jar" size="179420" download="eager" />
<jar href="lib/newlink.jar" size="6160" download="eager" />
<jar href="lib/scribe-1.3.0.jar" size="74543" download="eager" />
</resources>
<security>
<all-permissions/>
</security>
<applet-desc width="800" height="600" main-class="com.javafx.main.NoJavaFXFallback" name="Black" >
<param name="requiredFXVersion" value="2.2+"/>
</applet-desc>
<jfx:javafx-desc width="800" height="600" main-class="test.Test" name="Black" />
<update check="always"/>
</jnlp>
Use preloaders module from JavaFx
here is complete tutorial:
http://docs.oracle.com/javafx/2/deployment/preloaders.htm
Good luck,'.

Resources