• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Issue in adding a project dependency in another project

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to add other project dependency into my project.

For that I did the following in POM file:



But when I do mvn clean install in my project ,it shows follwing error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project realtime-student: Compilation failure
[ERROR] /Users/ljh736/Downloads/realtime-student/src/main/java/com/example/student/realtimestudent/config/ColorConfig.java:[11,50] package com.example.employee.employeeservice.model does not exist

Please help.

Thanks,
Sidharth
 
Saloon Keeper
Posts: 22273
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The group and artifact IDs for Maven do not refer to classes and packages, but rather to the  "vendor" and "product"  of a Maven-cataloged resource (generally a jar file).

So to get the message "package com.example.employee.employeeservice.model does not exist ", it means that neither the com.example.employee.employeeservice employee-service.jar file nor any other resource or project component contain any classes in the package named "com.example.employee.employeeservice.model." This can happen if you didn't build the jar with those classes or if you didn't observe Java's rules for precise upper/lower case letter usage.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you're using Java 9 or higher and the module system, the package is not exported in the module.
 
sidharth das
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The com.example.employee.employeeservice.model present in jar file. The jar file is available in m2 local repository.
But still I see the error
[ERROR] /Users/ljh736/Downloads/realtime-student/src/main/java/com/example/student/realtimestudent/config/ColorConfig.java:[11,50] package com.example.employee.employeeservice.model does not exist.

Do I need to deploy the jar file in nexus?

Thanks,
Sidhartha Das
 
Tim Holloway
Saloon Keeper
Posts: 22273
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run the command "jar -tvf employee-service-0.0.1-SNAPSHOT.jar" to list what files are actually in your employee-service jar. Run it against the jar file that's actually in ~/.m2/repository/com/example/employee/employeeservice/0.0.1-SNAPSHOT, since that's the file that Maven will actually pull.

Nexus is an upstream repository. If the artifact is in your local (!/.m2/repository) cache, it doesn't matter whether it's in Nexus.
 
sidharth das
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do the jar -tvf employee-service-0.0.1-SNAPSHOT.jar

I can see the class file which I am looking for
746 Sun Sep 30 19:58:50 CDT 2018 BOOT-INF/classes/com/example/employee/employeeservice/model/PineApple.class

But still I see the Error . when I do mvn cleam install

[ERROR] /Users/ljh736/Downloads/realtime-student/src/main/java/com/example/student/realtimestudent/config/ColorConfig.java:[11,50] package com.example.employee.employeeservice.model does not exist

Thanks,
Sidhartha Das
 
Tim Holloway
Saloon Keeper
Posts: 22273
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JAR file is incorrectly formed. Neither the BOOT nor classes directories should be part of the class file path in the jar. It should be simply /com/example/employee/employeeservice/model/PineApple.class
 
sidharth das
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this is a spring boot application, when I do mvn clean install it keeps inside BootINF/classes folder.

Thanks,
Sidhartha Das
 
Tim Holloway
Saloon Keeper
Posts: 22273
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your POM is supposed to build a Spring Boot product, that's fine. But any dependencies that you pull into the build for that product should be simple JARs (or maybe WARs, depending on how much of JEE Spring Boot employs). I would not expect a Spring Boot module to be able to properly incorporate a second free-standing Spring Boot module inside itself any more than a WAR can be included inside a WAR.
 
sidharth das
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going through an article about spring boot application dependency.
It says beans from dependency will not work by default as spring will not scan packages from dependency.

https://www.quora.com/How-do-I-add-one-Spring-Boot-application-jar-as-a-dependency-to-another-Spring-Boot-application

Thanks,
Sidhartha Das
 
Rob Spoor
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what's @ComponentScan is meant for. By default it will only scan the package the @SpringBootApplication class is in, and its sub packages. @ComponentScan allows you to add any package to the scan list.

If you use @ComponentScan, you will need to explicitly add the @SpringBootApplication class' package as well, because it won't be added automatically anymore.
 
Acetylsalicylic acid is aspirin. This could be handy too:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic