Java 在Tomcat'中找不到带有JAR的类;s库目录
我可能遗漏了一些非常明显的东西,或者情况非常奇怪: 我有一个Ant构建文件来编译一组类,然后将这些类及其依赖项打包到uber jar中。它工作得非常好,生成的jar保存在TOMCAT/lib目录中,TOMCAT启动也非常好 现在,大约3天前,我添加了Bouncy Castle 1.52依赖项,之后构建文件创建了jar,它保存在TOMCAT/lib中,在TOMCAT启动期间,我得到了非常持久的ClassNotFoundError,而类实际上在jar文件中,它在TOMCAT/lib中 我无法理解这种情况,是JAR文件在构建过程中被破坏了,还是uber jarred的类不兼容 当我从eclipse导出一个“runnable jar”时,上述问题就不会发生 我在下面给出Ant构建文件:Java 在Tomcat'中找不到带有JAR的类;s库目录,java,tomcat,ant,jar,Java,Tomcat,Ant,Jar,我可能遗漏了一些非常明显的东西,或者情况非常奇怪: 我有一个Ant构建文件来编译一组类,然后将这些类及其依赖项打包到uber jar中。它工作得非常好,生成的jar保存在TOMCAT/lib目录中,TOMCAT启动也非常好 现在,大约3天前,我添加了Bouncy Castle 1.52依赖项,之后构建文件创建了jar,它保存在TOMCAT/lib中,在TOMCAT启动期间,我得到了非常持久的ClassNotFoundError,而类实际上在jar文件中,它在TOMCAT/lib中 我无法理解这种
<?xml version="1.0" encoding="UTF-8"?>
<project name="PLATFORM_BUILD"
default="buildJAR"
basedir="E:\generalJunk\build\platform\vampire"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<property name="build.name" value="vampire"/>
<property name="base.dir" value="E:\generalJunk\build\platform\vampire"/>
<property name="src.dir" location="src"/>
<property name="classes.dir" location="classes"/>
<property name="jar.dir" location="jar"/>
<property name="lib.dir" location="lib"/>
<property name="lib.staging.dir" location="lib\STAGED_LIBS"/>
<property name="svn.repo.url" value="value_of_the_url_removed"/>
<path id="maven-ant-tasks.classpath" path="E:\install\apache_ant\maven-ant-tasks-2.1.3.jar"/>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
<target name='clean'>
<echoproperties/>
<delete dir="${src.dir}"/>
<delete dir="${classes.dir}"/>
<delete dir="${jar.dir}"/>
<delete dir="${lib.staging.dir}"/>
</target>
<target name="svnExport" depends="clean">
<exec executable="svn">
<arg line="export --username removed --password removed ${svn.repo.url}/dev/trunk/core/src@HEAD ${src.dir}"/>
</exec>
</target>
<target name="getDependencies" depends="svnExport">
<mkdir dir="${lib.dir}"/>
<mkdir dir="${lib.staging.dir}"/>
<artifact:dependencies pathId="dependency.classpath">
<!-- All downloaded dependency JARs will be stored here, this is the local repository -->
<localrepository path="${lib.dir}"/>
<!-- =========================== Apache Commons Libraries ======================= -->
<dependency groupId="log4j" artifactid="log4j" version="1.2.17"/>
<dependency groupId="org.slf4j" artifactid="slf4j-api" version="1.7.12"/>
<dependency groupId="org.slf4j" artifactid="slf4j-log4j12" version="1.7.12"/>
<dependency groupId="commons-logging" artifactid="commons-logging" version="1.2"/>
<dependency groupId="commons-io" artifactid="commons-io" version="2.4"/>
<dependency groupId="org.apache.commons" artifactid="commons-pool2" version="2.4.1"/>
<dependency groupId="org.apache.commons" artifactid="commons-lang3" version="3.4"/>
<dependency groupId="org.apache.commons" artifactid="commons-dbcp2" version="2.1">
<exclusion groupId="commons-logging" artifactid="commons-logging"/>
<exclusion groupId="org.apache.commons" artifactid="commons-pool2"/>
</dependency>
<dependency groupId="commons-codec" artifactid="commons-codec" version="1.10"/>
<dependency groupId="org.apache.httpcomponents" artifactid="httpclient" version="4.5.1">
<exclusion groupId="commons-codec" artifactid="commons-codec"/>
<exclusion groupId="commons-logging" artifactid="commons-logging"/>
</dependency>
<dependency groupId="commons-collections" artifactid="commons-collections" version="3.2.1"/>
<dependency groupId="commons-beanutils" artifactid="commons-beanutils" version="1.9.2">
<exclusion groupId="commons-logging" artifactid="commons-logging"/>
<exclusion groupId="commons-collections" artifactid="commons-collections"/>
</dependency>
<dependency groupId="commons-pool" artifactid="commons-pool" version="1.6"/>
<dependency groupId="org.apache.commons" artifactid="commons-email" version="1.4">
<exclusion groupId="javax.mail" artifactid="javax.mail-api"/>
</dependency>
<!-- ============================================================================ -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Apache LDAP API ================================ -->
<!--<dependency groupId="org.apache.directory.api" artifactid="api-ldap-client-api" version="1.0.0-M30">
<exclusion groupId="org.slf4j" artifactId="slf4j-api"/>
<exclusion groupId="org.slf4j" artifactId="slf4j-log4j12"/>
</dependency>-->
<dependency groupId="org.apache.directory.api" artifactid="api-all" version="1.0.0-M30">
<exclusion groupId="org.slf4j" artifactId="slf4j-api"/>
<exclusion groupId="org.slf4j" artifactId="slf4j-log4j12"/>
<exclusion groupId="commons-io" artifactid="commons-io"/>
<exclusion groupId="commons-collections" artifactid="commons-collections"/>
<exclusion groupId="commons-lang" artifactid="commons-lang"/>
<exclusion groupId="commons-pool" artifactid="commons-pool"/>
</dependency>
<!-- ============================================================================ -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== OpenCSV ========================================= -->
<dependency groupId="com.opencsv" artifactid="opencsv" version="3.4"/>
<!-- ============================================================================= -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Apache Zookeeper ================================ -->
<dependency groupId="org.apache.zookeeper" artifactid="zookeeper" version="3.4.6">
<exclusion groupId="org.slf4j" artifactId="slf4j-api"/>
<exclusion groupId="org.slf4j" artifactId="slf4j-log4j12"/>
<exclusion groupId="log4j" artifactid="log4j"/>
</dependency>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Java Mail API ==================================== -->
<!--<dependency groupId="javax.mail" artifactid="mail" version="1.4.7"/>-->
<dependency groupId="javax.mail" artifactid="javax.mail-api" version="1.5.4"/>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Apache Curator =================================== -->
<dependency groupId="org.apache.curator" artifactid="curator-client" version="2.8.0">
<exclusion groupId="org.slf4j" artifactId="slf4j-api"/>
</dependency>
<dependency groupId="org.apache.curator" artifactid="curator-framework" version="2.8.0">
<exclusion groupId="org.apache.curator" artifactId="curator-client"/>
</dependency>
<dependency groupId="org.apache.curator" artifactid="curator-recipes" version="2.8.0">
<exclusion groupId="org.apache.curator" artifactId="curator-framework"/>
</dependency>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Hazelcast ======================================== -->
<!--<dependency groupId="com.hazelcast" artifactid="hazelcast" version="3.4.2">-->
<dependency groupId="com.hazelcast" artifactid="hazelcast" version="3.5">
<exclusion groupId="org.slf4j" artifactId="slf4j-api"/>
<exclusion groupId="org.slf4j" artifactId="slf4j-log4j12"/>
<exclusion groupId="log4j" artifactid="log4j"/>
<exclusion groupId="org.apache.logging.log4j" artifactid="log4j-api"/>
<exclusion groupId="org.apache.logging.log4j" artifactid="log4j-core"/>
<exclusion groupId="org.codehaus.groovy" artifactid="groovy-all"/>
<exclusion groupId="org.jruby" artifactid="jruby-complete"/>
<exclusion groupId="org.osgi" artifactid="org.osgi.core"/>
</dependency>
<!--<dependency groupId="com.hazelcast" artifactid="hazelcast-client" version="3.4.2">-->
<!--<dependency groupId="com.hazelcast" artifactid="hazelcast-client-new" version="3.5">-->
<dependency groupId="com.hazelcast" artifactid="hazelcast-client" version="3.5">
<exclusion groupId="com.hazelcast" artifactid="hazelcast"/>
</dependency>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Antler String Template =========================== -->
<dependency groupId="org.antlr" artifactid="antlr-runtime" version="3.5.2">
<exclusion groupId="org.antlr" artifactid="ST4"/>
</dependency>
<dependency groupId="org.antlr" artifactid="ST4" version="4.0.8"/>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Apache BVal ====================================== -->
<dependency groupId="javax.validation" artifactid="validation-api" version="1.1.0.Final"/>
<dependency groupId="org.apache.bval" artifactid="bval-jsr303" version="0.5">
<exclusion groupId="org.apache.commons" artifactid="commons-lang3"/>
</dependency>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- =========================== Sardine WebDav Client ============================ -->
<dependency groupId="com.github.lookfirst" artifactid="sardine" version="5.4">
<exclusion groupId="org.apache.httpcomponents" artifactid="httpclient"/>
<exclusion groupId="org.slf4j" artifactId="slf4j-api"/>
</dependency>
<!-- ============================================================================== -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- ================================== graylog - syslog4j ======================== -->
<dependency groupId="org.graylog2" artifactid="syslog4j" version="0.9.53"/>
<!-- ============================================================================== -->
<!-- ================================== Bouncy Castle 1.52 ======================== -->
<dependency groupId="org.bouncycastle" artifactid="bcprov-jdk15on" version="1.52"/>
<dependency groupId="org.bouncycastle" artifactid="bcprov-ext-jdk15on" version="1.52"/>
<dependency groupId="org.bouncycastle" artifactid="bcmail-jdk15on" version="1.52"/>
<dependency groupId="org.bouncycastle" artifactid="bcpg-jdk15on" version="1.52"/>
<dependency groupId="org.bouncycastle" artifactid="bcpkix-jdk15on" version="1.52"/>
<!-- ============================================================================== -->
</artifact:dependencies>
<pathconvert property="maven.converted.classpath" refid="dependency.classpath"/>
<echo>${classpathProp}</echo>
<copy todir="${lib.staging.dir}" flatten="true">
<path refid="dependency.classpath" />
</copy>
</target>
<target name="compile" depends="getDependencies">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}">
<classpath refid="dependency.classpath"/>
</javac>
</target>
<target name="buildJAR" depends="compile">
<mkdir dir="${jar.dir}"/>
<fileset id="lib.file.set" dir="${lib.staging.dir}" includes="*.jar"/>
<jar destfile="${jar.dir}\vp_platform_core.jar"
filesetmanifest="mergewithoutmain"
duplicate="preserve">
<manifest>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${classes.dir}"/>
<fileset dir="${src.dir}\resources" includes="properties/**" />
<zipgroupfileset refid="lib.file.set"/>
</jar>
</target>
<!-- deploy-task for creating and writing a temporary pom-file and deploying the artifact beside this pom-file -->
<!-- CURRENTLY NOT USED-->
<!--<target name="deploy">
<artifact:pom id="tmp.pom" groupid="${artifact.group}" artifactid="${artifact.name}" version="${artifact.version}" packaging="${artifact.type}" name="${artifact.name}" />
<artifact:writepom pomRefId="tmp.pom" file="${artifact.pom}"/>
<artifact:deploy file="${build.dir}/${artifact.name}-${artifact.version}.${artifact.type}">
<remoteRepository url="${remote.repo.url}">
<authentication username="${remote.repo.username}" password="${remote.repo.password}" />
</remoteRepository>
<attach file="${build.dir}/${artifact.name}-${artifact.version}-dev.properties" classifier="config-dev" type="properties"/>
<attach file="${build.dir}/${artifact.name}-${artifact.version}-prod.properties" classifier="config-prod" type="properties"/>
<attach file="${build.dir}/${artifact.name}-${artifact.version}-test.properties" classifier="config-test" type="properties"/>
<pom file="${artifact.pom}" />
</artifact:deploy>
</target>-->
下面是反编译类的屏幕截图:
public class DistributedCacheManagerFactory implements ObjectFactory {
protected static DistributedCacheManager distributedCacheManager;
static{
distributedCacheManager=DistributedCacheManager.getDistributedCacheManager();
}//static block closing
@Override
public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3) throws Exception {
return distributedCacheManager;
}//getObjectInstance closing
下面是反编译类的源代码:
public class DistributedCacheManagerFactory implements ObjectFactory {
protected static DistributedCacheManager distributedCacheManager;
static{
distributedCacheManager=DistributedCacheManager.getDistributedCacheManager();
}//static block closing
@Override
public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3) throws Exception {
return distributedCacheManager;
}//getObjectInstance closing
公共类DistributedCacheManagerFactory实现ObjectFactory{
受保护的静态DistributedCacheManager DistributedCacheManager;
静止的{
distributedCacheManager=distributedCacheManager.getDistributedCacheManager();
}//静态闭塞
@凌驾
公共对象getObjectInstance(对象arg0、名称arg1、上下文arg2、哈希表arg3)引发异常{
返回分布式缓存管理器;
}//getObjectInstance关闭
}//类关闭堆栈跟踪?还有,找不到哪个类?@ChristopherSchultz,编辑了上面的文章,在启动时,所有Tomcat资源工厂都找不到。使用JAD来反编译eclipse生成的类,输出看起来是一样的。此外,在构建过程结束后,在jaring之前对类进行反编译,结果看起来是一样的。您可以使用
jar
解压.jar
文件吗?事实上,7-Zip可以处理该文件并不重要。@ChristopherSchultz,我使用了windows命令提示符“jar-ie:\generalJunk\build\platform\vampire\jar\vp\u platform\u core.jar”中的以下命令,并尝试用“-t”列出jar的内容,命令挂起。看起来“jar”无法打开归档文件,您的观察结果非常好。