12

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.

Is there a way to generate them automatically on Netbeans? I know maven can do it. 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

Community
  • 1
  • 1
hrzafer
  • 1,123
  • 1
  • 15
  • 35

6 Answers6

12

Here is the solution I came up with at the end. It uses Ant and generates javadoc and source jar. Then it archives binary jar, javadoc, source.jar, licence and readme file in to a zip file that is ready to release.

 <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

Script gets the version number from a properties file. I got this solution from here.

hrzafer
  • 1,123
  • 1
  • 15
  • 35
11

This is all the maven config you need to attach source and javadoc automatically to the build:

<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?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 2
    do they? I only criticize ant because it's awful to code against and to debug. seriously: you could strip groupIds, execution ids and plugin versions from this code and it would be shorter, but I prefer to spell things out. – Sean Patrick Floyd Oct 26 '10 at 12:30
1

Try ant http://ant.apache.org/ . It's easier to learn than maven and can do your code compilation.

kasten
  • 602
  • 2
  • 6
  • 17
  • In my experience it's the other way around. We used a ant build script to build our application with sourcecode and several jar-files. Later we switched to maven and my impression was that it's more powerful with it's automatic lib fetching. But i have only limited experience with both. – kasten Oct 26 '10 at 12:16
  • 3
    @seanizer: there's different kinds of hard. Ant is much easier to use and learn incrementally because you don't have to organize your project around it. – Michael Borgwardt Oct 26 '10 at 12:19
  • 1
    @Michael that's exactly what makes ant hard. With maven, you have to make the transition once and you're up and running, with ant you have to keep tweaking and keep wondering why things don't work like you expect them to. With maven, all plugins act together in a natural way, because there is a well-defined model underneath that everybody uses. – Sean Patrick Floyd Oct 26 '10 at 12:26
  • 2
    @kasten the two key features of maven are a) automated dependency management and b) convention over configuration (e.g. you can rely on the fact that things are where they are supposed to be by querying the appropriate properties). The key feature of ant is that you can do just about anything, but that is also the main bug in my opinion. – Sean Patrick Floyd Oct 26 '10 at 12:34
  • 2
    @seanizer: From what I've heard, some people have made very bad exoeriences with maven acting anything but "natural", wnd while I'm sure it's much easier to get to speed with a large complex maven config than a large complex ant script, if you just want to do X, ant lets you just do that without demanding your right arm, your firstborn and your immortal soul. – Michael Borgwardt Oct 26 '10 at 14:22
  • @Michael I guess that depends on your definition of "natural". But I agree with your second point: for small isolated tasks, ant is probably better, maven is better for the big picture. BTW both my right arm and my firstborn son are doing fine, and after recently switching from windows to ubuntu even my immortal soul should be ok. – Sean Patrick Floyd Oct 26 '10 at 14:27
  • Maven is an abomination and only suitable for those who don't really want to understand what's going on under the hood. Not surprisingly, when SHTF (and it does hit the fan a lot with all but the most trivial of projects) with Maven you throw your hands up in the air and curse your fate. Learn Ant. It's very simple, powerful, easily extensible and there's no magic involved. It says a lot about the engineering processes of an organization that they might want to "abstract away" their build system. – Marcus Junius Brutus Feb 21 '17 at 15:54
  • ... and when it comes to resolving and pulling in dependencies the combination of Ant with Ivy provides all of the often touted "benefits" of Maven in terms of dependency resolution, again with no magic in a totally transparent way. – Marcus Junius Brutus Feb 21 '17 at 16:50
0

Maven plugins could be you answer

<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>
Paul McKenzie
  • 19,646
  • 25
  • 76
  • 120
  • Just read your question more carefully. However, for a simple project Maven doesn't represent too large a learning curve, imho. – Paul McKenzie Oct 26 '10 at 12:08
0

With ant you can easily generate your javadoc, compile, create jars and zip-file. It's better than do it in netbeans, because if someone want to contribute he could do it with his preferred IDE.

niels
  • 7,321
  • 2
  • 38
  • 58
0

If you are developing a library that others might help develop then you should think about using 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

Peter Knego
  • 79,991
  • 11
  • 123
  • 154