The import javax.xml.rpc.encoding cannot be resolved - java

I'm trying to run this code
http://www.nactem.ac.uk/software/termine/webservice/termine_soap_client.java
and I get the following error: The import javax.xml.rpc.encoding cannot be resolved.
I'm using Oracle Java 7. What do I need to add to get this resolved?
Thanks,
Ivelina

Add the relevant jars to your build path :
axis.jar, jaxrpc.jar and xerces.jar.

In case someone is using Maven, these are the only dependencies I needed in order to make wsdl2java goal work:
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>

Related

NoClassDefFoundError with EncryptedDocumentException

I am building a java program that opens an excel document. While in the IDE everything works, when i execute the code from the built jar everything falls apart and it gives me the following exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/EncryptedDocumentException
at com.exceltogpx.Main.main(Main.java:19)
It stops the execution at the import of the class
import org.apache.poi.EncryptedDocumentException;
and it's driving me crazy
it's a maven build, dependencies imports following
<dependencies>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
I think something may be wrong with either the classpath or the way I create the build with maven, but it seems I can't find the issue itself
Found out the answer to the question
I am a newbie maven user and I had never worked with pom a before. Be sure to specify a goal for your project and to specify that it will be a "jar-with-dependencies"
Here's the guide I used to fix my pom file (I followed the second part of the guide, the one that uses Apache maven assembly plugin)
Other suggestions for others using maven for the first time. If you used any external libraries so you have dependencies, in the log you should see the download of those libs. Otherwise it means you probably did something wrong with the pom... The guide I linked works pretty good and explains what the main tags do.

java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException

I have created a Web Service using Spring. It works fine when running it on my embedded tomcat server. However when I package it as a JAR file and run it with java -jar command, I am receiving this exception.
My service sends a simple soap request and the server response is:
"exception": "java.lang.NoClassDefFoundError",
"message": "javax/xml/soap/SOAPException",
That's the response I get in Postman.
Any ideas where I can look for the problem.
Adding the following in pom file solved the issue
<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
JavaSE 8 includes package java.xml.soap.
JavaSE 9 moved package javax.xml.soap to the module java.xml.ws.
Modules shared with JEE (like java.xml.ws) are included in JavaSE 9, but are
- deprecated for removal from a future version of JavaSE, and
- not on the default module path.
A quick workaround is to either
- run the jar with JRE 8: $MY_JRE8_HOME/bin/java -jar my.jar, or
- add a module for JRE 9: java --add-modules java.xml.ws -jar my.jar
Longer term, JavaSE projects that use modules like java.xml.ws must explicitly include the module like other libraries.
See https://stackoverflow.com/a/46359097
See JDK 9 Migration Guide: Modules Shared with JEE Not Resolved by Default
(Reproduced NoClassDefError and workarounds with zipped SOAP web service project at https://spring.io/guides/gs/producing-web-service/)
Yes, In Java 11 java.xml.soap was completely removed.
java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException can be removed by adding the
following dependency.
<dependency>
<groupId>jakarta.xml.soap</groupId>
<artifactId>jakarta.xml.soap-api</artifactId>
<version>2.0.0-RC3</version>
</dependency>
But later, you will encounter , javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found.
This can be solved by adding the following dependency.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
Hope, it helps!
Add the following dependencies, it should work then
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.6</version>
</dependency>
Refer the following links for a running piece of code (SpringBootSOAPWS + Java10)
Github- SpringBoot Soap Server
Github- SpringBoot Soap Client
I imported this one to sort out the issue: https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api/1.4.0
Adding this dependency will solve the issue.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
The JAX-WS dependency library “jaxws-api.jar” is missing.
Try:
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' - for gradle or:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
I know this is already closed for all above people but I am still facing this issue even though I have added
jakarta-xml.soap-api and saaj jars in classpath.
Anything that I am missing to make it work.Tried out using javax-.xml-soap-api as well instead of jakarta jar but still same error.Somehow its not able to identify the jar.

Using maven dependency "util-compress" in Java

I want to unzip a folder in Java using "util-compress" maven dependency . After adding the dependency to the pom, how to use it in java program. Can someone explain please ? I'm new to this field . Any proper tutorial guidance is welcomed.
Thanks in advance.
https://mvnrepository.com/artifact/io.vertx/mod-unzip/1.0.0-final
Java comes with “java.util.zip” library to perform data compression in ZIp format. The overall concept is quite straightforward.
Read file with “FileInputStream”Add the file name to “ZipEntry” and output it to “ZipOutputStream“
Below link may help to u
https://www.mkyong.com/java/how-to-compress-files-in-zip-format/
I hope you are using below dependency.
<dependency> <groupId>com.madgag</groupId> <artifactId>util-compress</artifactId> <version>1.33</version> </dependency>
This dependency internally deals with below dependencies
<dependencies>
<dependency>
<groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.4</version>
<scope>test</scope>
</dependency>
<dependency> <groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.0</version>
</dependency>
</dependencies/>
So you can find examples in below link
https://commons.apache.org/proper/commons-compress/examples.html

NoClassDefFoundError: Mockito Bytebuddy

I recently added Mockito to a maven project on eclipse, by adding the external jar "mockito-core-2.0.53-beta.jar", and upon attempting to create my first mock object (Line two in the function)
And upon running it, the console prints out the first line, then throws this error:
It seems like previously there was a similar issue, but it was supposedly fixed internally. https://github.com/raphw/byte-buddy/issues/99
What is going wrong here?
You simply forgot to add the dependencies to your project which are according to the pom file:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.3.16</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>runtime</scope>
</dependency>
In other words you need to add byte-buddy 1.3.16 and objenesis 2.1 to your project too.
More details here
Instead adding
mockito-core
better option will to add
mockito-all
Refer to this link https://mvnrepository.com/artifact/org.mockito/mockito-all/2.0.2-beta
There is a post that explain the problem pretty well, you can find it here:
https://solidsoft.wordpress.com/2012/09/11/beyond-the-mockito-refcard-part-3-mockito-core-vs-mockito-all-in-mavengradle-based-projects/
If you are not using gradle or maven and you are just using mockit-core you should add these dependencies:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.7.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.4</version>
<scope>runtime</scope>
</dependency>
java.lang.NoClassDefFoundError
This indicates that in your .jar (org.mockito), you don't have that class.
This usually occurs when you have more than one .jar (with a different version) in your classpath. You could check that.

Writing Maven Dependency for javax.persistence

Can someone help me write the dependency for javax.persistence. I have googled it but nothing worked.
I bumped into this page that gives some details on how to write the dependency, but yet i am unable to write it. Can someone help me out?
This is the one for javax.persistence:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
and this is for the whole Java EE 6 stack:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Edit
Note that I specified a provided scope here, which means that your dependency is available at compile- and test-time, but will not be packaged into your artifacts. This is usually needed if you want to deploy your artifacts in an application server, since they provide their own implementation of the api.
And add this dependency in your pom.xml:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
That "Coping with Sun JARs" page might be a little outdated, this JAR is available in the Maven Central Repository
Updated link:
https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2 is here.
and the maven dependency is as below:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
For the latest versions javax.persistance is not working instead of that we can use jakarta.persistence to create an entity or resolve the error Cannot resolve symbol 'Entity'. For that need to add the dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.6.Final</version>
<type>pom</type>
</dependency>

Categories

Resources