maven打包生成doc文档和打包源码 在pom.xml中加入如下插件 build plugins !-- 文档 插件 -- plugin groupIdor下g.apache.maven.plugins/groupId artifactIdmaven-javadoc-plugin/artifactId version2.7/version executions execution
maven打包生成doc文档和打包源码
在pom.xml中加入如下插件
<build> <plugins> <!-- 文档 插件 --> <plugin> <groupId>or下g.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> <configuration> <additionalparam>-Xdoclint:none</additionalparam> </configuration> </execution> </executions> </plugin> <!-- 打包源码插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1.2</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
如上的此种打包方式打包成如下这种分为3个包,源码包,文档包,和不包含源码的war包
如果想把源码和编译后的打包到一个war里面,
将打包源码插件改为 如下插件
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.java</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
插件maven-resources-plugin默认处理资源和测试资源,把资源加入到文件夹${project.build.outputDirectory},这个引用表示项目的输出文件夹。
一般是项目的WEB-INF\classes文件夹。等到打包的时候,就把这个文件夹里面的内容打包成jar文件。所以想要把源代码打包到jar文件里面
就需要把源代码当作资源文件添加到文件夹${project.build.outputDirectory}。
打包完成只会生成一个war包,
而查看war包中包含源码的方式如下
maven 打包报错 生成javadoc 时有问题
项目是基于maven管理的,一直打包都好着呢,
今天打包莫名奇妙的报了一大堆错误
[ERROR] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc [ERROR] at com.sun.tools.javadoc.AnnotationDescImpl.annotationType(AnnotationDescImpl.java:46) [ERROR] at com.sun.tools.doclets.internal.toolkit.util.Util.isDeprecated(Util.java:811) [ERROR] at com.sun.tools.doclets.formats.html.TagletWriterImpl.deprecatedTagOutput(TagletWriterImpl.java:85) [ERROR] at com.sun.tools.doclets.internal.toolkit.taglets.DeprecatedTaglet.getTagletOutput(DeprecatedTaglet.java:40) [ERROR] at com.sun.tools.doclets.formats.html.MethodWriterImpl.writeDeprecated(MethodWriterImpl.java:166) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.MethodBuilder.buildDeprecationInfo(MethodBuilder.java:183) [ERROR] at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [ERROR] at java.lang.reflect.Method.invoke(Method.java:597) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.MethodBuilder.invokeMethod(MethodBuilder.java:109) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.AbstractMemberBuilder.build(AbstractMemberBuilder.java:56) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.MethodBuilder.buildMethodDoc(MethodBuilder.java:150) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [ERROR] at java.lang.reflect.Method.invoke(Method.java:597) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.MethodBuilder.invokeMethod(MethodBuilder.java:109) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.AbstractMemberBuilder.build(AbstractMemberBuilder.java:56) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.buildMethodDetails(ClassBuilder.java:322) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [ERROR] at java.lang.reflect.Method.invoke(Method.java:597) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.invokeMethod(ClassBuilder.java:101) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.buildClassDoc(ClassBuilder.java:124) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [ERROR] at java.lang.reflect.Method.invoke(Method.java:597) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.invokeMethod(ClassBuilder.java:101) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90) [ERROR] at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.build(ClassBuilder.java:108) [ERROR] at com.sun.tools.doclets.formats.html.HtmlDoclet.generateClassFiles(HtmlDoclet.java:155) [ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.generateClassFiles(AbstractDoclet.java:164) [ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:106) [ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.start(AbstractDoclet.java:64) [ERROR] at com.sun.tools.doclets.formats.html.HtmlDoclet.start(HtmlDoclet.java:42) [ERROR] at com.sun.tools.doclets.standard.Standard.start(Standard.java:23) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [ERROR] at java.lang.reflect.Method.invoke(Method.java:597) [ERROR] at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269) [ERROR] at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143) [ERROR] at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340) [ERROR] at com.sun.tools.javadoc.Start.begin(Start.java:128) [ERROR] at com.sun.tools.javadoc.Main.execute(Main.java:41) [ERROR] at com.sun.tools.javadoc.Main.main(Main.java:31)
搞了半天没研究出来,最后试了多个命令,如 :pakage 、test 等命令都不报错,只有在用install 的时候报错。 仔细看日志,最后怀疑是 在生成 javadoc 的时候报错,又试了install -D maven.javadoc.skip=true 命令跳过 生成javadoc 部分,果然就不报错了。
仔细研究了下,原来是maven javadoc插件 版本的问题,导致生成这个的时候报错。
在pom 中增加
<build> <finalName>biz-statistics</finalName> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9.1</version> <executions> <execution> <id>attach-javadocs</id> <phase>install</phase> <goals> <goal>jar</goal> </goals> <configuration> <encoding>UTF-8</encoding> </configuration> </execution> </executions> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
设置版本号即可。以上为个人经验,希望能给大家一个参考,也希望大家多多支持自由互联。