简体   繁体   English

Source和Javadoc jar生成

[英]Source and Javadoc jar generation

I think my question is easy. 我认为我的问题很简单。 However it is surprising that I couldn't find any easy solution. 然而令人惊讶的是,我找不到任何简单的解决方案。

I'm developing an open source Java library project on Netbeans and like many others I want to release it as binary.jar, source.jar and javadoc.jar. 我正在Netbeans上开发一个开源Java库项目,像其他许多我想将它发布为binary.jar,source.jar和javadoc.jar。

Is there a way to generate them automatically on Netbeans? 有没有办法在Netbeans上自动生成它们? I know maven can do it. 我知道maven可以做到。 But the learning curve seems too long. 但学习曲线似乎太长了。

There is a similar question but the only answer didn't work: Automatically generating source and doc jars in Netbeans 有一个类似的问题,但唯一的答案不起作用: 在Netbeans中自动生成源和文档罐

Here is the solution I came up with at the end. 这是我最后提出的解决方案。 It uses Ant and generates javadoc and source jar. 它使用Ant并生成javadoc和源jar。 Then it archives binary jar, javadoc, source.jar, licence and readme file in to a zip file that is ready to release. 然后它将二进制jar,javadoc,source.jar,license和readme文件存档到一个准备发布的zip文件中。

 <target name="-pre-init">
    <property file="version.properties"/>
    <property name="dist.jar" value="dist/${ant.project.name}-${project.version}.jar"/>
</target>

<target description="bundle sources in a jar" name="package-sources">
    <jar basedir="src" destfile="build/release/${ant.project.name}-${project.version}-sources.jar"/>
</target>


<target name="package_for_release" depends="jar,javadoc, package-sources">
    <mkdir dir="build/release"/>
    <copy file="${dist.jar}" todir="build/release/"/>
    <copy file="licence.txt" todir="build/release/"/>
    <copy file="beni_oku.txt" todir="build/release/"/>
    <mkdir dir="build/release/doc"/>
    <copy todir="build/release/doc">
        <fileset dir="dist/javadoc" includes="**"/>
    </copy>

    <zip basedir="build/release/" includes="**" destfile="dist/${ant.project.name}-${project.version}.zip"/>
</target>

Open build.xml in NetBeans than right click - > run target -> [other targets] -> package_for_release 在NetBeans中打开build.xml而不是右键单击 - >运行目标 - > [其他目标] - > package_for_release

Script gets the version number from a properties file. 脚本从属性文件中获取版本号。 I got this solution from here . 我从这里得到了这个解决方案。

This is all the maven config you need to attach source and javadoc automatically to the build: 这是将源和javadoc自动附加到构建所需的所有maven配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>attach-javadoc</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.1.2</version>
            <executions>
                <execution>
                    <id>attach-source</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

That's not too awful, is it? 这不是太可怕了,是吗?

Try ant http://ant.apache.org/ . 试试蚂蚁http://ant.apache.org/ It's easier to learn than maven and can do your code compilation. 它比maven更容易学习,可以进行代码编译。

Maven plugins could be you answer 你可以回答Maven插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <goals>
                <goal>jar</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.0.4</version>
    <executions>
        <execution>
            <goals>
                <goal>jar</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

With ant you can easily generate your javadoc, compile, create jars and zip-file. 使用ant,您可以轻松生成javadoc,编译,创建jar和zip文件。 It's better than do it in netbeans, because if someone want to contribute he could do it with his preferred IDE. 它比netbeans更好,因为如果有人想贡献,他可以用他喜欢的IDE做到这一点。

If you are developing a library that others might help develop then you should think about using Maven . 如果您正在开发其他人可能帮助开发的库,那么您应该考虑使用Maven

This way you project will be independent of your IDE and also dependencies, tests and deployment will be taken care of centrally, instead of ever contributor rolling their own.m 这样,您的项目将独立于您的IDE,并且依赖性,测试和部署将集中处理,而不是自己的贡献者自己滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM