Swagger generated file uses mysterious import - java

I just generated code using Swagger.io with the OpenApi 3.0 spec. The code it produces doesn't compile. Once class has this seemingly crucial import:
import springfox.documentation.oas.annotations.EnableOpenApi;
But I get this error: package springfox.documentation.oas.annotations does not exist
I can't figure out what I need to add to my pom.xml file to make the import work. The maven repo at https://mvnrepository.com/ doesn't let me search for a specific class, which makes no sense.

I hope you have missed swagger oas dependency so you are getting package not exist error. Swagger oas available in the below maven repository.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-oas</artifactId>
<version>3.0.0</version>
</dependency>

Related

How to exclude packages in Maven that uses the same attribute?

So, I am working with webservices using SOAP and Maven. This error - I think - is a warning instead because it let me run the application and the service just fine for now. Whenever I call any other package inside this module class it turns red. If I don't add packages the error disappears but I need jasperreports (strange, as the involved package got nothing to do with this)
I've followed this: Module reads package from both
Using the solution "implementation and excludes" does nothing. Probably because it is Gradle but I had to try restricting the xml transform using the suggested message.
I also tried Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base' this.
I followed this guide as well. https://maven.apache.org/guides/mini/guide-multiple-modules.html
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<optional>true</optional> <!-- value will be true or false only -->
</dependency>
Making those package use optional does not help either.
Important note, using a different package I want to use the ERROR WILL CHANGE. I removed and added some so you can withness it. Check these:
In short, a Web Service dependency using some of the declared in the client as well. As mentioned, I went one by one until I found it.
Also, updating javax.xml version of the dependency was a necessary step in order to solve the problem.

Can not import #ApiParam or #ApiModelProperty annotation eventough Swagger is added as a Maven dependency

I am working on a project where we document our backend's API with Swagger. I would like to use annotation based configuration for Swagger. For my controller classes using #Tag, #Operation and #ApiResponses works just fine and they can be imported with the following statements:
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
However if I try to add either #ApiParam or #ApiModel to my code, I am unable to import them in any way.
In my POM.xml I added Swagger as the following dependency:
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-annotations -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.11</version>
</dependency>
What is it that I am missing here? I tried following this Baeldung article and example code, however I could not get it to work. Thanks for the help!
The "problem" was that Springdoc is used and originally I made the assumption that Springfox or a plain Swagger 2 dependency is used, as it was not removed from the codebase.
To fix the issue, we just simply need to add the right dependency and use the new annotations, which are mapped to the old ones like explained here.

The type com.google.protobuf.GeneratedMessageV3$Builder cannot be resolved. It is indirectly referenced from required .class files

I have been doing my project and all the sudden eclipse started to give this error saying
The type com.google.protobuf.GeneratedMessageV3$Builder cannot be resolved.
It is indirectly referenced from required .class files where we declare the package. I have tried adding com.google.protobuf-2.4.0.jar to build path but it did not work. Please help and here's the screenshot.
com.mysql.cj.x.protobuf.MysqlxSql.StmtExecute is not on the classpath so remove this import
If you are expecting Protobuf generated files to be available, then ensure that you have added the Protobuf library to your project.
Gradle example:
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: googleProtobufVersion
Maven example:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${googleProtobufVersion}</version>
</dependency>
Not sure if this helps at such a later date. But i also faced something similar.
I found that I imported this by mistake
import com.mysql.cj.x.protobuf.MysqlxDatatypes.Array;
After removing this line, it works fine.
In your case you need to remove the import
com.mysql.cj.x.protobuf.MysqlxSql.StmtExecute
Replace it with the relevant import.
This is due to the missing dependency of gRPC protobuf. Add this dependency to your pom.xml and this should solve your problem.
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.16.1</version>
</dependency>
Lastly, do maven -> project update

CanĀ“t import class from updated org.json package

I have tried to use the org.json.XML class in my Android project. This class isn't provided by the core library's so I thought the only thing I had to do is use the updated org.json package with gradle. But I'm getting the following error when I'm trying to compile:
error: cannot find symbol class XML
Here my MainActivity import:
...
import org.json.XML;
...
And my build.gradle file:
dependencies {
...
compile 'org.json:json:20160212'
...
}
I know that Android Studio is compiling the jar and that is working, but I want to know a way to get it working using the maven dependencies.
I recommend you to use Jackson library to parse XML files.
Or if you want to keep doing it by yourself you can try using javax.XML
http://developer.android.com/reference/javax/xml/package-summary.html
instead of org.json.xml
Hope it helps!
This is maven dependency for org.json.XML
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
Source: http://mvnrepository.com/artifact/org.json/json/20160212

NoSuchMethod error getting a gdata service

I get the following error:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
at com.google.gdata.client.Service.<clinit>(Service.java:558)
at testproject.TestProject.run(TestProject.java:22)
at testproject.TestProject.main(TestProject.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
This comes from the following code:
package testproject;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.util.*;
import java.util.logging.*;
public class TestProject {
public static void main(String[] args) {
try {
YouTubeService service = new YouTubeService("Test", "developerKey");
service.setUserCredentials("root#gmail.com", "pa$$word");
} catch (AuthenticationException ex) {
Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
At first, I included every library in http://code.google.com/p/gdata-java-client/downloads/list and also imported much more than I needed to.
I've since removed the libraries I deemed unnecessary (thanks thinksteep). So the libraries I'm currently including are the following libraries:
mail.jar
activation.jar
ant.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
guava-11.0.1.jar
gdata-youtube-2.0.jar
gdata-youtube-met-2.0.jar
(There are probably a few libraries there which are not necessary... But I'm at my whit's end...)
I'm just trying to test getting a YouTube service so I can get things going on this project, but no dice. Oh, and I've also included this library: http://code.google.com/p/guava-libraries because before I was getting a NoClassDefFound error and including that library seemed to solve it. Thank you in advance for the help!
Oh, and I also followed every step exactly (or at least I think so) in the gdata getting started guide. My test build was successful by the end... Thanks again!
Adding more than required may cause issue too. java.lang.NoSuchMethodError error typically happens in case where runtime couldn't find required method with exact signature. Possible causes are:
1) There might be mulitple jars with same code, which may cause wrong class get loaded.
2) Incompatable version of jar, the jar you have in classpath might be older version/newer version.
Make sure none of those cases happening.
Issue with latest version of gdata still referencing older guava methods
Check Out
http://code.google.com/p/gdata-java-client/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=344
Solution
I switched to guava-r07.jar located at
http://code.google.com/p/guava-libraries/downloads/detail?name=guava-r07.zip&can=4&q=
This got me past
ContactsService service = new ContactsService("");
Jar's in use:
Default Eclipse plugin jar's
gdata-base-1.0.jar
gdata-client-1.0.jar
gdata-contacts-3.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
guava-r07.jar
Apache (servlet-api.jar)
JavaMail (mail.jar)
JavaBeans Activation Framework (activation.jar)
I dont know if its still relevant but i had the same exception
there is a problem with guava 11.02.jar (currently latest version)
when using guava-10.0.1 (can be found here) everything went well.
The Required library jars are as follows.
gdata-client-1.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
gdata-youtube-2.0.jar
guava-11.0.2.jar
java-mail-1.4.4.jar
I am using the above mentioned library . Please make use of it ; because the ultimate aim is to get the YouTubeService Object. Check below for the code snippet.
package com.baba.test;
/*
* Author : Somanath Nanda
*/
import java.net.MalformedURLException;
import java.net.URL;
import com.google.gdata.client.youtube.YouTubeQuery;
import com.google.gdata.client.youtube.YouTubeService;
public class Test {
private static final String CLIENT_ID = "XXXXXXXX.XXXXX.XXX.XXX";
private static final String DEVELOPER_KEY = "*********************************88";
public static void main(String[] args) throws MalformedURLException {
YouTubeService service = new YouTubeService(CLIENT_ID,DEVELOPER_KEY);
System.out.println("Service : "+service);
}
If you're using a build tool, such as Maven, then you could simply do something similar to the following example from a portion of the dependencies section in my pom.xml:
<!-- The mail dependency is required BEFORE the javaee-api dependency.
The gdata dependency (YouTube API) requires the mail dependency. -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>core</artifactId>
<version>1.47.1</version>
</dependency>
I have added googlecollection-exp.jar into my build path then the previous execption was gone.
Pay attention to this jar gdata-core-1.0.jar I have the same problem, and I realized I have problem with this jar gdata-core-1.0.jar, and I found from website the same jar gdata-core-1.0.jar, but the content is different. After I replaced the new gdata-core-1.0.jar, problem solved.
So it's tricky that the jar with the same name but their contents are not the same. you thought you have the jar, actually it's not the right one
It could be that some of your jars would be having dependency on google/guava jars and if they're not in build path or if multiple of them are there it might raise inconsistency hence the error. A quick solution could be add latest version of guava to your pom
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
Now check in dependency hierarchy if any of your Jar apart from guava is referring to any other older jar of guava/google-collections. If so then exclude it, something like this
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>

Categories