creating XSD using jaxb schemagen - java

i am learning JAXb 2.0 and is new to it.
i am trying to generate XSD based on y POJO classes using schemagen and for simple classes it working fine but when my class contains refrence to other classes
schemagen is giving me error below is the error trace for the same
Problem encountered during annotation processing;
see stacktrace below for more information.
java.lang.NullPointerException
at com.sun.tools.jxc.model.nav.APTNavigator$2.onDeclaredType(APTNavigator.java:436)
at com.sun.tools.jxc.model.nav.APTNavigator$2.onClassType(APTNavigator.java:410)
at com.sun.tools.jxc.model.nav.APTNavigator$2.onClassType(APTNavigator.java:464)
at com.sun.istack.tools.APTTypeVisitor.apply(APTTypeVisitor.java:27)
at com.sun.tools.jxc.model.nav.APTNavigator.getBaseClass(APTNavigator.java:113)
at com.sun.tools.jxc.model.nav.APTNavigator.getBaseClass(APTNavigator.java:89)
at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.getIndividualType(PropertyInfoImpl.java:195)
at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.<init>(PropertyInfoImpl.java:137)
at com.sun.xml.bind.v2.model.impl.MapPropertyInfoImpl.<init>(MapPropertyInfoImpl.java:71)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.createMapProperty(ClassInfoImpl.java:928)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.addProperty(ClassInfoImpl.java:885)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findGetterSetterProperties(ClassInfoImpl.java:1004)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl.java:314)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:247)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:213)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:319)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:334)
at com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.java:94)
at com.sun.tools.jxc.apt.SchemaGenerator$1.process(SchemaGenerator.java:119)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
at com.sun.tools.apt.main.Main.compile(Main.java:1102)
at com.sun.tools.apt.main.Main.compile(Main.java:964)
at com.sun.tools.apt.Main.processing(Main.java:95)
at com.sun.tools.apt.Main.process(Main.java:85)
at com.sun.tools.apt.Main.process(Main.java:67)
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.sun.tools.jxc.SchemaGenerator$Runner.main(SchemaGenerator.java:245)
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.sun.tools.jxc.SchemaGenerator.run(SchemaGenerator.java:177)
at com.sun.tools.jxc.SchemaGenerator.run(SchemaGenerator.java:81)
at com.sun.tools.jxc.SchemaGenerator.main(SchemaGenerator.java:73)
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.sun.tools.jxc.SchemaGeneratorFacade.main(SchemaGeneratorFacade.java:60)
C:\Users\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\tr\model\destination\Destination.java:9: package com.tr.model.address does not exist
import com.tr.model.address.BasicAddress;[code]
below is the detail of my folder structure
schemagen is located at the following location
C:\Users\Desktop\jaxb\jaxb-ri-20101119\bin
My Java class based on which i am trying to generate xsd is at the following location
C:\Users\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\tr\model\destination
Destination.java
while all other classes being refrenced from Destination as well as the class itself are inside the following structure
C:\Users\Raisonne\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\raisonne\tr\model
i know the problem is with the setting of classpath but i am unable to figure it out ho to set correct classpath for this case
i tried to set system's CLASSPATH variable to the value of
C:\Users\Raisonne\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\raisonne\tr\model as well other 2 mentioned in my post but nothing worked out.
can any one help me in setting classpath for the schemagen.
thanks in advance
Umesh

it seems you have set package declaration of your class to
com.tr.model.address
where it should be from your dir structure
com.tr.model.destination

Related

Issue displaying a map with java [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I currently am trying to make a risk-like game and as I try to display a map (vectorial image) I have a NullPointerException that I do not understand at all how it can be solved. =/
Here's the code :
public class Test1 extends Stage {
private BorderPane root = new BorderPane();
private WebView browser = new WebView();
public Test1(){
this.setTitle("Test1");
this.setScene(new Scene(content()));
}
Parent content(){
WebEngine webEngine = browser.getEngine();
webEngine.load(this.getClass().getResource("../../resources/worldMap.html").toExternalForm());
root.setCenter(browser);
return root;
}
}
and the error :
Exception in Application start method
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.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at hmi.Test1.content(Test1.java:23)
at hmi.Test1.<init>(Test1.java:18)
at Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application Main
So it seems to be caused by the link "../../resources/worldMap.html" but it really leads to the file. I also tried with a svg file or with an url (this one : https://upload.wikimedia.org/wikipedia/commons/8/80/World_map_-_low_resolution.svg )
and I still have the exact same error.
It's been a day I'm stuck on that despite my researchs on internet, so I hope you will be able to help me.
Thanks !
I can't say for certain from the pasted code, but I think I can help you debug it. You've identified webEngine.load(this.getClass().getResource("../../resources/worldMap.html").toExternalForm()); as the errant line in one of your comments.
The NPE means one of the things you are using in that line is null in an unexpected way. Are you using an IDE with a debugger? Set a break-point on that line and evaluate each subcomponent.
If not, you really should try one. I use intellij and find it makes me far more effective and efficient. In the interim, the hackiest simplest way to figure this out is with a bunch of print statements
System.out.println("webEngine" + webEngine);
System.out.println("class" + this.getClass());
System.out.println("resource" + this.getClass().getResource("../../resources/worldMap.html"));
System.out.println("loaded" + webEngine.load(this.getClass().getResource("../../resources/worldMap.html"));
One of these things will be null and the next line will throw an NPE. That way, you'll know where in the stack you have a problem. Please post back when you find it. I would guess that either using the this.getClass.getResource is wrong or the place you think the relative path starts from in your path string is wrong (usually it is relative to where your .class paths are written).
Have you tried using an absolute path instead to load your resource? It's possible where you think your code is executing from and where it's actually executing from are different.
Ok, I finally found out the answer.
My question is actually a duplicate of Class.getResource() returns null
And the answer was that the image had to be in the same directory as the package where the class on which I apply the "getclass" is, while it was in the root of the project.
Thank you for your help though !

java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder

Summary:
When I try loading a DLL and the language in my computer is set to a non-latin based language (such as Korean), I get the error java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder
If you can help me figure out how to avoid this error, I'd appreciate any help.
I am trying to load a Native DLL Library using:
Native.loadLibrary
But I keep getting these errors:
java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder
at java.nio.file.FileSystems.<unknown>(Unknown Source)
at java.io.File.toPath(Unknown Source)
at sun.security.provider.SeedGenerator$1.run(Unknown Source)
at sun.security.provider.SeedGenerator$1.<unknown>(Unknown Source)
at java.security.AccessController.<unknown>(Unknown Source)
at sun.security.provider.SeedGenerator.getSystemEntropy(Unknown Source)
at sun.security.provider.SecureRandom$SeederHolder.<clinit>(Unknown Source)
at sun.security.provider.SecureRandom$SeederHolder.access$100(Unknown Source)
at sun.security.provider.SecureRandom.engineNextBytes(Unknown Source)
at java.security.SecureRandom.nextBytes(Unknown Source)
at java.security.SecureRandom.next(Unknown Source)
at java.util.Random.nextLong(Unknown Source)
at java.io.File$TempDirectory.generateFile(Unknown Source)
at java.io.File.createTempFile(Unknown Source)
at com.sun.jna.Native.extractFromResourcePath(Native.java:839)
at com.sun.jna.Native.loadNativeLibraryFromJar(Native.java:751)
at com.sun.jna.Native.loadNativeLibrary(Native.java:737)
at com.sun.jna.Native.<clinit>(Native.java:129)
at com.sun.jna.Native.loadLibrary(RefProp.java:246)
I only get this error when I set my language in my computer to Korean (or any other non-Latin language). When I have it as English, I don't have the error.
By the way, I have set the character encoding as UTF-8:
This code:
Charset charset = Charset.defaultCharset();
System.out.println("Character Set: " + charset.displayName());
Gives this result:
Character Set: UTF-8
So I know the encoding is not the problem.
I've read through:
http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html
OSGi noClassDefFound for java.nio.files.FileSystems$DefaultFileSystemHolder
- Doesn't seem to apply because the error is slightly different.

MyBatis is looking for org/hsqldb/DatabaseURL while I set for MmySQL

I steup a sample project with Maven3/Guice/MyBatis3.1 and using "jdbc:mysql://..."
but when I want to call the mapper methods( mapper.getBean() ) I am getting :
java.lang.NoClassDefFoundError: org/hsqldb/DatabaseURL
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:190)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:191)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:186)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:88)
at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:373)
at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:82)
at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:131)
at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:58)
Make sure the library containing org.hsqldb.DatabaseURL is on your classpath

readObject() is not working and breaks from method

I'd like to read different kinds of objects from file to an ArrayList, all of them are instances of class which extend the class Advertisement. I'm trying with this code:
ArrayList <Advertisement> ads = new ArrayList<Advertisement>();
ObjectInput input2 = new ObjectInputStream(
new BufferedInputStream(new FileInputStream("ads.ser")));
//break from this method at this point
ads = (ArrayList<Advertisement>) input2.readObject();
The problem is at the 3rd line/last line. It doesn't read the objects in variable ads of type ArrayList<Advertisement>, furthermore, it breaks from this method, without any messages.
Edit: Removed the try-catch block, I should have done it earlier, but I still don't know the solution. Stacktrace:
java.io.InvalidClassException: Kiado; local class incompatible: stream classdesc serialVersionUID = -1393576200767336208, local class serialVersionUID = -841663850423605586
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.ArrayList.readObject(Unknown Source)
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 java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at Main.beolvasas(Main.java:30)
at Main.startup(Main.java:57)
at Main.main(Main.java:633)
Now that you have a stack trace, the problem is clear: since the moment you serialized the objects to the file, you have made changes to the class Kiado. So the class you have now is not compatible anymore with the class as it was when serializing the objects to the file.
If you didn't change the number and the names of the fields of the class (and of all its superclasses), you can make it compatible again by just adding the following variable declaration in the class:
private static final long serialVersionUID = -1393576200767336208;
If you added, removed or renamed at least one (non-transient) field, then you might make the new class still compatible with the old one, but with more pain. And we would have to know the nature of the changes to help you.
I would personally avoid using native serialization for long-term storage because, as you just noticed, it's fragile and makes it hard to change the model. I would use a more easily readable and migratable file format: XML or JSON for example.
Do you have any code like:
catch(<WheteverException> e)
{
// nothing here
}
If so do the following:
change the // nothing here to e.printStackTrace();
remove the try/catch and only add it back if the compiler tells you to, and then only add back what exception that the compiler tells you to add (for instance don't do catch(Exception e).

Unmarshaling xml with html entities using JAXB

I need to load wikipedia revision histories into POJOs, so I'm using JAXB to unmarshall the wikipeida data dump (well, individual pages of it). The problem is that the text nodes occasionally contain entities that are not defined in the wikipedia xml dump. eg: ° (`°' pleases keep in mind that I do not know the complete set of entities that I need to be able to read. My input file is 3tb, so let's just assume that everything html can render is in there.).
How can I configure JAXB to handle entities that are not valid xml?
Here is the SAX Exception that JAXB throws when it encounters an undefined entity:
Exception in thread "main" javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: The entity "deg" was referenced, but not declared.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:481)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:199)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
at com.stottlerhenke.tools.wikiparse.WikipediaIO.readPage(WikipediaIO.java:73)
at com.stottlerhenke.tools.wikiparse.WikipediaIO.main(WikipediaIO.java:53)
Caused by: org.xml.sax.SAXParseException: The entity "deg" was referenced, but not declared.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:195)
Edit: The input that triggered that exception is the complete revision history for the wikipedia article on the Arctic Circle. The XSD used to generate the JAXB classes is here: http://www.mediawiki.org/xml/export-0.3.xsd
Edit: The source of this problem was an error on my part -- I was using an initial extractor that did not maintain encoded entities properly. However, I did find a way around this, should anyone have the problem I thought I had. See below.
Resolving entities is not the job of JAXB's. It's the job of the underlying
XML parser.
What you could do is:
read the data yourself using DOM
replace all unresolved entities by something you wish
then, let JAXB handle the result
This is a hack, but it works in a pinch.
I downloaded the html entity definitions from w3.org, and set the doctype of the input xml file to xhtml-transitional, but directed the doctype url to a local dtd:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd">
xhtml1-transitional.dtd, in turn, requires:
xhtml-lat1.ent
xhtml-special.ent
xhtml-symbol.ent
which I sucked down and put along side xhtml1-transitional.dtd
(All files are available at: http://www.w3.org/TR/xhtml1/DTD/ )
Like I said, ugly as hell, but it did seem to do the job.

Categories

Resources