Maven dependency for javax.ejb.jar into .m2 directory - java

I cant find javax.ejb.jar in my .m2 dirctory, I need this jar for import javax.ejb.Schedule; , here is my pom file entry.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
I am not sure if it will work or not, or its a right way to do things. Can some one please help to make a change in the POM file so that it downloads javax.ejb.jar into the .m2 directory.
Updated
by .m2 I mean in the repository directory in the correct folder
hierarchy (What ever it is).
Why? We have multiple sub projects (In eclipse workspace), In order to resolve dependency we use M2_REPO/path/to/the/required_library_file.jar, Now theses projects are part of code bases, Every developer download the source code, Maven download all jar to the repository directory(of the developer using any OS/Platform). This relative path from M2_REPO helps developer to have consitenat code (for eclipse project). Otherwise everyone will be adding their own path.
If it still doesn't make sense, here is what I want, Please give me an entry for POM file which download the javax.ejb.jar file into .m2 directory what ever the sub path is.
I have to include this jar in every project manually (And every developer needs to them as well from what ever directory have glassfish (C: , D:, E:, or /home/glassfish/modules/)
D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar
where rest of the jars in each project are included as M2_REPO/path/to/jar which makes less no changes in the code base to commit.
M2_REPO/javax/ejb/ejb-api/3.0/ejb-api-3.0.jar
M2_REPO/javax/enterprise/cdi-api/1.0-SP1/cdi-api-1.0-SP1.jar
M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar
etc etc

I think I hear what you mean now :)
The maven dependency you specify
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
which you have in .m2/repository/javax/ueb/ejb-api/3.0/ejb-api-3.0.jar does not contain the class/interface javax.ejb.Schedule.
But you found the jar-file in your glassfish server, which does contain javax.ejb.Scheduleand its name is D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar and now you ask how to get that into the pom?
Well, the Java EE APIs and their official jars in maven are somewhat a study in disharmony.
If you run a search on maven central you will find multiple jars containing exactly that class. You will probably note that all appserver vendors provide their own edition of every aspect of every api in every version.
You should be able to find a jar with the javax.ejb module from glassfish in version 3.1.2
http://search.maven.org/#artifactdetails|org.glassfish|javax.ejb|3.1.2|jar
in which case the dependency would be
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>

I found another artifactId here, though maven has your version too.
A (very) weird maven caching problem? Then it might work tomorrow.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
Though this is a new version, for compilation it should do.

You may need to provide the repository location in your pom.xml file or in .m2/settings.xml file for the required jar to get downloaded into .m2 directory.

The dependency is declared as provided what means that the container will provide it.
What container are you using? I think Tomcat/Jetty won't provide that jar as it seems so Java EE. In that case just change the scope to compile.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
More info about dependency scopes:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

Related

ECLIPSE ERROR: The package javax.xml is accessible from more than one module: , java.xml [duplicate]

When referencing simple .jar files, Eclipse shows an error stating:
The package java.awt is accessible from more than one module: <unnamed>, java.desktop
This happens for instance when javax.awt or javax.swing is included in the .jar files.
The simplest example would be the following:
package test;
import javax.swing.JDialog;
public class Test {
public static void main(String[] args) {
new JDialog();
}
}
Adding a .jar file to the classpath with only the folder structure javax/swing (no files needed) will cause the error to appear. I'm using JDK 10/12 (neither works). Setting the compiler compliance to 1.8 makes the whole thing work again.
On another machine with Eclipse 2018-09 this works with compiler compliance set to 10.
I'm on Eclipse 2019-03, on a (for testing purposes) freshly installed Eclipse 2018-09 it works fine. Why?
Edit June/2020 (Solution)
As the answers correctly stated, this is a restriction built into Java ages ago and only recently was forced upon us. I came into contact with it while migrating a big project with dozens of dependencies to Maven. There were libraries from around the year 2000! There were 'meta libraries' which consisted of several libraries packaged together.
So there was no other way than to identify what was still needed (into the trash with the rest!), update libraries which violate the rules or find replacements for them. This took me many, many hours.
In the end it worked out and we've got a nice Maven project to work with.
This is caused by
a JAR on the Classpath that contains the package java.awt that also exists in the system library but the
JRE System Library is on the Modulepath
In the Java Platform Module System (JPMS) it is not allowed to use the same package in more than one module. If the Modulepath and the Classpath is used, everything on the Classpath is handled as the <unnamed> module (in your case the package java.awt exists in the system module java.desktop and also via the JAR on the Classpath in the module <unnamed>).
Since the JRE System Library cannot be moved from the Modulepath to the Classpath (see this answer by Stephan Herrmann for details), you only have the following options:
Set the compiler compliance to 1.8 (as you already mentioned)
Rebuilt the JAR to avoid Java system library package names inside the JAR (if reflection is used, additional code changes may be necessary):
If you have the source code, change the package names (e.g. change the package and subpackae java to java_util and javax to javax_util) and recreate the JAR
If you have only the .class files you have to decompile the .class files first
Since I'll bet lots of people will be running into this problem with modular Java, I'll help and give the real answer.
This error happens when
you have a dependency in your project
that contains code
using packages
that are also in the modules
being referenced by your project
If your project has set the source compatibility to something like Java 12, it will start enforcing the rule, that has been there all along in Java:
"Don't use packages that belong to the JDK in your own code."
Unfortunately, lots of developers and vendors have done that over the years. Can't do that anymore.
If you set your project to Java 12 source compatibility, Eclipse adds the JDK modules which include everything "java.*" and "javax.*" and even "jdk.*", "org.w3c.*". These packages may be in use by your dependencies or their transitive dependencies.
How to fix
You need to:
look at which package its complaining about
and expand the "Projects and External Dependencies" node in the Package Explorer.
Find out which dependency is using that package.
Then you can simply exclude that dependency from your project.
Or you could get the source of that dependency, if available, and rebuild the jar with changed packages. Otherwise you have to remove that dependency and find a replacement for that technology. Pain huh?
If its a transitive dependency you can often just exclude it. Here is an example of that for Gradle based projects.
GradleConfig.xml:
configurations {
all*.exclude group: 'xml-apis'
}
In my case, it was because I included a dependency (Apache Tika) in the POM.xml file.
I had to force the exclusion of the module that contained the classes with errors while imported at that dependency:
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.24.1</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
It worked for me that way.
I found a simple solution to troubleshoot this in Eclipse. Hit Ctrl + Shift + T in Eclipse to open the Open Type prompt. Then type the name of the package that is causing the issue. For me, it was org.w3c.dom. Now the search results will show all the locations from where this package is being loaded. Remove every JAR from the classpath that comes in the result other than the JDK 11 library.
My project being a legacy one, I had to remove a lot of JARs from the build path. Also, my project does not use Maven. So removing the JARs was a fairly straightforward step. The steps might vary for other build tools like ANT, Maven, Gradle, etc. I have just explained the troubleshooting steps above.
See also: The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml where I answered:
Disappointingly I don't see any compiler flags to show what jar the problem is with
Even -Xlint:module doesn't seem to show up anything useful and eclipse doesn't shed any light on the issue
Instead to find where java.awt comes from I've been using this script:
mvn dependency:copy-dependencies -DincludeScope=test -DoutputDirectory=deps
for i in deps/*.jar; do if unzip -l $i| grep -q java.awt; then echo $i; fi ; done
Strictly you don't have to specify the scope test as that's the default but I've included it as you might want to use compile instead
I think my flavour of the problem might be useful.
I got this error for classes under javax.xml.stream, by old Maven projects that depend on artifacts like xml-apis, stax-api, or geronimo-stax-api.
Technically, the problem is what others have already said: those artifacts expose the javax.xml.* package without any awareness of Java modules (they were invented later), so the package is automatically assigned to the unnamed module, which conflicts with the same package being included in the JDK's most recent versions, where the package has its own module name, and therefore the same package results in two different modules, which is forbidden.
That said, the practical solution is essentially to work with Maven exclusions to remove those dependencies from your project and let it use the JDK version instead (or, of course, remove them as direct dependencies, if that's your case). Use the equivalent if you're working with another build system.
In theory, the more recent flavours of these packages offered by the JDK might be non backward-compatible, in practice, I doubt such JSR specifications changed much over the years and so far, I haven't seen any issue with their replacement.
Since this is ranks quite high on Google I'm going to drop this here in case it's helpful for someone.
I've found some interesting behaviour with Java 11 and the xmlbeans library. The xmlbeans library is a transitive dependency of Apache POI, a very popular library for working with Microsoft Office documents, it is used to handle the internal XML structures of the newer Office formats. I've tested it with Apache POI 3.9 and it works perfectly fine, despite the error shown by Eclipse. So, I guess in Java 11 this rule it's not fully enforced.
For Apache POI version 5.0.0 using Maven, in the pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
Fixed: "The package javax.xml.parsers is accessible from more than one module"
I met a similar issue with the eclipse IDE while upgrading JDK from 1.8 to 11, "The package org.w3c.dom is accessible from more than one module: , java.xml". upgrading eclipse from 2019 to 2021 and setting system JDK home to 11 does not solve it. I don't think it's caused by "org.w3c.dom" existing in different jars of the classpath,dut to "Order and Export" should ordered the search sequence.
After several hours of searching and investigating, this issue is fixed by setting the Java Compiler - Compiler compliance level to 1.8(default is 11).
You can do what other people suggest which is to exclude xml-apis which worked fine with me, but if your are using and an old jaxb-api replace them with jakarta.xml.bind-api:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
and of course upgrade your jaxb-impl to match the same api:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
</dependency>
Steps below helped me,
Right click Eclipse project > Properties > Java Build Path
In Libraries tab, remove all the external jar files under Modulepath and add them under Classpath (you can just select all the jars and drag them under Classpath)
Click Apply and Close
Hope it help you too.
Wow, this was a tough one!
Some helpful tips (a summary of my journey through this maze):
This started when I migrated from Java 1.8 to 11.0.11
Right out of the gate this caused problems. I needed to change the syntax for how to specify the Java version for the maven build plug in as shown below:
Before
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
After
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
After that, everything compiled at a command prompt. However, when opening the project in Eclipse, I got a bunch of errors as shown in the next section.
Getting "<class> cannot be resolved to a type" errors
When I got errors in Eclipse and not at the command line I immediately started looking at configuration settings in Eclipse to no avail. After some googling I came to this post. The post at https://www.eclipse.org/forums/index.php/t/1110036/ was also very helpful.
Finding what resources were the problem
The answer to this post by #Anu suggesting using <shift><ctrl>T to bring up the type search window was very helpful using this I was able to see what resources were causing the problem (i.e. any resource that is also included in the JDK, in my case it was the ErrorHandler in the xml-apis jar). Type the name of one of the resources giving a "cannot be resolved to type" to see the name of the jar file, in my case the jar is xml-apis-1.4.01.jar.
All of this is shown in the screen shot below (click on the image to get a cleaner view).
Finding the Dependency that contains the offending jar
We can now use the information from https://www.eclipse.org/forums/index.php/t/1110036/ to find the dependency in our pom.xml file that contains the offending resource.
Open the pom.xml file in Eclipse and select the "Dependency Hierarchy". In the filter type the name of the jar file we found in the previous step (in my case it was xml-apis).
This will pull up the dependencies creating the problem. A screen shot of the Dependencies Hierarchy filtered for "xml-apis". From this we can see the offending dependencies in our pom.xml file are xercesImpl and xlsx-streamer.
Solving the problem
We can now add exclusions to these dependencies that will resolve the problem as shown below.
<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
And this fixes the current problem.
For anyone who suffer with this problem when refering to the org.w3c or javax.xml imports, be careful with this one module dependency: xml-apis it conflicts with java default xml classes.
One big project who references it is called DynamicJasper
Here's the image of my app
It seems to me the real problem here is that the JDK (in my case, JDK-19) has org.w3c.dom embedded in it, so everything else that was doing the correct thing by referencing libraries from external-lib, rather than embedding is now broken. I removed xml-apis and xerces, but it still complains about org.w3c.dom. the only place it is referenced in my project is the JDK.
Removing jar files, (xml-apis.jar and xerces_2_5_0.jar) Does not fix the issue. I cannot remove batik, project depends upon it.
I have a standard Java build, no maven. There is no decompiling/removing a valid reference that can be done with 3rd party software like batik.
Any suggestions on how to remove the embedded org.w3c.dom from JDK-19 so I can build?
I had this problem with the Stanford Core NLP package. As mentioned above adding an exclusion in the pom.xml solved the problem:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>4.5.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
First of all, make sure your pom is actually correct by running
mvn install
if that works, and eclipse still complains look at build path and find the library it is holding onto that is not in your pom.
Sometimes I just
rm .classpath
rm -rf .settings
rm -rf project
mvn eclipse:clean eclipse:eclipse

Problem with javax.xml in OpenJDK 11 and Eclipse [duplicate]

When referencing simple .jar files, Eclipse shows an error stating:
The package java.awt is accessible from more than one module: <unnamed>, java.desktop
This happens for instance when javax.awt or javax.swing is included in the .jar files.
The simplest example would be the following:
package test;
import javax.swing.JDialog;
public class Test {
public static void main(String[] args) {
new JDialog();
}
}
Adding a .jar file to the classpath with only the folder structure javax/swing (no files needed) will cause the error to appear. I'm using JDK 10/12 (neither works). Setting the compiler compliance to 1.8 makes the whole thing work again.
On another machine with Eclipse 2018-09 this works with compiler compliance set to 10.
I'm on Eclipse 2019-03, on a (for testing purposes) freshly installed Eclipse 2018-09 it works fine. Why?
Edit June/2020 (Solution)
As the answers correctly stated, this is a restriction built into Java ages ago and only recently was forced upon us. I came into contact with it while migrating a big project with dozens of dependencies to Maven. There were libraries from around the year 2000! There were 'meta libraries' which consisted of several libraries packaged together.
So there was no other way than to identify what was still needed (into the trash with the rest!), update libraries which violate the rules or find replacements for them. This took me many, many hours.
In the end it worked out and we've got a nice Maven project to work with.
This is caused by
a JAR on the Classpath that contains the package java.awt that also exists in the system library but the
JRE System Library is on the Modulepath
In the Java Platform Module System (JPMS) it is not allowed to use the same package in more than one module. If the Modulepath and the Classpath is used, everything on the Classpath is handled as the <unnamed> module (in your case the package java.awt exists in the system module java.desktop and also via the JAR on the Classpath in the module <unnamed>).
Since the JRE System Library cannot be moved from the Modulepath to the Classpath (see this answer by Stephan Herrmann for details), you only have the following options:
Set the compiler compliance to 1.8 (as you already mentioned)
Rebuilt the JAR to avoid Java system library package names inside the JAR (if reflection is used, additional code changes may be necessary):
If you have the source code, change the package names (e.g. change the package and subpackae java to java_util and javax to javax_util) and recreate the JAR
If you have only the .class files you have to decompile the .class files first
Since I'll bet lots of people will be running into this problem with modular Java, I'll help and give the real answer.
This error happens when
you have a dependency in your project
that contains code
using packages
that are also in the modules
being referenced by your project
If your project has set the source compatibility to something like Java 12, it will start enforcing the rule, that has been there all along in Java:
"Don't use packages that belong to the JDK in your own code."
Unfortunately, lots of developers and vendors have done that over the years. Can't do that anymore.
If you set your project to Java 12 source compatibility, Eclipse adds the JDK modules which include everything "java.*" and "javax.*" and even "jdk.*", "org.w3c.*". These packages may be in use by your dependencies or their transitive dependencies.
How to fix
You need to:
look at which package its complaining about
and expand the "Projects and External Dependencies" node in the Package Explorer.
Find out which dependency is using that package.
Then you can simply exclude that dependency from your project.
Or you could get the source of that dependency, if available, and rebuild the jar with changed packages. Otherwise you have to remove that dependency and find a replacement for that technology. Pain huh?
If its a transitive dependency you can often just exclude it. Here is an example of that for Gradle based projects.
GradleConfig.xml:
configurations {
all*.exclude group: 'xml-apis'
}
In my case, it was because I included a dependency (Apache Tika) in the POM.xml file.
I had to force the exclusion of the module that contained the classes with errors while imported at that dependency:
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.24.1</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
It worked for me that way.
I found a simple solution to troubleshoot this in Eclipse. Hit Ctrl + Shift + T in Eclipse to open the Open Type prompt. Then type the name of the package that is causing the issue. For me, it was org.w3c.dom. Now the search results will show all the locations from where this package is being loaded. Remove every JAR from the classpath that comes in the result other than the JDK 11 library.
My project being a legacy one, I had to remove a lot of JARs from the build path. Also, my project does not use Maven. So removing the JARs was a fairly straightforward step. The steps might vary for other build tools like ANT, Maven, Gradle, etc. I have just explained the troubleshooting steps above.
See also: The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml where I answered:
Disappointingly I don't see any compiler flags to show what jar the problem is with
Even -Xlint:module doesn't seem to show up anything useful and eclipse doesn't shed any light on the issue
Instead to find where java.awt comes from I've been using this script:
mvn dependency:copy-dependencies -DincludeScope=test -DoutputDirectory=deps
for i in deps/*.jar; do if unzip -l $i| grep -q java.awt; then echo $i; fi ; done
Strictly you don't have to specify the scope test as that's the default but I've included it as you might want to use compile instead
I think my flavour of the problem might be useful.
I got this error for classes under javax.xml.stream, by old Maven projects that depend on artifacts like xml-apis, stax-api, or geronimo-stax-api.
Technically, the problem is what others have already said: those artifacts expose the javax.xml.* package without any awareness of Java modules (they were invented later), so the package is automatically assigned to the unnamed module, which conflicts with the same package being included in the JDK's most recent versions, where the package has its own module name, and therefore the same package results in two different modules, which is forbidden.
That said, the practical solution is essentially to work with Maven exclusions to remove those dependencies from your project and let it use the JDK version instead (or, of course, remove them as direct dependencies, if that's your case). Use the equivalent if you're working with another build system.
In theory, the more recent flavours of these packages offered by the JDK might be non backward-compatible, in practice, I doubt such JSR specifications changed much over the years and so far, I haven't seen any issue with their replacement.
Since this is ranks quite high on Google I'm going to drop this here in case it's helpful for someone.
I've found some interesting behaviour with Java 11 and the xmlbeans library. The xmlbeans library is a transitive dependency of Apache POI, a very popular library for working with Microsoft Office documents, it is used to handle the internal XML structures of the newer Office formats. I've tested it with Apache POI 3.9 and it works perfectly fine, despite the error shown by Eclipse. So, I guess in Java 11 this rule it's not fully enforced.
For Apache POI version 5.0.0 using Maven, in the pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
Fixed: "The package javax.xml.parsers is accessible from more than one module"
I met a similar issue with the eclipse IDE while upgrading JDK from 1.8 to 11, "The package org.w3c.dom is accessible from more than one module: , java.xml". upgrading eclipse from 2019 to 2021 and setting system JDK home to 11 does not solve it. I don't think it's caused by "org.w3c.dom" existing in different jars of the classpath,dut to "Order and Export" should ordered the search sequence.
After several hours of searching and investigating, this issue is fixed by setting the Java Compiler - Compiler compliance level to 1.8(default is 11).
You can do what other people suggest which is to exclude xml-apis which worked fine with me, but if your are using and an old jaxb-api replace them with jakarta.xml.bind-api:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
and of course upgrade your jaxb-impl to match the same api:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
</dependency>
Steps below helped me,
Right click Eclipse project > Properties > Java Build Path
In Libraries tab, remove all the external jar files under Modulepath and add them under Classpath (you can just select all the jars and drag them under Classpath)
Click Apply and Close
Hope it help you too.
Wow, this was a tough one!
Some helpful tips (a summary of my journey through this maze):
This started when I migrated from Java 1.8 to 11.0.11
Right out of the gate this caused problems. I needed to change the syntax for how to specify the Java version for the maven build plug in as shown below:
Before
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
After
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
After that, everything compiled at a command prompt. However, when opening the project in Eclipse, I got a bunch of errors as shown in the next section.
Getting "<class> cannot be resolved to a type" errors
When I got errors in Eclipse and not at the command line I immediately started looking at configuration settings in Eclipse to no avail. After some googling I came to this post. The post at https://www.eclipse.org/forums/index.php/t/1110036/ was also very helpful.
Finding what resources were the problem
The answer to this post by #Anu suggesting using <shift><ctrl>T to bring up the type search window was very helpful using this I was able to see what resources were causing the problem (i.e. any resource that is also included in the JDK, in my case it was the ErrorHandler in the xml-apis jar). Type the name of one of the resources giving a "cannot be resolved to type" to see the name of the jar file, in my case the jar is xml-apis-1.4.01.jar.
All of this is shown in the screen shot below (click on the image to get a cleaner view).
Finding the Dependency that contains the offending jar
We can now use the information from https://www.eclipse.org/forums/index.php/t/1110036/ to find the dependency in our pom.xml file that contains the offending resource.
Open the pom.xml file in Eclipse and select the "Dependency Hierarchy". In the filter type the name of the jar file we found in the previous step (in my case it was xml-apis).
This will pull up the dependencies creating the problem. A screen shot of the Dependencies Hierarchy filtered for "xml-apis". From this we can see the offending dependencies in our pom.xml file are xercesImpl and xlsx-streamer.
Solving the problem
We can now add exclusions to these dependencies that will resolve the problem as shown below.
<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
And this fixes the current problem.
For anyone who suffer with this problem when refering to the org.w3c or javax.xml imports, be careful with this one module dependency: xml-apis it conflicts with java default xml classes.
One big project who references it is called DynamicJasper
Here's the image of my app
It seems to me the real problem here is that the JDK (in my case, JDK-19) has org.w3c.dom embedded in it, so everything else that was doing the correct thing by referencing libraries from external-lib, rather than embedding is now broken. I removed xml-apis and xerces, but it still complains about org.w3c.dom. the only place it is referenced in my project is the JDK.
Removing jar files, (xml-apis.jar and xerces_2_5_0.jar) Does not fix the issue. I cannot remove batik, project depends upon it.
I have a standard Java build, no maven. There is no decompiling/removing a valid reference that can be done with 3rd party software like batik.
Any suggestions on how to remove the embedded org.w3c.dom from JDK-19 so I can build?
I had this problem with the Stanford Core NLP package. As mentioned above adding an exclusion in the pom.xml solved the problem:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>4.5.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
First of all, make sure your pom is actually correct by running
mvn install
if that works, and eclipse still complains look at build path and find the library it is holding onto that is not in your pom.
Sometimes I just
rm .classpath
rm -rf .settings
rm -rf project
mvn eclipse:clean eclipse:eclipse

About dependency in maven

I have some code, its depend org.apache.batik.*. Many jars are necessary.I tried import this im my pom.xml.
<dependency>
<groupId>org.apache.batik</groupId>
<artifactId>org.apache.batik</artifactId>
<version>1.6.0-20070705</version>
</dependency>
So, That I found all jars I need have entered in project libraries.Following this.
Inside this jar that has a lib folder, That all jars I need are in there.
The problem is my code seems can not find some jar they need.
I can't sure if cause is the jar that I imported has a lib folder, and I found other maven jar's structure doesn't like this.
So thank if you can help me!
EDIT 1
I imported this successful, this dependency's type is 'pom', so I think my
code should can find those dependency they need, but in fact, it didn't work. I don't know why.
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik</artifactId>
<version>1.10</version>
<type>pom</type>
</dependency>
The artifact you are using is not directly usable in maven.
If you can use a more recent version (1.9, 1.10) of batik you can try this:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.9</version>
<type>pom</type>
</dependency>
If not search on https://mvnrepository.com/artifact/batik
In the latter case it seems you need to add each dependency one by one
Define dependencies for all jars you use in your source code. This usually means all jars from which you import at least one class in your source code.
Run clean package with Maven.
If you have errors, check if dependencies are missing.
If you get stuck, try a new question on Stackoverflow.

Platform-Specific Maven Dependencies

Here is the Maven Repository that I'm trying to use. A snippet from my pom.xml:
<dependency>
<groupId>edu.wpi.cscore.java</groupId>
<artifactId>cscore</artifactId>
<version>1.0.2</version>
</dependency>
When run, it grabs the cscore-1.0.2.pom file just fine, but then it goes searching for cscore-1.0.2.jar which doesn't exist - if you look in the repo, each JAR is platform-specific, and is named accordingly (e.g. cscore-1.0.2-linux.jar).
I've tried:
<dependency>
<groupId>edu.wpi.cscore.java</groupId>
<artifactId>cscore</artifactId>
<version>1.0.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>edu.wpi.cscore.java</groupId>
<artifactId>cscore</artifactId>
<version>1.0.2-linux</version>
<type>jar</type>
</dependency>
It gets the cscore-1.0.2.pom fine but then it goes looking in the 1.0.2-linux/ directory for the JAR, which simply doesn't exist. Is there a way to tell Maven that the JAR file it is looking for will be named something else? Or is this simply not a valid Maven repository?
Thanks!
There should be one [and only one] artifact addressable via a coordinate [group-id, artifact-id, version].
These platform-specific artifacts were likely pushed into the repository manually and can't be referred to individually via the expected maven dependency POM element.
The easiest short-term solution would be to manually extract the dependency/dependencies and install each one with its own unique maven coordinates in your local repository. Then refer to that artifact using its local coordinates from the element in your project's POM.
Unfortunately that makes it impossible for maven to automatically detect and download a newer version of the artifact in the remote repo.
The long-term solution would be to petition the keepers of the external dependency's project, asking them to re-consider how they identify and install their platform-specific artifacts.

crystal report jars for maven

I have built a non-maven project to display crystal reports with all necessary jars imported to the lib folder.
But, when I try to find the dependencies to add the same jars into my pom.xml for a maven project, I was not able to look it up online.
How can I find the crystal report dependencies for a maven project ? How to determine groupId and artifact for the crystal jar?
Below is the snapshot of jars I am looking for. Please suggest.
I tried looking into this link in the SCN but couldn't find much details.
You can specify your local jars as maven dependency using "system" scope
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${lib.path}/some_1.0.jar</systemPath>
</dependency>
define 'lib.path' in properties
Below are two solutions : One is pointing to local jars with system scope and the other is deploying the jars into m2. I felt the second solution more reliable.
First solution: I followed the link here ; but couldn't get it entirey working. So changed the scope to system and pointed to the local jars and was able to finally access the classes.
Please see below for the pom.xml
<dependency>
<groupId>com.sap.crystalReports</groupId>
<artifactId>CrystalCommon2</artifactId>
<version>1.0.0-RT</version>
<scope>system</scope>
<systemPath>${lib.path}/CrystalCommon2.jar</systemPath>
</dependency>
.....
Second solution is, from the comment in the question above, I came up with the idea of deploying all the crystal jars, one by one, which I downloaded on my local into my local m2 repository.
mvn deploy:deploy-file -DgroupId=com.crystalruntime.sdk -DartifactId=JDBInterface
-Dversion=1.5 -Dfile= point-to-the-jar-location-on your-local\JDBInterface.jar
-Dpackaging=jar -Durl=file://point-to-local-m2 repository
groupId, artifactId,version- can be modified, but it is good to keep consistency and readability, with the names chosen.
Run this command on any/all the jars that you want to install into m2. I then updated the project and did another clean build and was able to successfully run then application.
Also, I did remove the system scope from the pom.xml
<scope>system</scope>
<systemPath>${lib.path}/JDBInterface.jar</systemPath>
and modified it according to :
<dependency>
<groupId>com.crystalruntime.sdk</groupId>
<artifactId>JDBInterface</artifactId>
<version>1.5</version>
</dependency>
This made more sense to me, to use in the maven project.
This is the link I followed for reference.

Categories