0

I created my first library that I'm trying to import in other project where I'm using maven who build a war file.

First attempt was to include manually the jar as an external jar file in the build path without success...

Then after some google, I discover how to add the library in the maven local repo with the following command:

mvn install:install-file -Dfile=/Users/.../myfile.v1.jar -DgroupId=com.mycompany.app -DartifactId=app -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar

And added in the pom.xml as below

<dependency>
      <groupId>com.mycompany.app</groupId>
      <artifactId>app</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <scope>system</scope>
    <systemPath>/Users/.../myfile.v1.jar</systemPath>
 </dependency>

As I don't get a good success I keep searching and found that I need to add the following plugins

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                        <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <webResources>
                <resource>
                        <directory>/Users/../</directory>
                        <targetPath>BOOT-INF/lib/</targetPath>
                        <!-- <targetPath>WEB_INF/lib/</targetPath> just for none spring-boot project -->
                        <includes>
                            <include>**/*.jar</include>
                        </includes>
                </resource>
            </webResources>
        </configuration>
 </plugin>

But when I try to run the project I get:

java.lang.ClassNotFoundException: com.mycompany.app.myclass

If I run mvn clean package I get:

Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Unable to find main class

any help?

Let me add that in my app (the one I'm trying to import) there isn't any main method and it's not using sprintboot.

Edit Adding both POMs

pom.xml from my com.mycompany.app

<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.mycompany.app</groupId>
  <artifactId>app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.1</version>
        </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>commons-discovery</groupId>
        <artifactId>commons-discovery</artifactId>
        <version>0.5</version>
    </dependency>
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.3</version>
    </dependency>
    <dependency>
        <groupId>jaxen</groupId>
        <artifactId>jaxen</artifactId>
        <version>1.1.6</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.rpc</groupId>
        <artifactId>javax.xml.rpc-api</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
        <version>1.47</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpkix-jdk15on</artifactId>
        <version>1.47</version>
    </dependency>
    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.rpc</groupId>
        <artifactId>javax.xml.rpc-api</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.5.0-M1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.5.0-M1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.5.0-M1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.3.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
  </dependencies>
</project>

pom.xml from the app that is trying to implement the com.mycompany.app project

<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>com.mycompany.main</groupId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>mycompany_app</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.3.RELEASE</version>
        <relativePath/>
    </parent>

    <url>http://maven.apache.org</url>
    <properties>
        <spring.version>4.2.4.RELEASE</spring.version>
        <spring-security.version>4.0.3.RELEASE</spring-security.version>
        <hibernate.version>5.0.6.Final</hibernate.version>
        <log4j.version>2.5</log4j.version>
        <jjwt.version>0.6.0</jjwt.version>
        <jdk.version>1.8</jdk.version>
        <context.path>mycompany_app</context.path>
    </properties>
    <profiles>
    <profile>
        <id>test</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources/properties/default</directory>
                </resource>
                <resource>
                    <directory>src/main/resources/properties/test</directory>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>dev</id>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources/properties/default</directory>
                </resource>
                <resource>
                    <directory>src/main/resources/properties/dev</directory>
                </resource>
            </resources>
        </build>
    </profile>
</profiles>
    <build>
        <finalName>ws</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <dependencies>
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>pdfbox</artifactId>
    <version>2.0.4</version>
</dependency>
<dependency>
      <groupId>com.mycompany.app</groupId>
      <artifactId>app</artifactId>
      <version>0.0.1-SNAPSHOT</version>
 </dependency>
<dependency>
    <groupId>jaxen</groupId>
    <artifactId>jaxen</artifactId>
    <version>1.1.6</version>
</dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.47</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk15on</artifactId>
            <version>1.47</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.rpc</groupId>
            <artifactId>javax.xml.rpc-api</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.5</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.18</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>${jjwt.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>${hibernate.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>javax.transaction</groupId>
          <artifactId>jta</artifactId>
          <version>1.1</version>
      </dependency>
<dependency>
    <groupId>wsdl4j</groupId>
    <artifactId>wsdl4j</artifactId>
    <version>1.6.3</version>
</dependency>
      <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
      <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.4</version>
    </dependency>
      <dependency>
       <groupId>commons-fileupload</groupId>
       <artifactId>commons-fileupload</artifactId>
       <version>1.2.1</version> 
    </dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
</dependency>
    </dependencies>
    <artifactId>api</artifactId>
</project>

Full stacktrace Some comments: com.mycompany.main is the main project, the parent com.mycompany.app is the children, the dependency I'm trying to implement in the main.

GRAVE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'saleController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.main.services.SaleService com.mycompany.main.controller.SaleController.saleService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'saleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.main.services.invoiceService com.mycompany.main.services.SaleServiceImpl.invoiceService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoiceServiceImpl' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Post-processing failed of bean type [class com.mycompany.main.services.invoiceServiceImpl] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.mycompany.main.services.invoiceServiceImpl] for persistence metadata: could not find class that it depends on
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.main.services.SaleService com.mycompany.main.controller.SaleController.saleService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'saleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.main.services.invoiceService com.mycompany.main.services.SaleServiceImpl.invoiceService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoiceServiceImpl' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Post-processing failed of bean type [class com.mycompany.main.services.invoiceServiceImpl] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.mycompany.main.services.invoiceServiceImpl] for persistence metadata: could not find class that it depends on
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 29 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'saleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.main.services.invoiceService com.mycompany.main.services.SaleServiceImpl.invoiceService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoiceServiceImpl' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Post-processing failed of bean type [class com.mycompany.main.services.invoiceServiceImpl] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.mycompany.main.services.invoiceServiceImpl] for persistence metadata: could not find class that it depends on
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.main.services.invoiceService com.mycompany.main.services.SaleServiceImpl.invoiceService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoiceServiceImpl' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Post-processing failed of bean type [class com.mycompany.main.services.invoiceServiceImpl] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.mycompany.main.services.invoiceServiceImpl] for persistence metadata: could not find class that it depends on
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 42 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'invoiceServiceImpl' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Post-processing failed of bean type [class com.mycompany.main.services.invoiceServiceImpl] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.mycompany.main.services.invoiceServiceImpl] for persistence metadata: could not find class that it depends on
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:940)
    ... 44 more
Caused by: java.lang.IllegalStateException: Failed to introspect bean class [com.mycompany.main.services.invoiceServiceImpl] for persistence metadata: could not find class that it depends on

    ... 54 more
Caused by: java.lang.NoClassDefFoundError: Lcom/mycompany/app/bo/LoginData;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:710)
    at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:652)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:413)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:392)
    ... 56 more
Caused by: java.lang.ClassNotFoundException: com.mycompany.app.bo.LoginData
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1136)
    ... 63 more

jun 06, 2019 9:06:42 AM org.apache.catalina.core.StandardContext loadOnStartup
GRAVE: Servlet [mvc-dispatcher] in web application [/api] threw load() exception
java.lang.ClassNotFoundException: com.mycompany.app.bo.LoginData
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
    at ...

jun 06, 2019 9:06:42 AM org.apache.coyote.AbstractProtocol start
INFORMACIÓN: Starting ProtocolHandler ["http-nio-8080"]
jun 06, 2019 9:06:42 AM org.apache.coyote.AbstractProtocol start
INFORMACIÓN: Starting ProtocolHandler ["ajp-nio-8009"]
jun 06, 2019 9:06:42 AM org.apache.catalina.startup.Catalina start
INFORMACIÓN: Server startup in 14004 ms
jun 06, 2019 9:06:43 AM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet [jsp] lanzó excepción
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Faabass
  • 1,396
  • 4
  • 23
  • 41

2 Answers2

1

First you should learn how to use Maven: https://maven.apache.org/

But to solve your problem:

You installed the dependency in your local repository. So the dependency in your pom.xml must look like this:

<dependency>
  <groupId>com.mycompany.app</groupId>
  <artifactId>app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</dependency>

And the plugin is simply:

<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

That's all. Maven will include your dependency by default.

Simon Martinelli
  • 21,335
  • 3
  • 26
  • 53
  • No.. I keeps getting NoClassDefFoundError message. In the code it seems good, as I have access to the classes and that doesn't generate any error. But when I try to run the project I get this error. – Faabass Jun 06 '19 at 11:12
  • myclass is a class inside the external jar. That I'm trying to access from the other app in which I add the dependency and plugin as you mention and then I imported with `import com.mycompany.app.myclass;` (which is recognized by eclipse) and also I can use it in the code – Faabass Jun 06 '19 at 11:18
  • And myclass is annotated with @SpringBootApplication? – Simon Martinelli Jun 06 '19 at 11:19
  • No... app is a maven project from scratch (as it's not so complex) that I'm exporting as Jar file and it doesn't have any main method. I have some classes there that I can instantiate and start working sending information to get a result. But it's not an spring project (the one where I'm adding that jar It is) – Faabass Jun 06 '19 at 11:25
  • How does the pom.xml now look like of the project you have the main class? – Simon Martinelli Jun 06 '19 at 11:27
  • I added both pom files. sorry for the long post – Faabass Jun 06 '19 at 11:35
  • I'm sorry to ask but why do you have so many dependenices declared? Many of them already come with Spring Boot or one of it's starter projects. But anyway. Can you run the app when you run the main class? – Simon Martinelli Jun 06 '19 at 11:46
  • Yeah, I know... I have to do some clean up to the dependencies... About your cuestion the main class (the parent project) after I added the dependency to the other project it stop working, when I tried to run it, it tells me `NoClassDefFoundError ` The 'children' project (the one I'm trying to import in the other one) doesn't have any main method, but I tested using Unit test and it is working fine – Faabass Jun 06 '19 at 11:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194540/discussion-between-simon-martinelli-and-faabass). – Simon Martinelli Jun 06 '19 at 12:19
  • One more question... When I add the library without maven (just adding with the Properties -> Java Build Path option) and try to run the app I get a lot of errors as if spring cannot instantiate all the @Autowired classes and this happens when the spring-config.xml file is not correctly updated. Could be that I need to explain in any way to Spring that I'm adding a jar file? Because as far as I can imagine, in this way there shouldn't be any error... – Faabass Jun 07 '19 at 01:46
  • You shouldn't do that with a maven project – Simon Martinelli Jun 07 '19 at 06:22
  • My issue was related to how to generate the library project, so what Simon Martinelli said was fine! To see the real issue see https://stackoverflow.com/questions/56497449/get-noclassdeffounderror-when-implementing-own-jar/56529980#56529980 – Faabass Jun 10 '19 at 16:17
0

this has already been answered here How to add local jar files to a Maven project?. also you can take a look at this http://roufid.com/3-ways-to-add-local-jar-to-maven-project/

Goozo
  • 806
  • 2
  • 10
  • 26