4

I have a local jar file to import into my folder, and I have run the mvn install:

mvn install:install-file -Dfile="C:\myapp\Development\core\target\api-core-1.0.0.jar" -DgroupId="com.myapp" -DartifactId="api-core" -Dversion="1.0.0" -Dpackaging=jar

And this is successuful:

------------------------------------------------------------------------
[INFO] Building api-malloc 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ api-malloc ---
[INFO] Installing C:\myapp\Development\core\target\api-core-1.0.0.jar to C:\Users\myname\.m2\repository\com\myapp\api-core\1.0.0\api-core-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

From the .me folder, I can also see that the appropriate files are generated:

enter image description here

In the pom.xml file, I have:

<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.myapp</groupId>
    <artifactId>api-malloc</artifactId>
    <version>0.0.1</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.myapp</groupId>
            <artifactId>api-core</artifactId>
            <version>1.0.0</version>
        </dependency>
        ... rest of dependencies
    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                        <addClasspath>true</addClasspath>
                         </manifest>
                         <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <webResources>
                         <webResource> 
                           <directory>${project.build.directory}/WebContent/WEB-INF</directory> 
                           <includes> 
                             <include>web.xml</include> 
                           </includes> 
                           <targetPath>WEB-INF</targetPath> 
                           <filtering>true</filtering> 
                         </webResource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                    <id>copy-dependencies</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                            <outputDirectory>${project.build.directory}/WebContent/WEB-INF/lib</outputDirectory>
                            <includeScope>runtime</includeScope>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I also did a maven update project after installing the jar file.

However Eclipse still complain about the classes from that dependency api-core-1.0.0.jar cannot be resolved to a type.

What did I miss?


EDIT

The maven's settings.xml file is already included the lines while the error persist.

<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>C:/Users/username/.m2/repository</localRepository>
  <offline>false</offline>

And in Eclipse, the maven setting is correct:

enter image description here

2
  • Did you get the answer Commented May 11, 2020 at 22:18
  • @AmritRaj I can't remember from 4 years ago man, but I hope I accepted the answer below for a reason? Commented May 13, 2020 at 1:39

3 Answers 3

3
<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>${userhome}/.m2/repository</localRepository>
      <offline>false</offline>
</settings>

try to add this to settings.xml Create on under ${userhome}/.m2/ if it does not exists.

Sign up to request clarification or add additional context in comments.

Comments

0

Go to Maven->conf->setting.xml.add <localRepository>The path to the local repository </localRepository>

if you have in c: then path should look like this <localRepository>C:\Users\usename\.m2\repository</localRepository>

5 Comments

The .me/repository path seems to be the default path, and unfortunately even I specifically put the <localRepository> value there, it still didn't solve my problem :(
Have you checked the Eclipse->Preference->Maven->User Setting
@jamesdeath123 can you update maven in eclipse and check ? because it seems repository not updated.can you check?
@RogerDwan please see my updated question - it looks legit.
@Soorapadman yeah I tried maven update project and maven clean but still no luck.
0

If you're using eclipse try this.

  • Go to Windows->Show View->Other
  • You'll get a popup and in that go to Maven->Maven Repositories
  • Right click on the appropriate repository, and select Rebuild Index

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.