How to download source code from Maven Central for a project - java

I want to download the source code for the project XBee-api v9.3 from Maven Central so that I can modify the code for my application. I am using Netbeans and I have managed to produce a POM that validates and compiles successfully.
I have then run the command
mvn dependency:resources
from the same directory as the POM to force download of the source code.
I have a few problems:
When I look inside the project with Netbeans, I see the class files (which I think may actually be jars). When I open up any class, I only get the method headers, but not the source code.
When I open a class file, there is the option in the top right of the window to "Attach Sources...". When I select "Download", I get a message in the lower left of the window saying "Downloading source jar from known Maven Repositories for local repository file" but nothing seems to be happening.
When I open up the folder either with explorer or Netbeans files view, the folder is empty except for the POM. If I use Projects view in Netbeans, I can see a project structure and what appears to be the generated source files, but no source code.
I can't find answers on Google.
My questions are:
What am I doing wrong?
How do I download the source code?
Any help would be much appreciated.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<packaging>jar</packaging>
<version>0.9.3</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>A java library for communicating with XBee radios</description>
<url>https://github.com/andrewrapp/xbee-api/</url>
<licenses>
<license>
<name>GPL license, Version 3.0</name>
<url>https://www.gnu.org/licenses/gpl-3.0.html</url>
</license>
</licenses>
<developers>
<developer>
<name>Andrew Rapp</name>
<email>andrew.rapp+github.com#gmail.com</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<!-- https://mvnrepository.com/artifact/com.rapplogic/xbee-api -->
<dependencies>
<dependency>
<groupId>com.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<version>0.9.3</version>
</dependency>
</dependencies>
</project>

The GitHub project page is here:
https://github.com/andrewrapp/xbee-api
(referenced in the POM under the url element)
...so you can just download the source from the Github page: https://github.com/andrewrapp/xbee-api/archive/master.zip

Related

Maven inside docker container ignoring local repository

I have a maven project with a few custom dependencies that reside on a private repository. I'm attempting to create a docker image based on one of the maven images with these dependencies pre-loaded into the local maven repository.
Dockerfile
FROM maven:3.8.6-openjdk-11-slim
COPY settings-docker.xml /usr/share/maven/ref/
COPY bom.xml /tmp
RUN mvn -B -f /tmp/bom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve
settings-docker.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/usr/share/maven/ref/repository</localRepository>
<mirrors>
<mirror>
<id>Mirror of Private Repo</id>
<mirrorOf>Private Repo</mirrorOf>
<name>allows http</name>
<url>http://here.it.is/repository/</url>
</mirror>
</mirrors>
</settings>
bom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.myproject</groupId>
<artifactId>bom</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<repositories>
<repository>
<id>Private Repo</id>
<url>http://here.it.is/repository/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>codec</groupId>
<artifactId>codec</artifactId>
<version>1.10.0.</version>
</dependency>
</dependencies>
</project>
I followed the instructions from the official maven image on using /usr/share/maven/ref/repository for preloaded dependencies. The image builds successfully and when I start it I can see my dependency in both /usr/share/maven/ref/repository and in /root/.m2/repository.
Despite this when I run maven, it will always attempt to connect to my private repository. Is this some maven behavior I don't know about or is it ignoring my repository?
I believe you have faced with "enhanced local repository manager" feature:
Enhanced local repository manager is built upon the classical Maven
2.0 local repository structure but additionally keeps track of from what repositories a cached artifact was resolved. Resolution of
locally cached artifacts will be rejected in case the current
resolution request does not match the known source repositories of an
artifact, thereby emulating physically separated artifact caches per
remote repository.
For example:
% cat ~/.m2/repository/org/springframework/spring-core/5.3.9/_remote.repositories
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Wed Mar 16 08:49:28 AEDT 2022
spring-core-5.3.9.pom>internal-repository=
spring-core-5.3.9.pom>central=
spring-core-5.3.9.jar>central=
spring-core-5.3.9.jar>internal-repository=
You may either disable that feature via specifying -llr in maven opts or investigate how force maven to use the same "repository id" in different scenarios.

Error Code 400 when trying to (maven) deploy to github packages using github actions

I am struggling with the (seemingly) simple task of deploying a maven project to github packages using a github actions workflow. First of all, here's the error I am getting in the maven deploy phase:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project [project name]: Failed to retrieve remote metadata [groupId]:[artifactId]:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata [groupId]:[artifactId]:1.0-SNAPSHOT/maven-metadata.xml from/to github (https://maven.pkg.github.com/[username]/[repository]): Failed to transfer file https://maven.pkg.github.com/[username]/[repository]/[groupId as path]/[artifactId]/1.0-SNAPSHOT/maven-metadata.xml with status code 400 -> [Help 1]
(Info: I replaced unneccessary and/or private concrete information with general terms in [brackets])
Most likely, the actual maven-metadata.xml file is not the problem because I have already seen warnings like "could not upload checksum" with status 400 before. I guess that maven-metadata.xml is just the first file it fails on, but probably I am completely wrong with this assumption, please tell me if so.
Probably the most important file is the workflow yaml file:
name: Deploy SNAPSHOT (develop)
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Set up JDK 11
uses: actions/setup-java#v1
with:
java-version: 11
- name: Maven Deploy
env:
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn --settings settings.xml -B -e -Dmaven.wagon.http.pool=false clean deploy
Also quite important: the maven settings.xml file:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<activeProfiles>
<activeProfile>github-packages</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github-packages</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>github</id>
<name>GitHub [username] Apache Maven Packages</name>
<url>https://maven.pkg.github.com/[username]</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>${env.GITHUB_USERNAME}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
(Info: same goes for values in brackets as before)
And lastly, the parent pom.xml of my maven project:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[groupId]</groupId>
<artifactId>[artifactId]</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
[child modules]
</modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
</properties>
<dependencies>
[my dependencies]
</dependencies>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub [username] Apache Maven Packages</name>
<url>https://maven.pkg.github.com/[username]/[repository]</url>
</repository>
</distributionManagement>
</project>
Maybe it's also important to say that the GitHub repository belongs entirely to me and therefore I should have all admin rights on it.
Things I've tried:
I have done some research by now and I found that my issue seems to be not uncommon. Although, from all solutions I've found so far, not one has worked.
Official GitHub documentation for setting up workflows
To start of, I used this site as my reference.
This StackOverflow Question
I mostly stuck to all the advice I found in this question and in the answers to it.
This other StackOverflow Question about nexus deploys
The accepted answer of this question provides a checklist. I tried to check that all the bullet points work for me, although I wasn't able to validate everything. I did not find any issue based on this checklist.
This question on the GitHub community forum
The error displayed in this question looks very much like the error I am getting, still the proposed solution did not fix anything for me.
This Answer on a similar GitHub community forum question
This answer suggested using a personal access token instead of the GITHUB_TOKEN. I tried that and it changed nothing.
What I need
Of course I'd be happy if someone can show me what the exact issue of my case is, but it does not need to be that specific. I am trying to set up the most basic pipeline possible and I currently don't want to do more than just deploy a maven snapshot repository to github packages (with github actions). So, if anyone can show me how to do this properly in general, that's also fine. Thanks!
I kinda figured it out myself, but the result is very dissatisfying. The main problem here is:
Note: GitHub Packages does not support SNAPSHOT versions of Apache Maven. Make sure you disable SNAPHOT in your ~/.m2/settings.xml file.
(Source)
So, it seems like GitHub Packages does not support the construct of maven snapshot repositories, which are otherwise very practical. My plan was to set up a workflow that deploys a new SNAPSHOT on the package registry when a push to develop happens. Maven snapshot repositories do not require unique version numbers for deploys, which means I could have built a new version for every push, but the actual dependency version stays fixed. Everyone could then easily try out the latest state of my develop branch, simply by including the fixed snapshot version in their pom files.
Now, how to fix my issue:
Because GitHub packages does not support snapshot repositories, you will have to remove the keyword "SNAPSHOT" from the value in the project.version tag in your pom file. Basically you can put every other version description there, but now it is unique. However if you remove all SNAPSHOT keywords, the workflow should properly deploy a package to the GitHub package registry, at least it worked for me.
If anyone knows a way to "hack" around this SNAPSHOT issue, please tell me. Otherwise this is the only working solution I've found so far.

Dependency error in eclipse project making use of Maven

I am using Eclipse Mars to run my Java project. I am making use of Maven in it. But while trying to compile my package I am getting the following error.
Failed to execute goal on project apex-check: Could not resolve dependencies for project org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0: Failed to collect dependencies at org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Failed to read artifact descriptor for org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Could not transfer artifact org.fundacionjala.enforce.sonarqube:apex-squid:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): Failed to authenticate with proxy -> [Help 1].
I am able to find that my pom.xml has a bug in its dependency. But don't know how to resolve it. I have given below my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) Fundacion Jala. All rights reserved. ~ Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fundacionjala.enforce.sonarqube</groupId>
<artifactId>apex</artifactId>
<version>1.0b${build.number}</version>
</parent>
<artifactId>apex-check</artifactId>
<name>Apex :: Checks</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apex-squid</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
I have written 'apex-check' and 'apex-squid' as two separate projects.
Can anyone explain how to correct my pom.xml?
You need to have:
org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0
org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0
jar files available in your local .m2/repository folder. If they are not present maven will try to download from central repository and as an expected result it will fail on firewall or it will not find the artifact. i.e. if:
apex-check requires apex-squid project as dependency first you need to install squid project files by using mvn install on squid project folder.
But it seems more like you want to create a multi module maven project, take a look at this question. Create a parent project similar to this project, add check and squid as module and run mvn clean install on parent.
**edit: I just see you already have parent, so make sure parent has your projects as modules, which helps reactive build order and eclipse imports

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: linux, architecture: x86_64

I am trying setup TensorFlow Java application in Eclipse Oxygen (OS: Ubuntu Linux 16.x). I installed Tensorflow and followed the process mentioned in official documentation for Java (Maven Project) installation. I downloaded libtensorflow-1.3.0.jar, jni files and included in the build path. When I execute the program I get this following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: linux, architecture: x86_64. See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/java/README.md for possible solutions (such as building the library from source). Additional information on attempts to find the native library can be obtained by adding org.tensorflow.NativeLibrary.DEBUG=1 to the system properties of the JVM.
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.TensorFlow.init(TensorFlow.java:36)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:40)
at com.tensorflow.malwaredetection.App.main(App.java:13)
App.java
package com.tensorflow.malwaredetection;
import org.tensorflow.TensorFlow;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!"+ TensorFlow.version() );
}
}
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TensorFlow</groupId>
<artifactId>MalwareDetection</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MalwareDetection</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<exec.mainClass>App</exec.mainClass>
<!-- The sample code requires at least JDK 1.7. -->
<!-- The maven compiler plugin defaults to a lower version -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</project>
I got tired of this error and tried to do this in an old-fashioned way. Created App.java in a separate folder and included jar, jni files in the same directory. When I execute this from command line, I get different error
dev#ubuntu:~/Downloads$ javac -cp libtensorflow-1.3.0.jar Test1.java
dev#ubuntu:~/Downloads$ java -cp libtensorflow-1.3.0.jar:. -Djava.library.path=./jni Test1
Error: Could not find or load main class Test1
dev#ubuntu:~/Downloads$
I think you need to include jni library dependency in your pom.
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow_jni</artifactId>
<version>1.1.0</version>
</dependency>
When you have tensor flow dependency in your pom.xml file as below
<dependencies>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow</artifactId>
<version>1.14.0</version>
</dependency>
It will download required 3 libraries
tensorflow-1.14.0.jar
libtensorflow-1.14.0.jar
libtensorflow_jni-1.14.0.jar
So you have to manually extract the 3rd jar(libtensorflow_jni) and get your OS compatible file like for windows you have to copy the tensorflow_jni.dll file and paste in your project root directory
that will solve your problem.
For Linking error the JNI library which you have downloaded is
not compatible with OS you are running,
is not in PATH () or
with lesser probability TensorFlow bu which you should be able to confirm from TF triage.
For second could not find class
your PATH must be appended with "." so that it can find class in current folder from where it is running
Less probability is if class name/package is not same.
If you can post code for class will check

maven-compiler-plugin:3.1:compile(1 errors) in eclipse [duplicate]

This question already has answers here:
How to force maven update?
(26 answers)
Closed 6 years ago.
I want to learn java spring, so I choose Eclipse Mars2 Version and I want to build a java project using Maven. But I get errors
maven-compiler-plugin:3.1:compile(1 errors)
maven-compiler-plugin:3.1:testCompile(1 errors)
Then I check my maven and java path in my Windows 10 64 bit system variable.
I configured like this :
JAVA_HOME => C:\Program Files\Java\jdk1.8.0_71
M2_HOME => C:\apache-maven
MAVEN_HOME => C:\apache-maven
And in systen variabel path :
%JAVA_HOME%\bin
%M2_HOME%\bin
Everything is fine, I checked it by java -version and mvn-version
Also, I have installed mvn plugin in eclipse in install new software
to maven :
Name: m2e
Location: http://download.eclipse.org/technology/m2e/releases
But I still failed. The errors is still pop up.
Please advise. Thanks.
UPDATE
I test to build a project maven-archetype-quickstart version 1.1
execution default-compile, in Access/pom.xml
execution default-testCompile, in Access/pom.xml
UPDATE AGAIN
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tresnamuda</groupId>
<artifactId>access</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>access</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Eclipse detect error in first line which is :
project xmlns="http://maven.apache.org/POM/4.0.0" .....
also in line 8.
This is the complete error :
It seems like there is corruption in your local repository.
Please try:
Delete the local repository, if you use Windows, delete the folder C:\Users\your-user-name\.m2\repository
In Eclipse, right click on the project name and click Maven\Update project ... (or use hotkey ALT+F5)

Categories