是否可以从我自己的一个JAR中使用API,而不包括它的依赖关系?
我创建了一个独立的maven项目(A),它是一个API模块,它使用许多第三方jar,应该在多个项目中使用。但是在一个Spring boot项目(B)中,由于A引入了它的依赖项,Spring boot项目不能很好地工作。
如果从pom中排除了A,那么spring boot工作得很好。但我确实需要它的几个API。我该如何解决这个问题?
一开始,一切都很顺利。它是一个纯粹的控制台应用程序。Pom类似于下面的内容。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
-->
<!--
<dependency>
<groupId>InsuranceWrapper</groupId>
<artifactId>InsuranceWrapper</artifactId>
<version>1.0</version>
</dependency>
-->
</dependencies>
然后我向它添加InsuranceWrapper,它将有一个错误。
java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$TransactionManagementConfiguration due to org/springframework/web/servlet/view/freemarker/FreeMarkerConfigurer not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55) ~[spring-boot-autoconfigure-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/view/freemarker/FreeMarkerConfigurer
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_45]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_45]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_45]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_45]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_45]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_45]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_45]
... 38 common frames omitted
然后我想Spring boot可能认为我是一个Web项目。所以我添加了Spring boot web。现在又出现了一个错误。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:99) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
搜索了这些错误,没有任何线索。我的A项目是一个复杂的spring hibernate项目。这就是为什么我问这个问题,只是想为B提供一个干净的环境,同时使用a中的几个API。
更新
添加sping-boot-starter-freemarker以修复第一个错误
更新
更新mvn树
[INFO] net.ebaolife:EBTasks:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.3.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:1.3.1.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:4.2.4.RELEASE:compile
[INFO] | | \- org.springframework:spring-expression:jar:4.2.4.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.1.RELEASE:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.7:compile
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.7:compile
[INFO] | | \- org.slf4j:log4j-over-slf4j:jar:1.7.7:compile
[INFO] | +- org.springframework:spring-core:jar:4.2.4.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.16:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-freemarker:jar:1.3.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-web:jar:1.3.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.1.RELEASE:compile
[INFO] | | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.30:compile
[INFO] | | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.30:compile
[INFO] | | | +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.30:compile
[INFO] | | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.30:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.1.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.4:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.4:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-core:jar:2.6.4:compile
[INFO] | | +- org.springframework:spring-web:jar:4.2.4.RELEASE:compile
[INFO] | | \- org.springframework:spring-webmvc:jar:4.2.4.RELEASE:compile
[INFO] | +- org.freemarker:freemarker:jar:2.3.23:compile
[INFO] | \- org.springframework:spring-context-support:jar:4.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-beans:jar:4.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.3.1.RELEASE:compile
[INFO] | +- org.apache.tomcat:tomcat-jdbc:jar:8.0.30:compile
[INFO] | | \- org.apache.tomcat:tomcat-juli:jar:8.0.30:compile
[INFO] | \- org.springframework:spring-jdbc:jar:4.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:4.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.3.1.RELEASE:test
[INFO] | +- junit:junit:jar:4.12:compile
[INFO] | +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | | \- org.objenesis:objenesis:jar:2.1:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] | \- org.springframework:spring-test:jar:4.2.4.RELEASE:test
[INFO] +- com.dangdang:elastic-job-core:jar:1.0.2:compile
[INFO] | +- org.projectlombok:lombok:jar:1.16.4:compile
[INFO] | +- com.google.guava:guava:jar:18.0:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] | | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | +- org.quartz-scheduler:quartz:jar:2.2.1:compile
[INFO] | | +- c3p0:c3p0:jar:0.9.1.1:compile
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] | +- org.apache.curator:curator-framework:jar:2.8.0:compile
[INFO] | | \- org.apache.zookeeper:zookeeper:jar:3.4.6:compile
[INFO] | | +- log4j:log4j:jar:1.2.17:compile
[INFO] | | +- jline:jline:jar:0.9.94:compile
[INFO] | | \- io.netty:netty:jar:3.7.0.Final:compile
[INFO] | +- org.apache.curator:curator-client:jar:2.8.0:compile
[INFO] | \- org.apache.curator:curator-recipes:jar:2.8.0:compile
[INFO] +- com.dangdang:elastic-job-spring:jar:1.0.2:compile
[INFO] +- org.mybatis:mybatis:jar:3.2.8:compile
[INFO] +- org.mybatis:mybatis-spring:jar:1.2.2:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.38:compile
[INFO] +- org.mongodb.morphia:morphia:jar:1.1.0:compile
[INFO] | +- org.mongodb:mongo-java-driver:jar:2.13.3:compile
[INFO] | +- com.thoughtworks.proxytoys:proxytoys:jar:1.0:compile
[INFO] | \- cglib:cglib-nodep:jar:2.2.2:compile
[INFO] +- eu.bitwalker:UserAgentUtils:jar:1.18:compile
[INFO] \- InsuranceWrapper:InsuranceWrapper:jar:1.0:compile
[INFO] +- ebcore:ebcore:jar:1.0:compile
[INFO] | +- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] | +- org.apache.commons:commons-dbcp2:jar:2.1.1:compile
[INFO] | | \- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] | +- org.jdom:jdom:jar:1.1:compile
[INFO] | +- org.jdom:jdom2:jar:2.0.6:compile
[INFO] | +- commons-pool:commons-pool:jar:1.6:compile
[INFO] | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-aop:jar:4.2.4.RELEASE:compile
[INFO] | +- org.springframework:spring-orm:jar:4.2.4.RELEASE:compile
[INFO] | +- org.acegisecurity:acegi-security:jar:1.0.7:compile
[INFO] | | +- org.springframework:spring-remoting:jar:1.2.9:compile
[INFO] | | +- org.springframework:spring-support:jar:1.2.9:runtime
[INFO] | | \- commons-lang:commons-lang:jar:2.1:compile
[INFO] | +- com.aliyun.openservices:aliyun-openservices:jar:1.2.2:compile
[INFO] | | \- com.google.protobuf:protobuf-java:jar:2.4.1:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.apache.ant:ant:jar:1.9.4:compile
[INFO] | | \- org.apache.ant:ant-launcher:jar:1.9.4:compile
[INFO] | +- asm:asm-attrs:jar:1.5.3:compile
[INFO] | +- asm:asm:jar:3.1:compile
[INFO] | +- org.aspectj:aspectjrt:jar:1.8.7:compile
[INFO] | +- aspectj:aspectjweaver:jar:1.5.3:compile
[INFO] | +- org.glassfish.hk2.external:cglib:jar:2.1.3:compile
[INFO] | +- org.cometd.java:cometd-api:jar:1.0.beta8:compile
[INFO] | +- org.mortbay.jetty:cometd-server:jar:6.1.17:compile
[INFO] | | \- org.mortbay.jetty:jetty-util5:jar:6.1.17:compile
[INFO] | +- commons-discovery:commons-discovery:jar:0.2:compile
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3:compile
[INFO] | | \- commons-io:commons-io:jar:2.2:compile
[INFO] | +- com.hynnet:commons-lang3:jar:3.3.2:compile
[INFO] | +- commons-net:commons-net:jar:3.3:compile
[INFO] | +- org.xhtmlrenderer:core-renderer:jar:R8:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | +- org.directwebremoting:dwr:jar:2.0.3:compile
[INFO] | +- net.sf.ehcache:ehcache:jar:2.10.1:compile
[INFO] | +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[INFO] | +- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] | +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] | | +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
[INFO] | | \- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] | | \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] | | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] | | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | +- org.hibernate:hibernate-search:jar:3.1.0.GA:compile
[INFO] | | \- org.apache.lucene:lucene-core:jar:2.4.0:compile
[INFO] | +- org.hibernate:hibernate-tools:jar:3.2.4.GA:compile
[INFO] | | +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] | | \- org.hibernate:jtidy:jar:r8-20060801:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] | +- oro:oro:jar:2.0.8:compile
[INFO] | +- javassist:javassist:jar:3.11.0.GA:compile
[INFO] | +- jaxen:jaxen:jar:1.1.6:compile
[INFO] | +- axis:axis-jaxrpc:jar:1.3:compile
[INFO] | +- jboss:jboss-archive-browsing:jar:2.0.2.alpha:compile
[INFO] | +- com.jcraft:jsch:jar:0.1.51:compile
[INFO] | +- org.json:json:jar:20140107:compile
[INFO] | +- javax.servlet:jstl:jar:1.2:compile
[INFO] | +- javax.transaction:jta:jar:1.1:compile
[INFO] | +- net.sourceforge.jexcelapi:jxl:jar:2.6.10:compile
[INFO] | +- com.sun.mail:javax.mail:jar:1.5.4:compile
[INFO] | +- ognl:ognl:jar:3.0.6:compile
[INFO] | +- jsptags:pager-taglib:jar:2.0:compile
[INFO] | +- com.belerweb:pinyin4j:jar:2.5.0:compile
[INFO] | +- org.apache.poi:poi:jar:3.12:compile
[INFO] | +- org.apache.poi:poi-scratchpad:jar:3.12:compile
[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] | +- com.google.code.simple-spring-memcached:spymemcached:jar:2.8.4:compile
[INFO] | +- taglibs:standard:jar:1.1.2:compile
[INFO] | +- org.apache.struts:struts2-core:jar:2.3.24.1:compile
[INFO] | | \- org.apache.struts.xwork:xwork-core:jar:2.3.24.1:compile
[INFO] | | \- asm:asm-commons:jar:3.3:compile
[INFO] | | \- asm:asm-tree:jar:3.3:compile
[INFO] | +- org.apache.struts:struts2-json-plugin:jar:2.3.24.1:compile
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.2:compile
[INFO] | +- org.apache.struts:struts2-spring-plugin:jar:2.3.24.1:compile
[INFO] | +- redis.clients:jedis:jar:2.7.3:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.5.1:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.4.4:compile
[INFO] | +- ebao:tk-filters:jar:1.0:compile
[INFO] | +- ebao:flexjson:jar:1.0:compile
[INFO] | +- ebao:QRCode:jar:1.0:compile
[INFO] | +- ebao:java_memcached:jar:release_2.6.6:compile
[INFO] | +- ebao:jbarcode:jar:0.2.8:compile
[INFO] | +- ebao:jdbc2.0:jar:stdext:compile
[INFO] | \- ebao:lylab:jar:1.0:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- ebao:cxf:jar:2.3.3:compile
[INFO] +- com.google.code.findbugs:jsr305:jar:3.0.0:compile
[INFO] +- org.apache.ws.commons.schema:XmlSchema:jar:1.4.7:compile
[INFO] +- org.apache.axis:axis:jar:1.4:compile
[INFO] +- org.codehaus.xfire:xfire-core:jar:1.2.6:compile
[INFO] | +- javax.activation:activation:jar:1.1:compile
[INFO] | +- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] | +- stax:stax-api:jar:1.0.1:compile
[INFO] | +- commons-codec:commons-codec:jar:1.3:compile
[INFO] | +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:compile
[INFO] | +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] | \- commons-httpclient:commons-httpclient:jar:3.0:compile
[INFO] +- org.codehaus.xfire:xfire-aegis:jar:1.2.6:compile
[INFO] | \- net.java.dev.stax-utils:stax-utils:jar:20040917:compile
[INFO] +- org.codehaus.xfire:xfire-java5:jar:1.2.6:compile
[INFO] | +- org.codehaus.xfire:xfire-annotations:jar:1.2.6:compile
[INFO] | | \- commons-attributes:commons-attributes-api:jar:2.1:compile
[INFO] | | \- qdox:qdox:jar:1.5:compile
[INFO] | \- xfire:xfire-jsr181-api:jar:1.0-M1:compile
[INFO] \- org.codehaus.xfire:xfire-xmlbeans:jar:1.2.6:compile
[INFO] \- xmlbeans:xbean:jar:2.2.0:compile
更新
添加以下两个排除项,现在没有错误。
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
但既然包含了spring web。。它会从后面启动一只雄猫,这很烦人。。
更新
由于任何Spring web都会让Spring boot认为它现在是一个Web项目,因此最终所有的Spring web都被删除了。并且sping-boot-starter-freemarker也被删除了,因为它实际上并没有被使用。
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>freemarker</artifactId>
<groupId>org.freemarker</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>struts2-spring-plugin</artifactId>
<groupId>org.apache.struts</groupId>
</exclusion>
</exclusions>
现在一切都好了。。
要从jar/目标目录中排除任何文件,您可以使用
在下一个示例中,将不包括扩展名为
. properties
的所有文件:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
</build>
也看看这个
<dependencies>
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
<artifactId>Project-E</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
我是Hadoop的新手。我已将Gson API添加到我的Map减少程序中。当我运行程序获取时; 有谁能建议我如何向Hadoop添加第三方库吗?
问题内容: 我是现代JS开发的新手,因此我需要有关此情况的帮助或建议。 情况: 我们有一个支持IE8(React 0.14)的React-Typescript-Redux项目。现在我们要升级到IE11和React 16,但应该支持IE8。 要求: 通过为每个构建使用不同的软件包和/或配置文件,减少浏览器版本之间的项目维护。 问题: 根据我到目前为止所做的研究,似乎无法通过选定的工具(npm,Web
本文向大家介绍Android Studio 在项目中引用第三方jar包的方法,包括了Android Studio 在项目中引用第三方jar包的方法的使用技巧和注意事项,需要的朋友参考一下 在Android Studio项目中引用第三方jar包的方法: 步骤: 1、在build.gradle文件中添加如下代码: 备注:要添加在Android作用域下 点击【Sync Now】,会生成jniLibs文件
如果我有一个抽象类 像这样: 一些类扩展了这个类。 在同一项目中,我可以在派生类的cpp文件中实现函数,但当我想在同一解决方案中的另一个项目中使用该类时,我得到一个链接器错误
我有一个Maven项目,包含几个模块,其结构类似于: 我已经在parent在
我在Eclipse中有一个spring boot项目。我在项目构建路径中添加了一个外部第三方jar,它不是maven依赖项。现在,我可以从我需要的jar中导入2个类,并编写了一些实现。现在,当我试图用构建maven项目时,我使用的2个导入程序编译失败。错误显示:包不存在。 我在配置部分遗漏了什么吗?我已经在项目构建路径中将jar添加为外部jar。然后我已经清洁编译了项目。在由maven构建的spr