javaFX 2.0 XYChart and CSS - css

I am new to JavaFX 2.0 and to do practice I have followed the Oracle example about Line Chart (Stock Monitoring)
http://docs.oracle.com/javafx/2.0/charts/line-chart.htm#CIHGBCFI
Now I would like to ad a CSS class in the same package to modify Stroke, color, etc but I can't succed.
Searching here on StackOverflow I have found
scene.getStylesheets().add(this.getClass().getResource("linechart.css").toExternalForm());
but I still get errors
Exception in Application start method Exception in thread "main" java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
My java class name is JavaFXApplication2 and CSS class name is linechart.css
Would someone be so kind to explain me where I am wrong?
There is another nice tutorial about the CSS use with Stock Monitoring example here
http://docs.oracle.com/javafx/2.0/charts/css-styles.htm
but I do not know how to add the CSS examples to the java class
Thanks

I suspect that the css file is not being copied to the folder where the java files are compiled. Are you using an IDE? Can you add this line to your app System.out.println(this.getClass().getResource(".").toExternalForm());
and copy the css file to the folder path printed by this line.

You can build the project or copy the css file to the build path.If you using netbeans,you must build the project once after new resource file added.

Related

Jasper Reports NoClassDefFoundError

I'm getting a NoClassDefFoundError error when trying to compile or run a Jasper report.
2012-06-13 14:46:26,710 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jahtest].[jahtest]] Servlet.service() for servlet jahtest threw exception
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
I have a set of java classes wrapped up in a war file and deployed in JBoss default/deploy folder.
I have the jasperreports-4.1.2.jar file in the JBoss default/lib folder so I can't see how there can be a classpath problem because all other jars in the lib folder can be seen.
My front-end app calls a HTTPServlet class which then uses reflection to call the class containing the Jasper code. Everything works fine up until the point where this line is called -
JasperDesign jasperDesign = JRXmlLoader.load(strCompiledReportFile);
The strCompiledReportFile is correct and exists. This all works when I run it through Eclipse, just not when called from my HTTPServlet class.
I'm at the point where I want to ditch Jasper because I've had so many issues with it so this is the last chance saloon.
Cheers for any help you might be able to offer.
I think you are missing few jars that jasper depends on at runtime. Check this thread and make sure you have those jars in your classpath as well.
I'm not sure if it would also apply to your case, but I had a similar problem recently, where after failing to load a font ("problem reading font data"), Jasper Reports would start giving spurious java.lang.NoClassDefFoundError for many of its classes; this problem was caused because java.awt.Font.createFont(int fontFormat, InputStream fontStream) tried and failed to create a temporary file. The error happened inside Tomcat, but not inside Eclipse; what was happening was that Tomcat automatically configures its JVM to point to its temp folder instead of the default one, and Tomcat's temp folder had been deleted.
If you are trying to integrate jasper with springboot application check whether the .jrxml is in the resources folder.

Convert Class to Class Library

I'm trying to follow along with Paul Sheriff's e-book "Fundamentals of N-tier" which is really good so far.
At the end of chapter 2 he says we should break the classes we have created into separate class libraries and that these libraries(dlls) can then be used from any application. The book doesn't explain how to do this.
I have the classes built, but I don't know how to convert them to Class Libraries and reference them in my project.
===========================================================
Thanks for everyone's help I really appreciate it.
I've created the class library in the same project and added a reference to it.
DataCommon is the name of the Class Library
DataLayer is the class
GetDataTable is a method in the class
how do I access this method from the web project.
I added a "using DataCommon;" statement at the top of the class that I'm trying to access the class library in. I get a "the type or namespace could not be found" message
Start by adding a new project to your solution of type Class Library.
(source: c-sharpcorner.com)
Then move those classes to this project.
Finally reference the project in the ASP.NET site.
Just cut out the code you want to reuse and copy into a new dll project. Then reference that dll project from your application and include the namespace anywhere you want to use those classes. There isn't any other magic involved. Just cut from one project and put in another.
Create a new "class library", a project type when creating new project. Then just copy the class into the project, ensuring you are changing the namespace to the appropriate namespace.
I have the classes built, but I don't
know how to convert them to Class
Libraries and reference them in my
project.
Create a new project of type "Class Library" and add your class files to that.
To reference them from your project, you just right click the project in solution explorer and "Add Reference". If the you've got both projects in the same solution, you can then click the Project tab and make your selection. If not, then click the Browse tab and navigate to the bin/debug or bin/release folder from your class library project which contains the compiled dll. (you must have built your class library project for the compiled dll to exist, of course)

Problem modulating action script project

I am refactoring a hugh action script solution in Flash builder (beta 2) using the flex 4 sdk.
The project does NOT use the mx framework.
What i want to have is:
A big 'MAIN' project
several small 'MODULE' projects. each 'MODULE' class refrences the 'MAIN' project as an External reference (doesnt compile into swf) - this is done by setting link type = external in the 'MODULE' project properties -> library path.
'MAIN' loads a 'MODULE' project on runtime using the 'loader' class.
the problem:
I recieve an error from the MODULE project:
VerifyError: Error #1014: Class [some class in MAIN] could not be found.
PLEASE HELP!
Check which application domain you are loading your module into. The app domain needs to be able to access the class you have externalised or you'll get that error.
It might just be a bug with the beta version of the sdk. It seems like the import of a class in a module created in another project doesn't force it's inclusion in the main swf.
try putting a dummy dependency in you main application class, like:
private var forcedImports:Array = [MyClass];
It fixed some of my problems before.

Compile an ActionScript class that is in a package to a swf using Flex Builder 3

How do I configure an ActionScript Project in Flex Builder 3 Pro so that I can compile an ActionScript class that is part of a package into a swf. For example, the class that I want to compile to swf is:
package utils {
import flash.display.Sprite;
public class Tool extends Sprite {
public function Tool() {
}
}
Take a directory structure like the following:
RootASProject
-RootASProject.mxml
-subASProject1
--subSubASProject1a
---IASModule.as
---ASModule.as
---ASModule.swf
--subSubASProject2
-utils
--ITool.as
--Tool.as
--Tool.fla
--Tool.swf
RootASProject is being produced by one developer, subASProject1 and subSubASProject1a by another developer, utils.Tool by yet another person. This directory structure enables each person to independently build modules and other resources, and quickly test the entire product. It is also important to note that these resources are loaded at runtime. So, class definitions must be fully qualified. For example, Tool.swf contains/defines "utils.Tool" not "Tool".
Developing with just the Flash IDE, this directory structure is not a problem. We create a Tool.fla and assign utils.Tool as it's Document Class then in the Flash IDE's Publish Setting, we set the class path to be NOT the current directory (.), but instead the RootASProject directory. If it were set to the current directory, the error would be: A file found in a source-path must have the same package structure '', as the definition's package, 'utils'. Tool Tool.as. We're familiar with this error message and so I recognize that the Flex IDE is by default looking in the current directory for a subfolder, utils, to match the packaged class.
In the Flex IDE, I can add the utils parent, RootASProject, as an additional source path, but I do not know how to stop flex from looking in the current directory first.
Using an ant build file, I can set the source path to RootASProject and the mxmlc is able to build utils/Tool.swf just fine. Apparently, it uses just the source paths passed to it, and does not automatically look for utils in the current directory.
I know the problem is resolved by using Flash or Ant. Ant is even preferred for larger and automatic builds; however, during rapid debugging I'd really enjoy being able to stay within the Flex IDE to step through code using its debugger.
Your compilation error is unrelated to its use as a document class. Your directory structure needs to match your package in your clas. The simple solution is to create a folder called "utils" and move your Tool.as into that folder.
What you refer to as a "document" class is the base class of the exported symbol. Assuming your project is an ActionScript project and the above class is marked as your Application, then it should work as expected.
If you are using Flex Builder 3 or better, simply create a new ActionScript project by going File > New > ActionScript Project and assign your ITool.as file as the main Application file in it.

Where to place and how to read configuration resource files in servlet based application?

In my web application I have to send email to set of predefined users like finance#xyz.example, so I wish to add that to a .properties file and access it when required. Is this a correct procedure, if so then where should I place this file? I am using Netbeans IDE which is having two separate folders for source and JSP files.
It's your choice. There are basically three ways in a Java web application archive (WAR):
1. Put it in classpath
So that you can load it by ClassLoader#getResourceAsStream() with a classpath-relative path:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("foo.properties");
// ...
Properties properties = new Properties();
properties.load(input);
Here foo.properties is supposed to be placed in one of the roots which are covered by the default classpath of a webapp, e.g. webapp's /WEB-INF/lib and /WEB-INF/classes, server's /lib, or JDK/JRE's /lib. If the propertiesfile is webapp-specific, best is to place it in /WEB-INF/classes. If you're developing a standard WAR project in an IDE, drop it in src folder (the project's source folder). If you're using a Maven project, drop it in /main/resources folder.
You can alternatively also put it somewhere outside the default classpath and add its path to the classpath of the appserver. In for example Tomcat you can configure it as shared.loader property of Tomcat/conf/catalina.properties.
If you have placed the foo.properties it in a Java package structure like com.example, then you need to load it as below
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("com/example/foo.properties");
// ...
Note that this path of a context class loader should not start with a /. Only when you're using a "relative" class loader such as SomeClass.class.getClassLoader(), then you indeed need to start it with a /.
ClassLoader classLoader = getClass().getClassLoader();
InputStream input = classLoader.getResourceAsStream("/com/example/foo.properties");
// ...
However, the visibility of the properties file depends then on the class loader in question. It's only visible to the same class loader as the one which loaded the class. So, if the class is loaded by e.g. server common classloader instead of webapp classloader, and the properties file is inside webapp itself, then it's invisible. The context class loader is your safest bet so you can place the properties file "everywhere" in the classpath and/or you intend to be able to override a server-provided one from the webapp on.
2. Put it in webcontent
So that you can load it by ServletContext#getResourceAsStream() with a webcontent-relative path:
InputStream input = getServletContext().getResourceAsStream("/WEB-INF/foo.properties");
// ...
Note that I have demonstrated to place the file in /WEB-INF folder, otherwise it would have been public accessible by any webbrowser. Also note that the ServletContext is in any HttpServlet class just accessible by the inherited GenericServlet#getServletContext() and in Filter by FilterConfig#getServletContext(). In case you're not in a servlet class, it's usually just injectable via #Inject.
3. Put it in local disk file system
So that you can load it the usual java.io way with an absolute local disk file system path:
InputStream input = new FileInputStream("/absolute/path/to/foo.properties");
// ...
Note the importance of using an absolute path. Relative local disk file system paths are an absolute no-go in a Java EE web application. See also the first "See also" link below.
Which to choose?
Just weigh the advantages/disadvantages in your own opinion of maintainability.
If the properties files are "static" and never needs to change during runtime, then you could keep them in the WAR.
If you prefer being able to edit properties files from outside the web application without the need to rebuild and redeploy the WAR every time, then put it in the classpath outside the project (if necessary add the directory to the classpath).
If you prefer being able to edit properties files programmatically from inside the web application using Properties#store() method, put it outside the web application. As the Properties#store() requires a Writer, you can't go around using a disk file system path. That path can in turn be passed to the web application as a VM argument or system property. As a precaution, never use getRealPath(). All changes in deploy folder will get lost on a redeploy for the simple reason that the changes are not reflected back in original WAR file.
See also:
getResourceAsStream() vs FileInputStream
Adding a directory to tomcat classpath
Accessing properties file in a JSF application programmatically
Word of warning: if you put config files in your WEB-INF/classes folder, and your IDE, say Eclipse, does a clean/rebuild, it will nuke your conf files unless they were in the Java source directory. BalusC's great answer alludes to that in option 1 but I wanted to add emphasis.
I learned the hard way that if you "copy" a web project in Eclipse, it does a clean/rebuild from any source folders. In my case I had added a "linked source dir" from our POJO java library, it would compile to the WEB-INF/classes folder. Doing a clean/rebuild in that project (not the web app project) caused the same problem.
I thought about putting my confs in the POJO src folder, but these confs are all for 3rd party libs (like Quartz or URLRewrite) that are in the WEB-INF/lib folder, so that didn't make sense. I plan to test putting it in the web projects "src" folder when i get around to it, but that folder is currently empty and having conf files in it seems inelegant.
So I vote for putting conf files in WEB-INF/commonConfFolder/filename.properties, next to the classes folder, which is Balus option 2.
Ex: In web.xml file the tag
<context-param>
<param-name>chatpropertyfile</param-name>
<!-- Name of the chat properties file. It contains the name and description of rooms.-->
<param-value>chat.properties</param-value>
</context-param>
And chat.properties you can declare your properties like this
For Ex :
Jsp = Discussion about JSP can be made here.
Java = Talk about java and related technologies like J2EE.
ASP = Discuss about Active Server Pages related technologies like VBScript and JScript etc.
Web_Designing = Any discussion related to HTML, JavaScript, DHTML etc.
StartUp = Startup chat room. Chatter is added to this after he logs in.
It just needs to be in the classpath (aka make sure it ends up under /WEB-INF/classes in the .war as part of the build).
You can you with your source folder so whenever you build, those files are automatically copied to the classes directory.
Instead of using properties file, use XML file.
If the data is too small, you can even use web.xml for accessing the properties.
Please note that any of these approach will require app server restart for changes to be reflected.
Assume your code is looking for the file say app.properties. Copy this file to any dir and add this dir to classpath, by creating a setenv.sh in the bin dir of tomcat.
In your setenv.sh of tomcat( if this file is not existing, create one , tomcat will load this setenv.sh file.
#!/bin/sh
CLASSPATH="$CLASSPATH:/home/user/config_my_prod/"
You should not have your properties files in ./webapps//WEB-INF/classes/app.properties
Tomcat class loader will override the with the one from WEB-INF/classes/
A good read:
https://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html

Resources