Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

swagger-samples/java/java-jersey2 does not compile or run #154

Open
steranka opened this issue Nov 13, 2018 · 2 comments
Open

swagger-samples/java/java-jersey2 does not compile or run #154

steranka opened this issue Nov 13, 2018 · 2 comments

Comments

@steranka
Copy link

steranka commented Nov 13, 2018

I'm running with Java 11 (maven 3.5.3) on Windows 10 host and the java-jersey2 example does not compile. I just jumped in to that example as it seemed to be a starting point for me to learn Swagger.

The doc page says to run
mvn package -Dlog4j.configuration=file:./conf/log4j.properties jetty:run

That produces a bunch of errors: Cannot find symbol javax.xml.bind.annotation and other errors.

My request is to have the documentation updated so that the steps compile and run. I know that it might be related to using newer versions of Java and maven so I'll try this with an older version of java to see if that helps. There also might be "spec/interfaces" jar file that I'm missing to support compiling, if so please let me know.

Below are details of my environment

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T14:49:05-05:00)
Maven home: C:\P\apache-maven-3.5.3\bin\..
Java version: 11.0.1, vendor: Oracle Corporation
Java home: C:\PROGRA~1\Java\JDK-11~1.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

C:\Play\2018-11\swagger-samples\java\java-jersey2>mvn package -Dlog4j.configuration=file:./conf/log4j.properties jetty:run
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< io.swagger:swagger-jersey2-sample-app >----------------
[INFO] Building swagger-jersey2-jaxrs-app 1.0.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0-beta-1:enforce (enforce-maven) @ swagger-jersey2-sample-app ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.0-beta-1:enforce (enforce-versions) @ swagger-jersey2-sample-app ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:copy-resources (copy-resources) @ swagger-jersey2-sample-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 11 resources
[INFO]
[INFO] --- scala-maven-plugin:3.1.5:add-source (default) @ swagger-jersey2-sample-app ---
[INFO] Add Source directory: C:\Play\2018-11\swagger-samples\java\java-jersey2\src\main\scala
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ swagger-jersey2-sample-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- download-maven-plugin:1.2.1:wget (swagger-ui) @ swagger-jersey2-sample-app ---
[INFO] Got from cache: C:\Users\user1\.m2\repository\.cache\maven-download-plugin\master.tar.gz
[INFO] Expanding: C:\Play\2018-11\swagger-samples\java\java-jersey2\target\master.tar.gz into C:\Play\2018-11\swagger-samples\java\java-jersey2\target
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ swagger-jersey2-sample-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 22 source files to C:\Play\2018-11\swagger-samples\java\java-jersey2\target\classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/util/ApiAuthorizationFilterImpl.java: C:\Play\2018-11\swagger-samples\java\java-jersey2\src\main\java\io\swagger\sample\util\ApiAuthorizationFilterImpl.java uses or overrides a deprecated API.
[WARNING] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/util/ApiAuthorizationFilterImpl.java: Recompile with -Xlint:deprecation for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/User.java:[23,2] cannot find symbol
  symbol: class XmlRootElement
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/User.java:[21,1] package javax.xml.bind.annotation does not exist
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Category.java:[21,2] cannot find symbol
  symbol: class XmlRootElement
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Category.java:[19,1] package javax.xml.bind.annotation does not exist
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Pet.java:[26,2] cannot find symbol
  symbol: class XmlRootElement
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Tag.java:[21,2] cannot find symbol
  symbol: class XmlRootElement
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Pet.java:[24,1] package javax.xml.bind.annotation does not exist
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Tag.java:[19,1] package javax.xml.bind.annotation does not exist
[ERROR] /C:/Play/2018-11/swagger-samples/java/java-jersey2/src/main/java/io/swagger/sample/model/Order.java:[25,2] cannot find symbol
  symbol: class XmlRootElement
@steranka
Copy link
Author

steranka commented Nov 13, 2018

I found the answer for how to get this to compile and run. The question/answer on StackOverflow titled Java 11 package javax.xml.bind does not exist [duplicate] provided a pointer to another question which provided the answer I needed.

The fix (for me) was to add the following dependencies to my pom.xml file from StackOverflow This is required for Java 11, and Java 10 has another potential solution (not tried).

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

@steranka
Copy link
Author

This issue can be closed. I think just a comment that states that this was tested and worked with Java version 8 (likely) and later Java versions require other changes, and point to this question.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant