jdk 11 - package javax.xml.bind.annotation is declared in the unnamed module, but module javax.xml.bind.annotation does not read it - jaxb

I red all other topics (maybe work for jdk 10) and still have problem to run javax.xml.bind on jdk 11.
My dependency:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version> <!-- 2.2.12, 2.3.1 -->
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version> <!-- 2.3.1 -->
<!--<scope>compile</scope>-->
<!--<scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
My IDE (newest intellij) still doesn't see import:
import javax.xml.bind.annotation.XmlAccessType;
Also my module-info.java doesnt see:
requires java.xml.bind;
And when i use maven i have an error:
[ERROR] ...ExceptionType.java:[6,22] package javax.xml.bind.annotation is not visible
(package javax.xml.bind.annotation is declared in the unnamed module, but module javax.xml.bind.annotation does not read it)
anybody run it on jdk 11 ?
edit:
1) App version with java module system:
i have similar problem to this:
https://youtrack.jetbrains.com/issue/IDEA-197956
but my error message is a little difrent
2) App version without java module system:
Maven compile correctly. Problem is that intellij dont see my imports:
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
and say: cannot resolve symbol.
Also at file > project structure > modules > dependencies intellij didnt add javax.xml.bind and org.glassfish.jaxb
Why?
I added this in pom:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version> <!-- 2.2.8, 2.4.0-b180830.0359 -->
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version> <!-- 2.3.0, 2.4.0-b180830.0438 -->
</dependency>
JDK: openjdk11
Intellij version: IntelliJ IDEA 2018.2.4 (Ultimate Edition), Build #IU-182.4505.22, built on September 18, 2018, JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Maven:3.5.4
It seems to be a intellij bug.

Switched back to JDK 1.8 and it fixed this issue for me. How to switch in ubuntu: https://askubuntu.com/questions/740757/switch-between-multiple-java-versions

We managed to find the cause of the problem. In ide intellij I have a modules maven project and I use JLupin Platform Development Tool, so in *.iml files i dont have line:
'<'module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule = "true" type = "JAVA_MODULE" version = "4">
but i have for example:
'<'module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule = "true" type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE" version = "4">
During the development, the names of the modules were changed, then the idea asked whether to remove modules (because ide did not recognize:
type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE").
Although the chosen option was not, then ide automatically performed:
selecting the maven module as ignored
replace in the iml file from:
'<'module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule = "true" type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE" version = "4">
to:
'<'module type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE" version = "4">
For the above reason, the project did not correctly read the maven artifacts. After unifying the names and marking the project as not ignored, it works correctly.
The problem is not related to java packages
EDIT: its resolved as above

Related

Giving maven dependency error in Spark 2.3

I am building spark 2.3 scala code using maven , giving following error.
error: missing or invalid dependency detected while loading class file SparkSession.class.
This is snippet of pom file, please advise
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.3.0</version>
</dependency>
You might want to check your Java and Scala versions. They should be 1.6 or higher and 2.11 respectively. Or it could also be a mismatch with other dependencies like spark_sql.Make sure you have same version across all dependencies.

Correct configuration for Maven to load Native Hadoop Libraries

I am trying to run a Mahout project which I wrote in Eclipse with the Mahout and Hadoop libraries. It loads in a dataset and runs the FPGrowth algorithm. I set up the following Run configuration to run the project:
mvn exec:java -Dexec.mainClass=com.patternmatching.RecommendApp.TopPatternMatches
After running the program, I get the following error message:
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
I researched this issue, and realized that the Native hadoop libraries have to either be compiled, or downloaded from Apache (Hadoop "Unable to load native-hadoop library for your platform" warning) . I downloaded the libraries on a Cloudera Quickstart VM, on which I set up Mahout and Maven, along with my project package. After running it in cloudera, I get the same error. I also ran the Hadoop checknative -a command, which verifies that the Native libraries are available:
[root#quickstart /]# hadoop checknative -a
16/10/22 19:32:16 INFO bzip2.Bzip2Factory: Successfully loaded & initialized native-bzip2 library system-native
16/10/22 19:32:16 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
Native library checking:
hadoop: true /usr/lib/hadoop/lib/native/libhadoop.so.1.0.0
zlib: true /lib64/libz.so.1
snappy: true /usr/lib/hadoop/lib/native/libsnappy.so.1
lz4: true revision:99
bzip2: true /lib64/libbz2.so.1
openssl: true /usr/lib64/libcrypto.so
The output of the command verifies that the libraries are available, but are not being correctly loaded into the program or classpath. I am not sure how to configure Maven so that it loads in the Hadoop native libraries when running the program. This is the dependencies section of the Maven pom.xml file:
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.0.0-alpha1</version>
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
and the command I run to execute my Mahout java program is
mvn exec:java -Dexec.mainClass=com.patternmatching.RecommendApp.TopPatternMatches
How can I configure Maven to see these libraries so they are used in the program?

Getting error during running Cucumber feature file Unknown option: --plugin

Usage: java cucumber.api.cli.Main [options] [ [FILE|DIR][:LINE[:LINE]*] ]+
Options:
-g, --glue PATH Where glue code (step definitions and hooks) is loaded from.
-f, --format FORMAT[:PATH_OR_URL] How to format results. Goes to STDOUT unless PATH_OR_URL is specified.
Built-in FORMAT types: junit, html, pretty, progress, json.
FORMAT can also be a fully qualified class name.
-t, --tags TAG_EXPRESSION Only run scenarios tagged with tags matching TAG_EXPRESSION.
-n, --name REGEXP Only run scenarios whose names match REGEXP.
-d, --[no-]-dry-run Skip execution of glue code.
-m, --[no-]-monochrome Don't colour terminal output.
-s, --[no-]-strict Treat undefined and pending steps as errors.
--snippets Snippet name: underscore, camelcase
--dotcucumber PATH_OR_URL Where to write out runtime information. PATH_OR_URL can be a file system
path or a URL.
-v, --version Print version.
-h, --help You're looking at it.
Exception in thread "main" cucumber.runtime.CucumberException: Unknown option: --plugin
at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:119)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:50)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:44)
at cucumber.api.cli.Main.run(Main.java:20)
at cucumber.api.cli.Main.main(Main.java:16)
I am getting this error during running my feature file.
PoM dependency is given below and I am using 3.2.4 Spring version with cucumber veriosn 1.1.5
Looks like you are using a very old version of cucumber-jvm that is looking for
--format
instead of
--plugin
The latest cucumber-jvm usage text can be found here.
Get the latest cucumber-jvm from the Maven repository as described here or here.
Either its related with JAR library(ies) version mismatch or plugin(cucumber-eclipse-plugin) mismatch.
look Here: https://groups.google.com/forum/#!topic/cukes/1urjr3ASq78
I was also facing similar issue. The cucumber jars were old. So I updated it as below using maven repository
<properties>
<cucumber.version>6.10.3</cucumber.version>
</properties>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
NOTE: you can find the latest cucumber java in maven repository at this link Cucumber jars maven dependency

Unable to start spring boot server

I am new to spring boot and when I try to start my server , I get the following Exception. I understand that this has something to do with dependency conflict, but still unable to figure it out.I am using maven to manage my dependencies.Please help
Exception in thread "main" java.lang.IllegalArgumentException:
LoggerFactory is not a Logback LoggerContext but Logback is on the
classpath. Either remove Logback or the competing implementation
(class org.slf4j.impl.Log4jLoggerFactory) Object of class
[org.slf4j.impl.Log4jLoggerFactory] must be an instance of class
ch.qos.logback.classic.LoggerContext at
org.springframework.util.Assert.isInstanceOf(Assert.java:339) at
org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:93)
at
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSensibleDefaults(AbstractLoggingSystem.java:62)
at
org.springframework.boot.logging.AbstractLoggingSystem.beforeInitialize(AbstractLoggingSystem.java:45)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:69)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:135)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
at
org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
at
org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:54)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:276)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at org.magnum.mobilecloud.video.Application.main(Application.java:30)
Resolved:Add the following to the POM.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
Excluding logback-classic from spring-boot-starter-web and spring-boot-starter-actuator worked for me
compile("org.springframework.boot:spring-boot-starter-web:1.1.10.RELEASE") {
exclude module: "spring-boot-starter-tomcat"
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-actuator:1.1.10.RELEASE") {
exclude module: "logback-classic"
}
Add this to your build.gradle
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.springframework.boot', module: 'logback-classic'
}
In my project, it is using
spring boot 1.4.2.RELEASE
both slf4j 1.7.21 and logback 1.1.7. (some dependency , called module A, depend on logback 1.1.2, this is the issue)
First Introduction to the Dependency Mechanism
Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.
"nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0
So maven will use logback 1.1.7 in my project. I am not sure it is my module A not compatible with 1.1.7 or logback 1.1.7 not compatible with slf4j 1.7.21
Whatever, in my case. I add dependencyManagement in my pom. Tell maven use lockback 1.1.2 only. Problem solved.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>
the following configuration in my gradle.build file worked for me:
configurations {
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
all*.exclude group: "ch.qos.logback"
all*.exclude group: "org.slf4j", module: "log4j-over-slf4j" // allow using log4j 2.x
all*.exclude group: "org.slf4j", module: "slf4j-simple" // log4j is the configured backend
}
Repeat answer but you can use Eclipse to exclude the spring-boot-starter-logging dependency
Select dependency hierarchy
Search for logging top right
Select spring-boot-starter-logging
Right click exclude maven artifact
e.g
enter image description here
Gradle solution is adding below lines in build.gradle :
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
I would recommend you to try removing any dependency that contains the Logback, the most common one is:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
It worked for me.
Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. If you use the starters for assembling dependencies, you have to exclude Logback and then include log4j 2 instead.
Resolved the issue by adding the below dependencies in this order
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Finally resolved this issue by excluding the Logback dependency and explicitly adding the log4j dependency

Which JDK's distributions can run `javac -source 1.6 -target 1.5`?

NOTE: Please do not comment on all the perils of cross-compiling. Thank you.
I have a situation where we need to have Java 6 source compiled for a Java 5 JVM (to be sure that JAX-WS usage is correct). Previously we have done this with ant ant script (which apparently can), but after migrating to Maven we have found that it ends up with javac complaining:
$ javac -source 1.6 -target 1.5
javac: source release 1.6 requires target release 1.6
Is there any Java distribution for Linux (Ubuntu 11.10, x86) where the javac can do this?
EDIT: It appears not, as the limitation is in javac which is the same. The solution (which made this need go away) was to change from the default javac compiler to the eclipse compiler in maven-compiler-plugin.
EDIT: I've found that the Eclipse compiler generates byte code for anonymous inner classes that the javadoc utility disagrees with. I am preparing a bug report for this issue.
According to the documentation (Java 5, Java 6), the Oracle SDK should be able to do this when you follow the instructions in the Cross-Compilation Example.
Java 6 should support any version between 1.3 to 1.6 as -target; it doesn't say anything what happens when you use generics and other "compatible" features in the source. The compiler should be able to strip them.
Another culprit in the game might be javac: The compiler might be able to handle this set of arguments but the command line tool might take offense.
In this case, write your own command line using the Java Compiler API. That might allow to pull of some tricks that you can't achieve otherwise.
You can also try the Eclipse compiler (see "Using the batch compiler").
This might fail because of how Java works: Java X code can run on Java Y as long as X <= Y. So while you can easily compile Java 1.4 code for a Java 6 VM, the reverse is not always true.
If everything else fails, write a preprocessor that reads the source and strips unsupported elements (like #Override on interfaces). As long as you compile the code with the annotations once in a while with Java 6, the converted code should be safe as well (unless your code stripper has a bug ...)
This answer is an implementation of what #ThorbjørnRavnAndersen explained in the comments as a solution. Using the example code from here, and fixing a few typos, I was able to come up with an example using Eclipse Compiler.
Calculator.java
package example;
// there needs to be a package to avoid A "#WebService.targetNamespace must be specified on classes with no package"
// when running this
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;
#WebService
public class Calculator {
#WebMethod
public int add(int a, int b) {
return a+b;
}
public static void main(String[] args){
// create and publish an endpoint
Calculator calculator = new Calculator();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/calculator", calculator);
}
}
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>fi.eis.applications</groupId>
<artifactId>ws-calculator</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.5</target>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
That you can compile with mvn clean compile and then run with java Calculator on the target/classes/example folder. It will start up a web service on port 8080, which you can test with url http://localhost:8080/calculator?wsdl on your browser.

Resources