前言
把项目的JDK升级成了JDK11后,发现原来的代码报错了,javax.annotation.Resource等地方,提示没有那个包:
java: package javax.annotation does not exist
解决
问题是Java11以后,都移除了javax.annotation,不过解决方案也简单,它只是不在标准的JDK里,还可以通过第三方jar包引入,或者利用maven引入:
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Copyright (c) 2020. ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. ~ --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.terrynow</groupId> <artifactId>myapp</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> </plugins> </build> <dependencies> <!--其他依赖忽略--> <!--javax.annotation支持--> <dependency> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> <version>1.3.2</version> </dependency> </dependencies> </project>
如上,问题解决!
文章评论