如何将JAR包上传至远程仓库并解决POM依赖缺失工件问题
Alright, let's sort out your artifact missing issue first, then cover the correct way to publish JARs to a remote Maven repository so this doesn't happen again.
Why You're Seeing the Artifact Missing Error
Manually creating the directory structure (jxl/jxl/1/jxl.jar) isn't enough for Maven to recognize the artifact. Maven requires additional metadata files alongside the JAR to validate its validity:
- A corresponding
pom.xmlfor the artifact - Checksum files (
.md5,.sha1) for both the JAR and POM
Without these files, Maven can't confirm the artifact is legitimate, hence the missing error you're seeing.
Step 1: Correctly Upload Your JAR to the Remote Repository
The standard, reliable way to publish JARs to a remote Maven repo is using the deploy:deploy-file Maven command. This handles all directory structure creation, metadata generation, and upload automatically.
Run This Command
Replace /path/to/your/jxl.jar with the actual file path of your JAR on your local machine:
mvn deploy:deploy-file \ -DgroupId=jxl \ -DartifactId=jxl \ -Dversion=1 \ -Dpackaging=jar \ -Dfile=/path/to/your/jxl.jar \ -Durl=http://xx.yy.zz.ss/uirepo \ -DrepositoryId=uirepo
Configure Repository Authentication (If Required)
If your remote repository requires login credentials, add this block to your settings.xml (usually located in ~/.m2/settings.xml or your Maven installation's conf/settings.xml):
<settings> <servers> <server> <id>uirepo</id> <username>your-repo-username</username> <password>your-repo-password</password> </server> </servers> </settings>
Make sure the <id> here matches the repositoryId in your deploy command and your pom.xml's repository <id>.
Step 2: Verify Your pom.xml Configuration
Your current pom.xml setup looks correct, but let's double-check to be sure:
<repositories> <repository> <id>uirepo</id> <url>http://xx.yy.zz.ss/uirepo</url> </repository> </repositories> <dependencies> <dependency> <groupId>jxl</groupId> <artifactId>jxl</artifactId> <version>1</version> </dependency> </dependencies>
The repository ID matches across configurations, and the dependency coordinates align with what you're uploading—this should work seamlessly once the artifact is properly deployed.
Alternative: Upload via Repository Management UI
If you're using a tool like Nexus, Artifactory, or Apache Archiva for your remote repo, you can also upload the JAR through their web interface:
- Look for an "Upload" section in the tool's UI
- Fill in the
groupId,artifactId,versionfields, then select your JAR file - The tool will auto-generate all required metadata and place the JAR in the correct directory structure
Final Steps to Resolve the Error
- Run the
deploy:deploy-filecommand (or upload via UI) to publish the JAR correctly to your remote repo - Refresh your Maven project (in IDEs like IntelliJ/Eclipse, use the "Reload All Maven Projects" option)
- Run
mvn clean installto pull the dependency from the remote repository
This should fully resolve the artifact missing error.
内容的提问来源于stack exchange,提问作者k.rohit

