Spring .jar没有启动

时间:2017-09-27 13:23:13

标签: java spring maven spring-boot

当我在IntelliJ中运行我的项目时它工作正常,服务器启动等但是当我构建我的项目(使用maven)并且我想执行.jar文件时我得到了这些错误:

> java.lang.IllegalStateException: Cannot load configuration class:
> at.ennui.backend.facebook.configuration.SocialConfig
>         at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:249)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:281)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:125)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
> ~[spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at at.ennui.backend.EnnuiApplication.main(EnnuiApplication.java:12)
> [classes!/:1.0.0-RELEASE]
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
>         at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144]
>         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE] Caused by:
> java.lang.IllegalStateException: Unable to load cache item
>         at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:79)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:138)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:393)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         ... 20 common frames omitted Caused by: java.lang.NoClassDefFoundError:
> org/springframework/social/facebook/connect/FacebookConnectionFactory
>         at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_144]
>         at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[na:1.8.0_144]
>         at java.lang.Class.getDeclaredConstructors(Unknown Source) ~[na:1.8.0_144]
>         at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:566)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanFactoryAwareGeneratorStrategy.generate(ConfigurationClassEnhancer.java:252)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_144]
>         at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
> ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         ... 28 common frames omitted Caused by: java.lang.ClassNotFoundException:
> org.springframework.social.facebook.connect.FacebookConnectionFactory
>         at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_144]
>         at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_144]
>         at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
> ~[EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_144]
>         ... 42 common frames omitted
> 
> 2017-09-27 15:10:03.076  INFO 6740 --- [           main]
> ationConfigEmbeddedWebApplicationContext : Closing
> org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5afa04c:
> startup date [Wed Sep 27 15:10:01 CEST 2017]; parent:
> org.springframework.context.annotation.AnnotationConfigApplicationContext@20fa23c1
> 2017-09-27 15:10:03.076  WARN 6740 --- [           main]
> ationConfigEmbeddedWebApplicationContext : Exception thrown from
> LifecycleProcessor on context close
> 
> java.lang.IllegalStateException: LifecycleProcessor not initialized -
> call 'refresh' before invoking lifecycle methods via the context:
> org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5afa04c:
> startup date [Wed Sep 27 15:10:01 CEST 2017]; parent:
> org.springframework.context.annotation.AnnotationConfigApplicationContext@20fa23c1
>         at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:427)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:999)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:750)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at at.ennui.backend.EnnuiApplication.main(EnnuiApplication.java:12)
> [classes!/:1.0.0-RELEASE]
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
>         at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144]
>         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
> 
> 2017-09-27 15:10:03.091 ERROR 6740 --- [           main]
> o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with
> name
> 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory'
> threw an exception
> 
> java.lang.IllegalStateException: ApplicationEventMulticaster not
> initialized - call 'refresh' before multicasting events via the
> context:
> org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5afa04c:
> startup date [Wed Sep 27 15:10:01 CEST 2017]; parent:
> org.springframework.context.annotation.AnnotationConfigApplicationContext@20fa23c1
>         at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
> ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
> ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
> [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
> [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
> [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
> [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
> [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
> [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1006)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
> [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
>         at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:750)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
> [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
>         at at.ennui.backend.EnnuiApplication.main(EnnuiApplication.java:12)
> [classes!/:1.0.0-RELEASE]
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
>         at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144]
>         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]
>         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
> [EnnuiBackend-1.0.0-RELEASE.jar:1.0.0-RELEASE]

第一个例外可能是因为在我的SocialConfig类中,我使用“Environment”从application.properties中获取属性,并且没有属性在.jar之外(当它们在jar旁边时也可以获取它) 但我不知道其他例外是​​什么意思......

Application.class:

@SpringBootApplication
public class EnnuiApplication {

    public static void main(String[] args) {
        SpringApplication.run(EnnuiApplication.class, args);
    }

    @Bean
    public ModelMapper modelMapper(){
        return new ModelMapper();
    }
}

SocialConfig.class:

   @Configuration
public class SocialConfig implements SocialConfigurer {

    public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
        cfConfig.addConnectionFactory(new FacebookConnectionFactory(
                env.getProperty("facebook.appId"),
                env.getProperty("facebook.appSecret")));
    }

    @Override
    public UserIdSource getUserIdSource() {
        return null;
    }

    @Override
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
        return null;
    }
}

pom.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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>at.ennui</groupId>
    <artifactId>EnnuiBackend</artifactId>
    <version>1.0.0-RELEASE</version>
    <packaging>jar</packaging>

    <name>EnnuiBackend</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <repositories>
        <repository>
            <id>milestone</id>
            <name>Spring Miestone Repo</name>
            <url>http://repo.spring.io/milestone/</url>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Dalston.SR3</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!--dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-facebook</artifactId>
            <version>3.0.0.M3</version>
        </dependency-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- spring social facebook dependencies-->
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-facebook</artifactId>
            <version>3.0.0.M3</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/spring-social-facebook-3.0.0.M3.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.0.pr3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.0.pr3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.0.pr3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-core</artifactId>
            <version>2.0.0.M4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-config</artifactId>
            <version>2.0.0.M4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-security</artifactId>
            <version>2.0.0.M4</version>
        </dependency>


        <!--                           -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

2 个答案:

答案 0 :(得分:1)

正如JB Nizet指出的那样,问题在于没有提供FacebookConnectionFactory。

目录JAR可以添加到包装中。但是,您应该考虑将依赖项安装到本地Maven存储库并从那里将其提供给项目,而不是将其传递到目录中。

http://roufid.com/3-ways-to-add-local-jar-to-maven-project/

答案 1 :(得分:0)

将JAR手动安装到本地Maven存储库中。

第一个解决方案是使用Maven目标install:install-file将JAR手动添加到本地Maven存储库中。插件的使用非常简单,如下所示:

mvn install:install-file -Dfile=<path-to-file>

请注意,我们没有指定要安装的JAR的groupId,artifactId,版本和包装。实际上,由于Maven-install-plugin的版本为2.5,因此可以从可选的pomFile中获取这些信息。

这些信息也可以在命令行中给出:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version>

位置:

<path-to-file>: Path to the JAR to install
<group-id>: Group id of the JAR to install
<artifact-id>: Artifact id of the JAR to install
<version>:  Version of the JAR

例如:

mvn install:install-file –Dfile=C:\dev\app.jar -DgroupId=com.roufid.tutorials -DartifactId=example-app -Dversion=1.0

然后您可以通过将这些行添加到pom.xml文件中来将依赖项添加到您的Maven项目中:

<dependency>
    <groupId>com.roufid.tutorials</groupId>
    <artifactId>example-app</artifactId>
    <version>1.0</version>
</dependency>

此解决方案可能非常昂贵。为什么?您必须考虑到更改本地Maven存储库的那一天必须重新安装JAR。再或者,如果有很多人在从事该项目,那么每个人都必须在其本地存储库中安装JAR。必须考虑项目的可移植性。

另一种解决方案是在pom.xml中使用maven-install-plugin,这将在Maven“初始化”阶段安装jar。为此,您必须指定要安装的jar的位置。最好的方法是将JAR放在项目根目录下创建的文件夹中(与pom.xml文件位于同一目录中)。