0

The local jar is copied into /src/main/resources/, and add Maven dependency as How to add local jar files to a Maven project?

        <dependency>
            <groupId>com.yahoo.egads</groupId>
            <artifactId>egads</artifactId>
            <version>0.4.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/egads-0.4.0-jar-with-dependencies.jar</systemPath>
        </dependency>

The plugin is as following:

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The class of local jar can be located in IntelliJ IDEA and the main function can run successfully in IntelliJ IDEA button run. But error when running the final packaged jar, the class of local jar cannot be found with log java.lang.NoClassDefFoundError.

During packaging there is the following warning:

'dependencies.dependency.systemPath' for com.yahoo.egads:egads:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/egads-0.4.0-jar-with-dependencies.jar will be unresolvable by dependent projects @ line 36, column 25
Muz
  • 699
  • 1
  • 11
  • 25
  • After the following steps it works. 1.Following the highest answer of @user373455 in https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project 2.Add dependency in pom file. groupid id 0.1.0 – Muz Dec 10 '19 at 02:57

1 Answers1

0

How to add local jar files to a Maven project?

This video solved the problem for me.

https://www.youtube.com/watch?v=3nGwbRONhEU

Using Netbeans, it was as simply as adding the dependency (in your case it would be): In your "pom.xml" file: ... com.yahoo.egads egads 0.4.0 ... Then Open the dependencies folder and;

  1. right click the "egads-0.4.0.jar"
  2. then click on manually install artifact
  3. search for your .jar file and select it
  4. Finally, right on your project and "Clean and Build" I

After doing the "Clean and Build" if the following error appears:

Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

Then the following worked 100% for me: (thanks to the reference: Maven dependencies are failing with a 501 error)

Add in your "pom.xml" file (in Project Settings, as long as you created a maven java project):

<project>
      ...
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

Then, right click on your project, press -> Clean and Build. If "Succeded" then that's it. Else... (more errors) try (the last thing I can recommend):

Put in your "settings.xml" file (in your Project Settings, near the pom.xml), just the following:

<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>${user.home}/.m2/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <offline>false</offline>
</settings>




















It is not assured that the following will work:

(try under your own risk of losing your time, and patience..)

If that doesn't work and you still have errors I just can say other things that I did before but it isn't assured that they will work (here it goes):

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Remove all the "<" and ">" and execute that command with your custom parameters in the command line.

I executed that while being in ~/.m2/repository (/.m2/repository)

Hope it worked for you. I spent too much time today trying to solve this. The first post about this on stackoverflow is full of confusing things, bad explained and that isn't working at least for me. But well. I would have commented there but I got no points.

Original post (very confusing / bad explained): How to add local jar files to a Maven project?

I also had in my "pom.xml" the following (after having tried so much things I can't remember)

Write in "" your Java Source Package (the parent of your .java classes):

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
                <manifest>
                    <mainClass>com.mycompany.app</mainClass> 
                </manifest>
            </archive>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                    <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
            </execution>
        </executions>
    </plugin>

And finally, I also had this on my "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">
      <localRepository>${user.home}/.m2/repository</localRepository>
      <interactiveMode>true</interactiveMode>
      <offline>false</offline>
    </settings>

(I'm putting this on the final part because probbably with the first thing it will work, but if not you cant try to do all that I did wich I'm putting in the final part, just in case)

Also, all the links that were usefull for me, are these:

Wiki:

https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

https://techglimpse.com/create-maven-jar-file-netbeans-tutorial/

http://maven.apache.org/general.html#importing-jars (I just remember going straight to the point "have a jar that I want to put into my local repository. How can I copy it in?")

https://www.youtube.com/watch?v=3nGwbRONhEU

(I'm not puting the docens of useless links)

Gabriel
  • 1
  • 1