# Artifact Analysis

## About

**Artifact Analysis** is the process of inspecting and debugging packaged build outputs like JAR, WAR, EAR, or ZIP files. These artifacts are typically generated by build tools such as Maven or Gradle and deployed to servers, containers, or client machines.

Analyzing artifacts helps identify issues related to missing classes, incorrect dependencies, resource loading problems, packaging errors, and misconfigurations in the build process.

## **Common Use Cases**

* Verifying if all classes and resources are packaged correctly
* Checking for duplicate or conflicting classes in shaded or fat JARs
* Confirming that `MANIFEST.MF` is correctly configured (e.g., `Main-Class`)
* Identifying missing or misaligned dependencies
* Validating web resources in WAR files (`WEB-INF`, `META-INF`, etc.)
* Comparing two versions of artifacts for debugging regression issues
* Troubleshooting classpath issues in deployed environments

## **Common Artifact Types**

<table data-full-width="true"><thead><tr><th width="315.9661865234375">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>JAR</strong> (Java Archive)</td><td>Used for packaging Java classes and libraries.</td></tr><tr><td><strong>WAR</strong> (Web Application Archive)</td><td>Used for packaging web applications (includes JSPs, servlets, web.xml).</td></tr><tr><td><strong>EAR</strong> (Enterprise Archive)</td><td>Used in Java EE for combining multiple modules (JARs, WARs).</td></tr><tr><td><strong>ZIP</strong></td><td>Generic compressed archive; often used for distribution.</td></tr></tbody></table>

## **Typical Issues Found**

* `ClassNotFoundException` or `NoClassDefFoundError` due to missing classes
* Resources not loading (e.g., `FileNotFoundException` for `.properties` or `.xml`)
* Duplicate classes causing version conflicts
* Incorrect structure (e.g., `web.xml` not under `WEB-INF`)
* Missing or incorrect `Main-Class` in `MANIFEST.MF`
* Incorrect packaging type in `pom.xml` (e.g., `jar` vs `war`)
* Conflicts due to transitive dependencies

## **Tools for Artifact Analysis**

<table data-full-width="true"><thead><tr><th width="182.55035400390625">Tool</th><th width="149.91668701171875">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>jar</strong> (Java SDK)</td><td>CLI</td><td>Built-in Java tool to view, extract, and modify JAR files. Use <code>jar -tf</code>, <code>jar -xf</code>, and <code>jar -uf</code>.</td></tr><tr><td><strong>unzip</strong></td><td>CLI</td><td>Command-line utility to extract ZIP-based archives like JAR, WAR, and EAR.</td></tr><tr><td><strong>jd-cli</strong></td><td>CLI</td><td>Decompiles <code>.class</code> files inside JARs to Java source for inspection.</td></tr><tr><td><strong>jdeps</strong></td><td>CLI</td><td>Java Dependency Analysis Tool. Shows package-level and class-level dependencies.</td></tr><tr><td><strong>javap</strong></td><td>CLI</td><td>Java class file disassembler. Use to inspect bytecode-level details.</td></tr><tr><td><strong>Maven Dependency Plugin</strong> (<code>mvn dependency:tree</code>)</td><td>Build Tool Plugin</td><td>Shows resolved dependencies and helps detect conflicts or missing jars.</td></tr><tr><td><strong>Gradle Dependency Insight</strong> (<code>./gradlew dependencies</code>)</td><td>Build Tool Plugin</td><td>Similar to Maven, useful for inspecting resolved dependencies and transitive conflicts.</td></tr><tr><td><strong>Apache Tika</strong></td><td>CLI / API</td><td>Can detect file types and metadata inside archives (e.g., MIME type validation).</td></tr><tr><td><strong>ClassScavenger / Classpath Hell Analyzers</strong></td><td>GUI / CLI</td><td>Tools to scan JARs for duplicate classes or conflicting versions in the classpath.</td></tr><tr><td><strong>JarAnalyzer (OWASP)</strong></td><td>GUI</td><td>Analyzes JARs for common security risks, duplicates, and outdated libraries.</td></tr><tr><td><strong>JARScan / WARScan</strong></td><td>GUI / CLI</td><td>Scans <code>.jar</code> and <code>.war</code> files for content, metadata, and known issues.</td></tr><tr><td><strong>Beyond Compare / Meld / WinMerge</strong></td><td>GUI</td><td>File and directory diff tools used to compare contents of two artifacts.</td></tr><tr><td><strong>IDE (IntelliJ IDEA / Eclipse / VS Code)</strong></td><td>GUI</td><td>Built-in archive viewers, decompilers, and dependency visualizers.</td></tr></tbody></table>

## **Which Tool to Use When?**

<table data-full-width="true"><thead><tr><th>Use Case</th><th>Recommended Tools</th></tr></thead><tbody><tr><td>View or extract contents of JAR/WAR</td><td><code>jar</code>, <code>unzip</code>, IntelliJ</td></tr><tr><td>Compare two artifacts</td><td>Beyond Compare, Meld</td></tr><tr><td>View class-level dependency graph</td><td><code>jdeps</code>, Maven/Gradle dependency tools</td></tr><tr><td>Identify duplicate classes or version conflicts</td><td>Classpath Hell analyzers, <code>mvn dependency:tree</code></td></tr><tr><td>Decompile <code>.class</code> files</td><td><code>jd-cli</code>, IntelliJ, <code>javap</code></td></tr><tr><td>Inspect manifest file and metadata</td><td><code>jar -xf</code>, IDEs</td></tr><tr><td>Troubleshoot missing or misloaded resources</td><td><code>unzip</code>, <code>jar</code>, file structure checks</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/java/troubleshooting-java-code/artifact-analysis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
