在Tomcat的lib目录中使用JAR的ClassNotFound

时间:2015-09-22 13:14:17

标签: java tomcat ant jar

我可能会遗漏一些非常明显或情况非常奇怪的事情:

我有一个Ant构建文件来编译一组类,然后将类及其依赖项打包在一个超级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构建文件:

<?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>-->

请求帮助解决此问题。

感谢

-------------------------------编辑回应克里斯托弗----------- -

我可以用7-zip打开超级jar,我也可以用JAD-UI反编译类。但是(我不知道它是否是JAD-UI 1.4.0的问题,很可能不是),反编译源看起来很奇怪。

首先,这是堆栈跟踪:

 23-Sep-2015 09:56:46.414 WARNING [Thread-6] org.apache.catalina.deploy.NamingResourcesImpl.cleanUp Failed to retrieve JNDI resource [platform/CACHE] for container [StandardServer[8005]] so no cleanup was performed for that resource
javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: com.hm.vigil.platform.cache.DistributedCacheManagerFactory]
    at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:66)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
    at org.apache.catalina.deploy.NamingResourcesImpl.cleanUp(NamingResourcesImpl.java:1007)
    at org.apache.catalina.deploy.NamingResourcesImpl.stopInternal(NamingResourcesImpl.java:975)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:793)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:698)
    at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:799)
 Caused by: java.lang.ClassNotFoundException: com.hm.vigil.platform.cache.DistributedCacheManagerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:61)
    ... 12 more

以下是反编译类的屏幕截图:

$location

以下是反编译类的来源:

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

} //关闭课程

0 个答案:

没有答案