SyntaxHighlighter

2012-10-31

run java programs with self-boudle JRE

1. at first, make sure you have the JRE which can run the program.
for example, It's c:\java\jre.

2. copy the JRE to the program directory.
so, it may look like below:
SOMEPROGRAM\ (root)
SOMEPROGRAM\jre (the JRE directory)
SOMEPROGRAM\app (maybe put JARs here)
SOMEPROGRAM\app\lib (maybe some third-party JARs here)

3. make a batch file in root directory, maybe named it FOO.bat
.\jre\bin\java -jar "app\FOO.jar" -cp app\lib

4. run the FOO.bat.
It's done.

to run the batch(.bat) file without showing the (command line tool) window in Windows

1.At first, we have a batch file, FOO.BAT for example.

2.Make a vbScript file, BOO.vbs for example
contents with the script below:

Set ws = CreateObject("Wscript.Shell") 
ws.run "cmd /C FOO.bat",vbhide 

3. Put the BOO.vbs with FOO.bat, or say, put the files into the same directory.

4. done.

2012-10-25

net.sf.jasperreports.engine.JRException: Error loading byte data

OK, if you find this from Google or somewhere, you got the same problem as I did.

With an official answer, you lost the JDT jar in your classpath.
So, the solvation is easy: include the jdt jar into your classpath.

That's all.

Compile and Print reports in JasperReports 4

When I working my report with JasperReports 4.7(the latest version at the moment), I'm forced to face the truth: the documents on the net were too old to make the reports. They uses the JasperReports 3.x when it's in 2002~2005. I can't find the JasperManager class in the library in JasperReports 4.7.

You may see some examples which were written for JasperReport 3.x as below:
// First, load JasperDesign from XML and compile it into JasperReport
JasperDesign jasperDesign = JasperManager.loadXmlDesign("BasicReport.xml");
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);
// Second, create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("ReportTitle", "Basic JasperReport");
parameters.put("MaxSalary", new Double(25000.00));
// Third, get a database connection
Connection conn = Database.getConnection(); 
// Fourth, create JasperPrint using fillReport() method
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, conn);
// You can use JasperPrint to create PDF
JasperManager.printReportToPdfFile(jasperPrint, "BasicReport.pdf");
// Or to view report in the JasperViewer
JasperViewer.viewReport(jasperPrint);


In JasperReport 4.x, it will look like below:
// First, load JasperDesign from XML and compile it into JasperReport
JasperDesign jasperDesign = JRXmlLoader.load("BasicReport.xml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
// Second, create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("ReportTitle", "Basic JasperReport");
parameters.put("MaxSalary", new Double(25000.00));
// Third, get a database connection
Connection conn = Database.getConnection(); 
// Fourth, create JasperPrint using fillReport() method
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
// You can use JasperPrint to create PDF
JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
// Or to view report in the JasperViewer
JasperViewer.viewReport(jasperPrint);


As you can see, there is some change between version 3.x to 4.x. In JasperReport 4.x, there are LOTS of class which sees to access to the same in-memory data. The classes becomes more easy to do things you want. Just try it.

2012-10-17

JavaFX standalone application with external jar

To compile/build a JavaFX standalone application with external jar CORRECTLY.

with the code below, I get runtime exception as the others.

     <target name="-post-jfx-deploy">
        <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" 
                  nativeBundles="all"
                  outdir="${basedir}/${dist.dir}" outfile="${application.title}">
          <fx:application name="${application.title}" 
                          mainClass="${javafx.main.class}"/>
          <fx:resources>
              <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>
              <fx:fileset dir="${basedir}/${dist.dir}/lib" includes="*.jar"/>
          </fx:resources>
          <fx:info title="${application.title}" 
                   vendor="${application.vendor}"/>
        </fx:deploy>
     </target>

but I fix it finally.
with the code below, the external jars go to the right location.
     <target name="-post-jfx-deploy">
        <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" 
                  nativeBundles="all"
                  outdir="${basedir}/${dist.dir}" outfile="${application.title}">
          <fx:application name="${application.title}" 
                          mainClass="${javafx.main.class}"/>
          <fx:resources>
              <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>
              <fx:fileset dir="${basedir}/${dist.dir}" includes="lib/*.jar"/>
          </fx:resources>
          <fx:info title="${application.title}" 
                   vendor="${application.vendor}"/>
        </fx:deploy>
     </target>

All the thing I done is just set the external jar's dir and includes in to the correct way.
from
<fx:fileset dir="${basedir}/${dist.dir}/lib" includes="*.jar"/>
to
<fx:fileset dir="${basedir}/${dist.dir}" includes="lib/*.jar"/>

2012-10-09

JavaFX 2 MDI プログラム

基本的に、MDIは現時点でJavaFX自体ではできない。

けれど、swingと組み合わせると、何とかできる。

keyword: swing, JDesktopFrame, JInternalFrame, JApplet

具体的にいうと、swingアプリの中に、JFrameの中身をすべてJApplet経由でJavaFXを呼び出す。

swingの奥が深いなぁ

人気の投稿