phax / ph-ubl

Java library for reading and writing UBL 2.0, 2.1, 2.2, 2.3 and 2.4 documents
Apache License 2.0
111 stars 40 forks source link

Error when run createinvoicefromscratch #51

Closed belya1979 closed 2 years ago

belya1979 commented 2 years ago

I'm using these libraries in my project:

when i run the CreateInvoiceFromScratchFuncTest.testCreateInvoiceFromScratch , i faced the following error . either with java 8 or java 11 . the error is as following :

Exception in thread "main" java.lang.NoClassDefFoundError: com/helger/xsds/ccts/cct/schemamodule/IdentifierType at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType.setID(InvoiceType.java:4269) at javaapplication13.JavaApplication13.testCreateInvoiceFromScratch(JavaApplication13.java:56) at javaapplication13.JavaApplication13.main(JavaApplication13.java:41) Caused by: java.lang.ClassNotFoundException: com.helger.xsds.ccts.cct.schemamodule.IdentifierType at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 27 more

phax commented 2 years ago

Well, you also need:

I recommend to use Maven or Gradle to work around these issues.

belya1979 commented 2 years ago

thanks for your fast reply dear, so, if i use Maven, what are exactly the dependencies which i should add them to the POM file. and their versions too BTW: I'm using java 11 and i need to implement xml invoice using ubl2.1 Thanks again

phax commented 2 years ago

If you use Maven, it includes all the needed dependencies "transitively". In Maven you need to include this (with 6.7.0 is the latest and greatest version):

    <dependency>
      <groupId>com.helger.ubl</groupId>
      <artifactId>ph-ubl21</artifactId>
      <version>6.7.0</version>
    </dependency>
belya1979 commented 2 years ago

Amazing dear, all things built successfully after I use Maven. but I got a following runtime error: java.lang.IllegalArgumentException: Failed to create JAXB context for package 'oasis.names.specification.ubl.schema.xsd.invoice_21' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@2cdf8d8a at com.helger.jaxb.JAXBContextCacheKey._createFromPackageAndClassLoader(JAXBContextCacheKey.java:165) at com.helger.jaxb.JAXBContextCacheKey.createJAXBContext(JAXBContextCacheKey.java:202) at com.helger.jaxb.JAXBContextCache.lambda$new$0(JAXBContextCache.java:81) at com.helger.commons.cache.MappedCache.getFromCache(MappedCache.java:337) at com.helger.jaxb.JAXBContextCache.getFromCache(JAXBContextCache.java:124) at com.helger.jaxb.JAXBContextCache.getFromCache(JAXBContextCache.java:166) at com.helger.jaxb.builder.AbstractJAXBBuilder.getJAXBContext(AbstractJAXBBuilder.java:164) at com.helger.jaxb.builder.AbstractWritingJAXBBuilder.createMarshaller(AbstractWritingJAXBBuilder.java:80) at com.helger.jaxb.builder.JAXBWriterBuilder.createMarshaller(JAXBWriterBuilder.java:232) at com.helger.jaxb.builder.JAXBWriterBuilder.write(JAXBWriterBuilder.java:298) at com.helger.jaxb.IJAXBWriter.write(IJAXBWriter.java:381) at com.helger.jaxb.IJAXBWriter.write(IJAXBWriter.java:234) at com.helger.jaxb.IJAXBWriter.write(IJAXBWriter.java:195) at com.ase.ubl.ubl21test.UBL21Test.testCreateInvoiceFromScratch(UBL21Test.java:131) at com.ase.ubl.ubl21test.UBL21Test.main(UBL21Test.java:48) Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.

phax commented 2 years ago

My bad - I forget one "optional" depencency. Please also add this:

    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>2.3.6</version>
    </dependency>
phax commented 2 years ago

That is the main JAXB dependency, that does the heavy lifting

belya1979 commented 2 years ago

it's worked. u r the best ever. too many thanks.. I wish all the best for you

phax commented 2 years ago

Thanks for the nice words. Good luck with your endeavours :)