Java - JARs

java

http://one-jar.sourceforge.net/

How can we install a JAR file that is created by our Maven project?

In Eclipse, in the Project Explorer pane, find the pom.xml file, right click on it and select 'Run As -> Maven Install'. This will install the JAR file into the local repository such as C:\Users\username\.m2.

If we want to build the "source" JAR that contains the source code of our project so that developers that use our JAR file can debug our code, in our pom.xml file, we need to include:

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

The above code can be either below or above the dependencies section.

To deploy our code to another repository, our pom.xml needs to contains sections that define those repositories, and from the command line we would have to run:

mvn deploy -DrepositoryId=central -Dfile=.\target\jxlpoi-0.0.16.jar -DartifactId=jxlpoi -Dversion=0.0.16 -Dsources=.\target\jxlpoi-0.0.16-sources.jar

Find the settings.xml file inside the MAVEN_HOME (C:\dev\apache-maven-3.5.3\conf). Inside this file, we need to define the username and password for connecting to our local maven server:

    <server>
        <id>central</id>
        <username>...</username>
        <password>...</password>
    </server>

How can a class read a file that is included in the same JAR that this class is included in?

ClassName.class.getResourceAsStream("/initialization/Lifepaths.txt")

See http://stackoverflow.com/questions/16570523/getresourceasstream-returns-null for details

How can we compare two JAR files?

  1. JAPICC: japi-compliance-checker OLD.jar NEW.jar
  2. PkgDiff: pkgdiff OLD.jar NEW.jar
  3. Clirr: java -jar clirr-core-0.6-uber.jar -o OLD.jar -n NEW.jar
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License