JAXB & java.mail Java 11: Module problems - jaxb

When I converted an application, that uses jaxb & java.mail, from java 8 to java 11 I had lots of module problems that seemed intractable.
My build.gradle included:
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
compile group: 'javax.mail', name: 'mail', version: '1.4.7'
The module errors I got included:
the unnamed module reads package javax.activation from both java.activation and activation
I tried this but it didn't work with the same error:
compile (group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1') {
exclude group: 'javax.activation', module: 'activation'
}
compile group: 'javax.mail', name: 'mail', version: '1.4.7'
And I tried this which also failed:
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
compile (group: 'javax.mail', name: 'mail', version: '1.4.7') {
exclude group: 'javax.activation', module: 'activation'
}
The error was:
java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
Also tried using in gradle with various exclude statements that all failed one way or another:
compile (group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1')
compile (group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1')
compile (group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.0.1')
Also got runtime error:
class not found com.sun.activation.registries.LogSupport

Solution
In the end I found that using glassfish.jaxb and jakarta.mail worked.
My build.gradle included:
compile(group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.2') {
exclude group: 'jakarta.activation', module: 'jakarta.activation-api'
}
compile group: 'com.sun.mail', name: 'jakarta.mail', version: '1.6.5'
My module-info.java included:
requires java.xml.bind;
requires jakarta.mail;
requires com.sun.xml.bind; // needed this for jlink
Hope this helps.

Related

Problems of Compilation in Liferay7

I have created the module attached by mail in liferay and developed in eclipse and executed the following commands for compiling it :
blade gw jar
o el comando
gradlew distBundle
I have the following build.gradle file :
dependencies {
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: '4.33.0'
compileOnly group: "javax.ws.rs", name: "javax.ws.rs-api", version: '2.1.1'
compileOnly group: "org.osgi", name: "org.osgi.core", version: "6.0.0"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations",version: '1.3.0'
compileOnly group: "org.osgi", name: "org.osgi.service.jaxrs",version: '1.0.0'
compileOnly group: "com.liferay", name: "com.liferay.asset.category.property.api",version: '2.1.3'
compileOnly group: "com.liferay", name: "com.liferay.dynamic.data.mapping.api",version: '6.0.1'
compileOnly group: "com.liferay", name: "com.liferay.journal.api",version: '2.1.0'
compileOnly group: "javax.servlet", name: "javax.servlet-api",version: '4.0.1'
}
Whe I compile I have the following error :
C:\Users\usuario\Documents\LiferayA1CuatroOchenta\modules\modulo-rest-gestion-contenidos\cuatroochenta-rest\src\main\java\com\cuatro\ochenta\onesignal\listener\AvisoListener.java:55: error: cannot access CTModel
if (Objects.equals(avisoStructureId, ddmStructure.getStructureId())) {
^
class file for com.liferay.portal.kernel.model.change.tracking.CTModel not found
C:\Users\usuario\Documents\LiferayA1CuatroOchenta\modules\modulo-rest-gestion-contenidos\cuatroochenta-rest\src\main\java\com\cuatro\ochenta\rest\resource\AgendaTematicaResource.java:69: error: cannot access CTService
DDMStructure ddmStructure = _ddmStructureLocalService.getDDMStructure(GetterUtil.getLong(PropsUtil.get("agenda.tematica.structure.id")));
^
class file for com.liferay.portal.kernel.service.change.tracking.CTService not found
2 errors
Whe I execute the following command :
gradle gw jar
The JournalArticle class cannot get the CTmodel
I have used the following Liferay version: 7.2.0-ga1
I have attached main files in the module folder.

Kafka Spark Streaming Filing with source KAFKA not found

I am trying to Steam a Producer Topic Form Kafka. Getting the error that Kafka is not a valid data source
I imported all the required packages like Kafka SQL streaming etc.
BUILD.Gradle FILE
dependencies {
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '2.2.0'
compile group: 'org.apache.kafka', name: 'kafka_2.12', version: '2.2.0'
compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.8'
compile group: 'org.scala-lang', name: 'scala-reflect', version: '2.12.8'
compile group: 'org.scala-lang', name: 'scala-compiler', version: '2.12.8'
compile group: 'org.scala-lang.modules', name: 'scala-parser-combinators_2.12', version: '1.1.2'
compile group: 'org.scala-lang.modules', name: 'scala-swing_2.12', version: '2.1.1'
runtime group: 'org.apache.spark', name: 'spark-mllib_2.12', version: '2.4.3'
compile group: 'org.apache.spark', name: 'spark-core_2.12', version: '2.4.3'
compile 'org.apache.spark:spark-streaming-flume-assembly_2.11:2.1.0'
compile group: 'org.apache.spark', name: 'spark-sql_2.12', version: '2.4.3'
compile group: 'org.apache.spark', name: 'spark-graphx_2.12', version: '2.4.3'
compile group: 'org.apache.spark', name: 'spark-launcher_2.12', version: '2.4.3'
testCompile group: 'org.apache.spark', name: 'spark-catalyst_2.12', version: '2.4.3'
provided group: 'org.apache.spark', name: 'spark-streaming_2.12', version: '2.4.3'
provided group: 'org.apache.spark', name: 'spark-hive_2.12', version: '2.4.3'
compile group: 'org.apache.spark', name: 'spark-avro_2.12', version: '2.4.3'
compile group: 'com.databricks', name: 'spark-avro_2.11', version: '4.0.0'
compile group: 'io.confluent', name: 'kafka-avro-serializer', version: '3.1.1'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
compile group: 'org.apache.spark', name: 'spark-streaming-kafka_2.11', version: '1.6.3'
compile group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.12', version: '2.4.3'
provided group: 'org.apache.spark', name: 'spark-sql-kafka-0-10_2.12', version: '2.4.3'
}
CODE:
import com.util.SparkOpener
import org.apache.spark.streaming._
import org.apache.spark.streaming.kafka.KafkaUtils
import org.apache.spark.streaming.kafka010.{ConsumerStrategies, LocationStrategies}
object SparkConsumer extends SparkOpener
{
val spark=SparkSessionLoc("SparkKafkaStream")
spark.sparkContext.setLogLevel("ERROR")
def main(args: Array[String]): Unit = {
val Kafka_F1Topic=spark.readStream.format("kafka").option("kafka.bootstrap.servers", "localhost:9092,localhost:9093,localhost:9094").option("subscribe","F1CarDetails").option("key.serializer", "org.apache.kafka.common.serialization.StringSerializer").option("value.serializer", "org.apache.kafka.common.serialization.StringSerializer").load()
Kafka_F1Topic.show()
}
}
Result :
Exception in thread "main" org.apache.spark.sql.AnalysisException:
Failed to find data source: kafka. Please deploy the application as
per the deployment section of "Structured Streaming + Kafka
Integration Guide".;
Structured Streaming Guide also used the same format.

Liferay: Reading Excel data using Apache POI

Getting the below error while reading the Excel data using Apache POI:
javax.xml.stream.FactoryConfigurationError: Provider
com.bea.xml.stream.EventFactory not found.
Below is the code I am using:
InputStream inputStream = new ByteArrayInputStream(byteCodeConversion);
ZipSecureFile.setMinInflateRatio(-1.0d);
XSSFWorkbook wb = new XSSFWorkbook(inputStream);//Throwing the error
Below are the dependencies I am using:
compile group: 'stax', name: 'stax-api', version: '1.0.1'
compile group: 'commons-codec', name: 'commons-codec', version: '1.9'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.15'
compile group: 'org.apache.poi', name: 'poi', version: '3.15'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'stax', name: 'stax-api', version: '1.0.1'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'

ClassNotFoundException: com.liferay.portal.kernel.model.BaseModelListener

I wrote a Liferay module:
#Component(
immediate = true,
service = ModelListener.class
)
public class TopMessageListener extends BaseModelListener<JournalArticle> {
// Do stuff
}
with this bnd.bnd:
Bundle-SymbolicName: fr.free.nrw.impl
Bundle-Version: 1.0.0
Liferay-Require-SchemaVersion: 1.0.0
Import-Package: !org.apache.avalon.framework.logger, !org.apache.log \
*
And this in my build.gradle (among other things):
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
compileInclude group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
It compiles fine, but deployment fails:
ClassNotFoundException: com.liferay.portal.kernel.model.BaseModelListener cannot be found by fr.free.nrw.impl_1.0.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:444)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:357)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:349)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
The error disappears if I replace compileOnly group: "com.liferay.portal" with compileInclude group: "com.liferay.portal", but I am sure it is not the correct way to do things. How to correctly fix the ClassNotFoundException above?
Please try this dependency
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
Duplicate the httpcomponents line into two lines, one compileOnly and one runtime:
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
runtime group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
That solved the problem for me.

Error java.lang.NoClassDefFoundError: com/liferay/util/dao/orm/CustomSQLUtil

I have added the jar named util-java.jar containing the above mentioned file into the build .gradle file. At compile time there is no error. But on executing the project I get a NoClassDefFoundError.
Please tell me how to eradicate this problem. My build.gradle is as follows:-
dependencies {
compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compile group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compile group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
compile project(":modules:customuser:customuser-api")
compile group: 'com.liferay.portal', name: 'portal-kernel', version: '5.2.3'
runtime group: 'com.liferay.portal', name: 'portal-kernel', version: '5.2.3'
compile group: 'com.liferay.portal', name: 'util-java', version: '6.2.4'
runtime group: 'com.liferay.portal', name: 'util-java', version: '6.2.4'
}
Something like :
compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql", version: "1.0.5"
Should help you.
This a version issue, change
compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
to
compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.5.0"

Resources