Cant Run Java FX Executable Jar or Native Bundle - javafx-2

I have created a java fx application on Netbeans 7.3.1 with fxml,hibernate. It works fine when run in Netbeans and when run the jar file from dist folder. Database operations are just fine. But I want export the app to another system in a portable form. So i created the native bundle using the tools Wix and Inno 5. But the produced app doesnt work in my own syntem or another system. Shows Exception while runnig application. I checked several times by changing the db ip address as localhost, 127.0.0.1 and my my physical ip. but no working.
My java version is Java 7 update 40 (jdk1.7.0_40)
This is the link for the screenshot showing error : http://i.imgur.com/popokhh.jpg
my build.xml contains
<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:resources>
<fx:info title="${application.title}" vendor="${application.vendor}"/>
</fx:deploy>
</target>
And my hibernate cfg file contains
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sample?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="entity/Sample.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Is there any extra configuration for the application to work independently??

I got it fixed...
All i need to do was include the lib folder in the build... My bad.

Related

How to hide Tomcat version from error messages when using embedded servers in Java

I have a java application where i'm using embedded Tomcat servers,
which looks like this
Tomcat tomcat = new Tomcat()
I'm creating an embedded tomcat server here.
Problem statement
whenever there's an error it displays information on which tomcat version i'm using,
how to hide this in java?
i have a little idea that i need to override ServerInfo.properties, but how do i do this?
I'm not sure how we can do this in java, but if you are using any build scripts like ant / gradle for distribution purpose, we can write a task to override / harden the jar file, and replace the ServerInfo.properties file with the customized value whatever we need.
the code for ant build scripts would look like
<target name="override.tomcat">
<jar destfile="path/to/tomcat-embed-core-9.0.62.jar" update="true">
<fileset dir="src/"> <!-- folder where you keep the directory/file to raplace-->
<include name="org/apache/catalina/util/ServerInfo.properties"/> <!-- file to replace within directory path in side the jar-->
</fileset>
</jar>
</target>
and in gradle
task overRideTomcat(type: Jar) {
from(zipTree(file("path/to/tomcat-embed-core-9.0.62.jar"))) {
exclude '**/org/apache/catalina/util/ServerInfo.properties'
}
from('src/') {
include('/org/apache/catalina/util/ServerInfo.properties')
}
archiveName "tomcat-embed-core-9.0.62.jar"
}
make sure you have the modified ServerInfo.properties file under src directory in the same path as you have mentioned in the include statement.

Ant Tomcat: Failed to create task or type "list"

I am using Spring official docs to understand the Spring Basic Application and Environment set up on Linux using Ant.
Softwares and system configurations:
OS: Linux/Ubuntu
JRE: 1.8.0_51-b16
Ant Version: 1.9.3
IDE: Luna Service Release 1 (4.4.1)
Project directory structure:
Everything goes fine till end of Section 1.3 where I can start the tomcat server and execute ant, ant deploy successfully and I have the desired output as follows:
But when I am trying to execute ant list - the build fails.
Buildfile: /home/sandeep/MyDocs/workspace/springapp/build.xml
list:
BUILD FAILED
/home/sandeep/MyDocs/workspace/springapp/build.xml:113: Problem: failed to create task or type list
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
Here is the list target in my build.xml:
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>
What am I doing wrong here? Here is a link to my entire build.xml.
In the article you linked to, it shows how to add the <list> task:
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
Add the above line to your build.xml.
I think task list is unknown to ant. There is no task named list defined by ant. To start tomcat I did something like --
<exec executable="${tomcat.home}/bin/tomcat5.exe" >
<arg value="start"/>
<env key="JAVA_OPTS"
value="-Xint -Xdebug -Xrunjdwp:transport=dt_socket,address=${hotswap.port},server=y,suspend=n"/>
</exec>
</target>

Using bouncycastle in Websphere liberty profile

Our application uses Bouncycastle. I am now attempting to deploy my app on websphere liberty profile and getting the below error
[err] java.io.IOException: error constructing MAC: java.lang.SecurityException: JCE cannot authenticate the provider BC
[err] at org.bouncycastle.jce.provider.JDKPKCS12KeyStore.engineLoad(Unknown Source)
[err] at java.security.KeyStore.load(KeyStore.java:1214)
[err] at com.manh.jwt.JwtKeyManager.loadPrivateKeyByIssuer(JwtKeyManager.java:213)
So instead of having the bouncycastle jar in WEB-INF/lib dir, i created a shared lib and added this library as a privateLibraryRef to my web application. I still get the same error.
Here is my server.xml for your reference.
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>servlet-3.0</feature>
</featureManager>
<webContainer deferServletLoad="false" />
<httpEndpoint id="defaultHttpEndpoint"
host="localhost"
httpPort="20000"
httpsPort="9443" />
<library id="configResources">
<folder dir="${server.config.dir}/conf" />
</library>
<library id="bc">
<fileset dir="${server.config.dir}/bclib" includes="*.jar" />
</library>
<webApplication name="scope" location="scope.war" contextRoot="/">
<classloader privateLibraryRef="configResources, bc" />
</webApplication>
</server>
Is there any other setting that i can try to have this working?
Here is the magic to get Bouncy Castle cryptography to work with WAS Liberty, which should work for the stacked products as well.
Create a "jvm.options" file in the servers working directory. In a default installation, this would be wlp/usr/servers/
Add the following to the "jvm.options" file.
a. -Djava.ext.dirs= //I tested this with /opt/fun/libs and wlp/usr/servers/defaultServer and wlp/usr/servers/defaultServer/libs. All three worked. If I included a path to a WEB-INF/lib directory it failed.
b. -Dorg.osgi.framework.bootdelegation=org.bouncycastle.jce.provider
Copy the bouncy castle jar from the WEB-INF/lib directory to the java.ext.dirs defined directory (above).
Stop and start the server, since you are changing JVM arguments.
Test the application or stacked product.

Deploying Custom theme in production server

I'm working on a Liferay project.
I'm developing a new Liferay theme using Plugins SDK.
I wonder is it better to use ANT or MAVEN for the project?
Because I managed to run both projects in eclipse.
Also is there any way to deploy automatically the theme in the production server ? (Distant server using tomcat).
For now I'm just using auto deployment, copying the war file to the /deploy file.
Regards
You can add remote server to your Eclipse with Plugins SDK, check https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/developing-apps-with-liferay-ide-liferay-portal-6-2-dev-guide-02-en
(this may be helpful for older versions of plugins-sdk)
Assuming that you have ssh access to the remote server, the following ant target can be added and used in /liferay-plugins-sdk/build-common-plugin.xml
<property name="web-server" value="11.11.11.11" />
<property name="web-server-username" value="yourusername" />
<property name="web-server-password" value="yourpassword" />
<property name="web-server-deploy-folder-path" value="/liferay-x.x/deploy" />
<target name="remote-deploy" depends="war">
<echo message="Copying plugin to remote server ..." />
<scp
file="${plugin.file}"
todir="${web-server-username}:${web-server-password}#${web-server}:${web-server-deploy-folder-path}"
trust="true"
/>
<echo message="Done!" />
</target>

JavaFx 2.0 application referencing external jars

I'm developing a JavaFx 2.0 application using Netbeans 7.
The main application references another class library project added by rightclicking the 'Libraries' folder and selecting 'Add Project...'. Executing the application from netbeans works fine.
When deploying it to a jar file by 'Clean and build' and trying to execute it via console with
java -jar TestApp.jar
I get
Exception in thread "JavaFX-Launcher" java.lang.NoClassDefFoundError: net/pmoule/SomeClass
...
The dist/lib folder of my application contains the referenced library. So IMHO everything should be fine. Looking at the Manifest.MF contained in my application jar I get this
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_23-b05 (Sun Microsystems Inc.)
Implementation-Vendor: pmoule
Implementation-Title: TestApp
Implementation-Version: 1.0
Main-Class: com/javafx/main/Main
JavaFX-Application-Class: testapp.TestApp
JavaFX-Version: 2.0
Where is my class path? How do I get Netbeans to add the correct classpath?
I tried adding it manually to the Manifest.MF by editing the one contained in the jar
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_23-b05 (Sun Microsystems Inc.)
Implementation-Vendor: pmoule
Implementation-Title: TestApp
Implementation-Version: 1.0
Class-Path: lib/MyLib.jar //THIS IS NEW
Main-Class: com/javafx/main/Main
JavaFX-Application-Class: testapp.TestApp
JavaFX-Version: 2.0
No success and same error.
All samples delivered with the JavaFX 2.0 SDK work by doubleclicking in WindowsExplorer or from the console by entering e.g.
java -jar PathAnimation.jar
But not any of these examples makes a reference to an external jar.
Some research lead me to this question: Netbeans JavaFX 2.0 Application
But without any solution so far.
Thanks for any help!
Found a working solution by myself.
All the external libraries in the dist/lin folder had a size of 0kb. So the exception was correct, of course.
To get my application running I did the following in the project's jfx-impl.xml:
Add the classpath to manifest.mf
<fxjar destfile="${jfx.deployment.dir}/${jfx.deployment.jar}" applicationClass="${main.class}" >
<fileset dir="${build.classes.dir}"/>
<manifest>
<attribute name="Implementation-Vendor" value="${application.vendor}"/>
<attribute name="Implementation-Title" value="${application.title}"/>
<!-- NEW --> <attribute name="Class-Path" value="${jar.classpath}"/> <!-- NEW -->
<attribute name="Implementation-Version" value="1.0"/>
</manifest>
</fxjar>
Create an output dir for web deployment
<property name="jfx.deployment.web.dir" location="${jfx.deployment.dir}/web" />
<mkdir dir="${jfx.deployment.web.dir}" />
Set output dir for fxdeploy task
<fxdeploy width="${jfx.applet.width}" height="${jfx.applet.height}"
outdir="${jfx.deployment.web.dir}" <!-- NEW DIR -->
embedJNLP="true"
outfile="${application.title}">
<info title="${application.title}"
vendor="${application.vendor}"/>
<application name="${application.title}"
appclass="${main.class}"/>
<resources type="eager">
<fileset dir="${jfx.deployment.web.dir}"> <!-- NEW DIR -->
<include name="${jfx.deployment.jar}"/>
<include name="lib/*.jar"/>
<exclude name="**/jfxrt.jar"/>
</fileset>
</resources>
</fxdeploy>
Now, I can deploy my desktop application and execute ist via doubleclick from windows explorer or by entering
java -jar TestApp.jar
There still exists some issue with the content of my newly created web-dir.
The TestApp.jar ist not copied zo dist/web
The referenced external jars are not copied to dist/web
This is fine for me and will be fixed some time later.
Hope this helps anyone else.
In Netbeans, under project => properties => Build => Packaging, did you check "Copy Dependent Libraries" ?
You need to tell the fx:jar task what your classpath dependencies are:
<fxjar destfile="${jfx.deployment.dir}/${jfx.deployment.jar}" applicationClass="${main.class}" >
<fileset dir="${build.classes.dir}"/>
<manifest>
<attribute name="Implementation-Vendor" value="${application.vendor}"/>
<attribute name="Implementation-Title" value="${application.title}"/>
<attribute name="Implementation-Version" value="1.0"/>
</manifest>
<!-- Setup the classpath for the generated .jar here -->
<fx:resources>
<fx:fileset type="jar" dir="lib" includes="MyLib.jar"/>
</fx:resources>
</fxjar>
You also need to use fx:resources tag in your fx:deploy task instead of just resources. That should resolve the last two problems left in your answer.

Resources