Java program running on build but not in a fat jar - java

I have a java application that uses the Jasper Reports API to generate a PDF. It builds fine but I had to add in some fonts via Netbeans/iReport plugin in order for them to show up when exporting the PDF. On clean and build it's fine and everything works.
But when I build a fat jar (via a few package-for-store lines in the build.xml) the reports won't run. Running via the Terminal, I get this error (sorry for wall of text):
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:124)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:89)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:104)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:62)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:108)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:668)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:649)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:971)
at ie.orderofmalta.OMFinancialsForm.yTDReportBtnActionPerformed(OMFinancialsForm.java:283)
at ie.orderofmalta.OMFinancialsForm.access$700(OMFinancialsForm.java:30)
at ie.orderofmalta.OMFinancialsForm$8.actionPerformed(OMFinancialsForm.java:163)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Input stream not found at : fonts/fontsfamily1406301744789.xml
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:188)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:56)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:110)
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
... 50 more
Caused by: net.sf.jasperreports.engine.JRException: Input stream not found at : fonts/fontsfamily1406301744789.xml
at net.sf.jasperreports.repo.RepositoryUtil.getInputStreamFromLocation(RepositoryUtil.java:159)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:183)
... 53 more
When I added in the fonts, I added them to a jar which I then added to the class path. By the "input stream not found" error I'm guessing this is something to do with those fonts. But everything works fine in the normal clean-and-build process but I can't understand why the fat jar won't work.
Any ideas?
EDIT: Very similar to this Font Extension for barcode in report

I was stuck with this same problem for two days and I could not find anything to help me. I hope this helps anyone facing the same problem.
Here is how I solved the problem.
First of all, the tools being used by me
Jaspersoft Studio to create my reports 6.0.3
Jasperreport Library 6.0.3
Arial Unicode MS, font being embedded
Netbeans 8.0.2
So, first I modified the file jasperreports_extension.properties inside of jasperreports-6.0.3.jar and included the following lines
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.dejavu=net/sf/jasperreports/fonts/fonts.xml
For some reason when I was building my jar file there was a conflict between the file jasperreports_extension.properties from jasperreports-6.0.3.jar and the one inside jasperreports-fonts-6.0.3.jar and the last one would be overridden.
Now to include my font (Arial Unicode MS) I edited the file /net/sf/jasperreports/fonts/fonts.xml and inserted the following code:
<fontFamily name="Arial Unicode MS">
<normal>net/sf/jasperreports/fonts/ArialUnicodeMS/ARIALUNI.TTF</normal>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
</exportFonts>
</fontFamily>
After this I included my font inside of jasperreports-fonts-6.0.3.jar.
Now this is very important, when you are creating your jar file make sure to extract jasperreports-fonts-6.0.3.jar before jasperreports-6.0.3.jar.
Here is my build.xml
<target name="-post-jar">
<jar jarfile="dist2/Reports.jar">
<zipfileset src="${dist.jar}" excludes="META-INF/*;*.jar;*.txt;*.html" />
<zipfileset src="lib/jetty-all-9.0.3.v20130506.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/lib/jasperreports-javaflow-6.0.3.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/jasperreports-fonts-6.0.3.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/jasperreports-6.0.3.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/mysql-connector-java-5.1.34-bin.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/commons-javaflow-20060411.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/servlet-api-2.4.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/javax.servlet-3.0.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/commons-logging-1.1.1.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/commons-collections-3.2.1.jar" excludes="META-INF/*;*.txt;*.html" />
<zipfileset src="lib/ant-1.7.1.jar" excludes="META-INF/*" />
<zipfileset src="lib/groovy-all-2.0.1.jar" excludes="META-INF/*" />
<zipfileset src="lib/commons-digester-2.1.jar" excludes="META-INF/*" />
<zipfileset src="lib/itextpdf-5.5.0.jar" excludes="META-INF/*" />
<zipfileset src="lib/itext-pdfa-5.5.0.jar" excludes="META-INF/*" />
<zipfileset src="lib/apache-commons-lang.jar" excludes="META-INF/*" />
<zipfileset src="lib/com.lowagie.text-2.1.7.jar" excludes="META-INF/*" />
<zipfileset src="lib/commons-beanutils-1.9.0.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Main-Class" value="Jetty"/>
</manifest>
</jar>
</target>

What solved it for me was to append the contents of the jasperreports_extension.properties file contained in the jasperreports-6.x.x.jar to my custom jasperreports_extension.properties.
The Problem was that the properties file from the jar got overwritten when creating the fat jar. Obviously JasperReports merges both files at runtime. Since the original content is missing, it causes this slightly misleading error.

Caused by: net.sf.jasperreports.engine.JRException: Input stream not found at : fonts/fontsfamily1406301744789.xml at
net.sf.jasperreports.repo.RepositoryUtil.getInputStreamFromLocation(RepositoryUtil.java:159) at
net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:183)
... 53 more
You need to provide a proper input stream to whatever you want to do here. If the resource is inside a jar file you must write special code to handle this. FileInputStreams will not work.

#eoinDub:
I had a similar problem when loading the report itselfes from the class directory of the fat jar. So I used "...getResourceAsStream()".
I did something like this (see code below). [Actually I used a compiled *.jasper - I don't remember whether an uncompiled *.jrxml did work, too.]
JasperReport report = null;
InputStream is = MyClass.class.getClassLoader().getResourceAsStream(reportName);
if (FilenameUtils.isExtension(reportName, "jrxml")) {
JasperDesign jd = JRXmlLoader.load(is);
report = JasperCompileManager.compileReport(jd);
} else {
report = (JasperReport) JRLoader.loadObject(is);
}
JRCsvDataSource ds;
try {
ds = new JRCsvDataSource(csvName, csvEncoding);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return;
}
ds.setUseFirstRowAsHeader(true);
ds.setFieldDelimiter(csvDelimiter.charAt(0));
JasperPrint jprint = JasperFillManager.fillReport(report, reportParams, ds);
try {
JasperExportManager.exportReportToPdfFile(jprint, outPDF);
} catch (Exception e) {
e.printStackTrace();
}

I was stuck with the same problem. In my project I am using Maven, and I noticed that at the end of generating the fat .jar, it threw a message of
jasperreports_extension.properties already added, skipping
Among what I saw on the web about this problem, I got that this file is repeated in several libraries, such as: jasperreports and jasperfonts; this causes conflicts between them and the Maven ignores them. So what I did was put my custom jasperreports_extension.properties file among the first Maven dependency files, so that this file setting takes it first.

Related

How to import properly a jar dependency into a .jar file generated by Ant? [duplicate]

This question already has an answer here:
How to include a .jar dependency into the ANT target that generate my final .jar file of my application?
(1 answer)
Closed 8 years ago.
I am pretty new in Ant and I have the following problem trying to create a build.xml file to compile a single class (that contains the main() method) command line application.
So this is the code of the Main class (at this time it is the only class in the application):
import java.sql.*;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World !!!");
System.out.println(args.length);
if(args.length != 0) {
String partitaIVA = args[0];
String nomePDF = args[1];
}
Connection conn = null;
Statement stmt = null;
try {
Class.forName ("oracle.jdbc.OracleDriver");
TimeZone timeZone = TimeZone.getTimeZone("Etc/GMT+2");
TimeZone.setDefault(timeZone);
// Step 1: Allocate a database "Connection" object
conn = DriverManager.getConnection("jdbc:oracle:thin:#XXX.XXX.XXX.XXX:1521:eme1", "myUserName", "myPswd"); // Oracle DB driver
System.out.println("After obtained connection with DB");
} catch(SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
As you can see the behavior of the main() method is very simple, at this time only obtain a connection with an Oracle database (represented by the Connection conn object). Running it into the IDE (I am using IntelliJ) it works fine (I can see it using the debugger, the **Connection conn is correctly set).
Now I am working on the following build.xml file for the Ant compilation:
<project name="edi-sta">
<description>
EDI-STA
</description>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/Main.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="Main"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/Main.jar" fork="true"/>
</target>
</project>
After that I have performed in order the clean, compile and jar targets I tried to open the console, access to the build/jar/ directory that contains the Main.jar file and I try to execute it performing the following statement:
C:\Projects\edi-sta\build\jar>java -jar Main.jar
Hello World !!!
0
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Main.main(Unknown Source)
C:\Projects\edi-sta\build\jar>
But, as you can see, now happens a very strange thing, it seems that can't found the class that contains the Oracle driver (oracle.jdbc.OracleDriver) so the ClassNotFoundException is thrown.
I think that this happens because if I open (with WinZip) my generated Main.jar file it only contains the Main.class file and the META-INF folder (that contains only the MANIFEST.MF file) but I have not the ojdbc6.jar file that contains the Oracle driver that I use.
So my question is: what have I to do to include this ojdbc6.jar dependency properly in my generated Main.jar file and avoid the ClassNotFoundException?
Tnx
You can define jar dependencies in the Class-Path attribute of the manifest file of the jar. Read the documentation here - http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
To achieve that from your ant task, use the Class-Path attribute as below
<jar destfile="build/jar/Main.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="Main"/>
<attribute name="Class-Path" value="your-jar-file"/>
....

Build error: NoClassDefFoundError: org/apache/xpath/XPathAPI [duplicate]

This question already has answers here:
java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI
(2 answers)
Closed 3 years ago.
I have upgraded my J2EE web application from jdk6,tomcat6 to jdk7 and tomcat7
but while deploying teamcity is giving following error.
[xmltask] java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI
java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI
at com.oopsconsultancy.xmltask.jdk14.XPathAnalyser14.analyse(XPathAnalyser14.java:29)
at com.oopsconsultancy.xmltask.XmlReplace.apply(XmlReplace.java:72)
at com.oopsconsultancy.xmltask.XmlReplacement.apply(XmlReplacement.java:61)
at com.oopsconsultancy.xmltask.ant.XmlTask.processDoc(XmlTask.java:707)
at com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:676)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: java.lang.ClassNotFoundException: org.apache.xpath.XPathAPI
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 25 more
The missing class is contained in xalan-2.7.0 (See Maven central). So I think the problem is how your classpath has been set.
Considering that this appears to be an error reported by the xmltask task, does this mean the error is being thrown by ANT?
Google found the following example which might be the answer to your problems:
https://wiki.nci.nih.gov/display/NBIA/Migration+to+Java+7
Add the xalan jar to the classpath of your taskdef:
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement path="${common.lib.dir}/xmltask-1.15.1.jar" />
<pathelement path="${common.lib.dir}/xalan-2.7.1.jar"/>
</classpath>
</taskdef>
if using maven add this to your dependencies section:
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.0</version>
</dependency>
I am not sure but, i guess jar named xalan-2.4.0.jar is missing
please download it and place inside.
http://www.java2s.com/Code/Jar/x/Downloadxalan240jar.htm
Add xpath to your classpath and try the deploy again. If you are not sure which xpath jar you need search in the tomcat libraries folder for xpathapi jar
Xpathapi is a jar used for evaluating xpaths (related to xml) in java. if you are not sure which version you need, google for it and fetch the latest xpath api jar .
For now I just remove
from my build.xml, and its working.
I know its not a solution but we have to deliver.
In Build.xml, change the java version to 1.7 and classpath XMLTask from 1.15.1 to 1.16.1.. It works
This is how I solved this, inlcuding Xalan and Serializer
Download xalan-j2-2.7.0.jar & serializer-2.7.0.jar
Update build.xml to include these jars in path
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement location="../xmltask-v1.14.jar"/>
<pathelement path="../xalan-j2-2.7.0.jar"/>
<pathelement path="../serializer-2.7.0.jar"/>
</classpath>
</taskdef>
This should get it running.
You should remove import org.apache.xpath.operations.String;.

Not able to execute jar file. Getting NoClassDefFoundError

I have created a executable jar file using build.
<target name="deploy" depends="compile">
<jar jarfile="${deploy.home}/${app.name}.jar" basedir="${build.home}">
<manifest>
<attribute name="Main-Class" value="abc.xyz"/>
</manifest>
</jar>
Here the xyz call has the main method to execute the whole program..
public static void main(String[] args) {
File buildFile = new File("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
}
The jar file is being created successfuly. When I execute the like java -jar appname.jar, it is throwing exception --
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Project
at abc.xyz.main(xyz.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Project
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
The project class not found. Its there in ant.jar.
But when i execute the abc.java class simply by on command prompt java abc its working fine.
Pleased help me to get the cause? and its solution.
Add required libraries to the class path of the jar
<target name="deploy" depends="compile">
<jar jarfile="${deploy.home}/${app.name}.jar" basedir="${build.home}">
<manifest>
<attribute name="Main-Class" value="abc.xyz"/>
<attribute name="Class-Path" value="ant.jar"/>
</manifest>
</jar>
If you need more than one jar you have to separate them by spaces.

Web-start exception JNLP

So I'm a bit confused on how to sign a jar in order for it to run as a jnlp.
At present I have a jar, it runs, starts to download and verify stuff, then it gets to the end and a window pops up saying it's unable to launch, then it gives the exception:
JNLPException[category: Launch File Error : Exception: null : LaunchDesc:
<jnlp codebase="http:/SomeHost:8080/_test/" href="jnlpcomponent1.jnlp" spec="1.0+">
<information>
<title>jnlpcomponent1</title>
<vendor>SUN_MICR</vendor>
</information>
<security>
<all-permissions/>
</security>
<resources>
<jar href="lib/activation.jar" download="eager"/>
<jar href="lib/mail.jar" download="eager"/>
</resources>
<component-desc/>
</jnlp>
]
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResourcesHelper(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResources(Unknown Source)
at com.sun.javaws.Launcher.prepareResources(Unknown Source)
at com.sun.javaws.Launcher.prepareAllResources(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I am fairly sure this has something to do with the jar being signed wrong / poorly... I could use some help in understanding what's going on here and how to fix it though.
Thanks a lot.
I am fairly sure this has something to do with the jar being signed
wrong / poorly
Exactly that happent, one of your jars isn't signed (properly)
What is always working for me:
unzip all jars than sign with 1 process. If is confirmed as it working, than I will remove 1-2 jar to match the original deployment design. And you will know in what jar is the problem, than easier to fix it.
You can use ANT to sign the JAR file. This way you can sign your files from within your IDE and it makes for a faster work-flow for when you deploy your appplication. Every change requires that you re-sign your application.
<project name="YourProject" default="dist" basedir="jarsigning">
<target name="signMainJar">
<signjar jar="../dist/YourApp.jar" destDir="signed" alias="WhateverYouSetIt2"
keystore="fileNameOfCerticate" storepass="passw03d" lazy="true" />
<echo message="The file was signed." />
</target>
<!-- Use this if you are using any libraries. These also need to be signed. -->
<target name="signLibs">
<signjar destDir="signed" alias="WhateverYouSetIt2"
keystore="fileNameOfCerticate" storepass="passw03d" force="true">
<path>
<fileset dir="lib" includes="*.jar" />
</path>
</signjar>
<echo message="The library files were signed." />
</target>
</project>
Before you can run this script, you need to first create a jarsigning directory and place a certificate (key) to be used for signing. Inside that folder, create a folder called "signed" and this is where your signed code will be placed by the script. Use the keystore tool to create a self-signed certificate if you have not purchased one from a granting authority like Verisign or GoDaddy.

Google App Engine entities in a separate project are not being dataenhanced

I have my application entities in a separate project from my main servlet, and they aren't being DataNucleus enhanced.
Not sure if I'm just breaking the rules or what, but setting the ORM setting on the project doesn't enhance my .class files. The way my workspace is built is by compiling the projects, then running an ant script builds jar files and copies them into the lib directory of my servlet.
I suppose that if I must, I can add some java tasks to my ant scripts to enhance my .class files. If that's the case, an example of the task would be helpful.
I do want to keep my projects are they are, let me know what I need to do to maintain that.
This is my build.xml of the project containing my entities:
<project default="default">
<property name="appengine.sdk.dir" location="C:\superlongpathtomyeclipseplugins\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\appengine-java-sdk-1.6.5"/>
<import file="${appengine.sdk.dir}/config/user/ant-macros.xml"/>
<target name="default" depends="dist"/>
<target name="dist">
<enhance>
<classpath>
<pathelement path="${appengine.sdk.home}/lib/*"/>
<pathelement path="bin"/>
</classpath>
<fileset dir="bin" includes="**/*.class" />
</enhance>
<jar basedir="bin" destfile="dist\sessionexample.model.jar"/>
</target>
</project>
But now here is the error I'm getting:
java.lang.RuntimeException: Unexpected exception
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
at com.google.appengine.tools.enhancer.Enhance.(Enhance.java:71)
at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:74)
... 2 more
Caused by: java.lang.NoClassDefFoundError: com/google/appengine/api/datastore/Key
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getDeclaredMethods(Unknown Source)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getJavaBeanAccessorAnnotationsForClass(AbstractAnnotationReader.java:238)
at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:128)
at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:136)
at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2278)
at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:385)
at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:743)
at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:545)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1252)
... 7 more
Caused by: java.lang.ClassNotFoundException: com.google.appengine.api.datastore.Key
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.google.appengine.tools.enhancer.EnhancerLoader.loadClass(EnhancerLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 18 more
Do I need to keep adding things to my <classpath> until it works?
The DataNucleus project defines many ways to run enhancement. It's for you to choose which one makes most sense to your environment and build system. Any other methods not defined on that page are not supported (by us)
Finally got an ant task to run:
<project default="default">
<property name="appengine.sdk.dir" location="c:\pathtoeclipse\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\appengine-java-sdk-1.6.5"/>
<import file="${appengine.sdk.dir}/config/user/ant-macros.xml"/>
<target name="default" depends="dist"/>
<target name="dist">
<enhance>
<classpath>
<pathelement path="${appengine.sdk.home}/lib/*"/>
<pathelement path="${appengine.sdk.home}/lib/user/*"/>
<pathelement path="${appengine.sdk.home}/lib/user/orm/*"/>
<pathelement path="bin"/>
</classpath>
<fileset dir="bin" includes="**/*.class" />
</enhance>
<jar basedir="bin" destfile="dist\sessionexample.model.jar"/>
</target>
</project>

Categories