JAR文件在执行期间被修改

时间:2009-06-04 21:13:21

标签: java hibernate spring jar

这是在我的程序最后一次失败之后。我注意到文件大小已经改变,我不能再运行我的程序的Java类:

root@dbs01 ~
$ ls -l lifecycle-0.1-SNAPSHOT.jar
-rw-r--r--   1 root     root     24740243 Jun  4 20:48 lifecycle-0.1-SNAPSHOT.jar

这是在我复制原始JAR文件的新副本之后:

root@dbs01 ~
$ ls -l lifecycle-0.1-SNAPSHOT.jar
-rw-r--r--   1 root     root     24833475 Jun  4 20:55 lifecycle-0.1-SNAPSHOT.jar

然后我运行Java命令:

root@dbs01 ~
$ java -cp lifecycle-0.1-SNAPSHOT.jar com.abc.lifecycle.cli.LifecycleManagerCli -dm web 0001 lm2-dom0.sfbay.abc.com ZONE /path/to/bits
Jun 4, 2009 8:55:51 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@186c6b2: display name [org.springframework.context.support.ClassPathXmlApplicationContext@186c6b2]; startup date [Thu Jun 04 20:55:51 GMT+00:00 2009]; root of context hierarchy
Jun 4, 2009 8:55:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [lifecycle_lite.xml]
Jun 4, 2009 8:55:51 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@186c6b2]: org.springframework.beans.factory.support.DefaultListableBeanFactory@88e2dd
Jun 4, 2009 8:55:51 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [lifecycle.properties]
Jun 4, 2009 8:55:51 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@88e2dd: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,com.abc.lifecycle.util.LoggingConfigurer#0,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,txAdvice,lifecycleOperations,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,dataSource,hibernateSessionFactory,moduleDefinitionDao,moduleHostDao,moduleInstanceDao,physicalHostDao,serviceDefinitionDao,serviceInstanceDao,numericOffsetDao,virtualHostDao,broker,jmsConnectionFactory,lifecycleMessageQueue,lifecycleMessageXmlConverter,lifecycleMessageListener,lifecycleMessageListenerContainer,jmsTemplate,lifecycleProcessor,statusChecker,lifecycleComponentBuilder,lifecycleManagerInitializer,lifecycleManagerCli]; root of factory hierarchy
Hibernate:
    insert
    into
        SERVICE_INSTANCE
        (CREATED_DATE, OPTIMISTIC_LOCKING_VERSION, UPDATED_DATE, MODULE_INSTANCE_ID, serviceDefinition_ENTITY_ID)
    values
        (?, ?, ?, ?, ?)
Hibernate:
    delete
    from
        NUMERIC_OFFSET
    where
        ENTITY_ID=?
        and OPTIMISTIC_LOCKING_VERSION=?
Exception in thread "lifecycleMessageListenerContainer-1" java.lang.NoClassDefFoundError: org/springframework/jms/support/JmsUtils
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.clearResources(DefaultMessageListenerContainer.java:1024)
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:887)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: org.springframework.jms.support.JmsUtils
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 3 more

此时我用Ctrl-C杀死它:

^CException in thread "ActiveMQ ShutdownHook" java.lang.NoClassDefFoundError: org/apache/activemq/broker/TransportConnection$3
        at org.apache.activemq.broker.TransportConnection.stopAsync(TransportConnection.java:920)
        at org.apache.activemq.broker.TransportConnection.stop(TransportConnection.java:902)
        at org.apache.activemq.util.ServiceStopper.stop(ServiceStopper.java:41)
        at org.apache.activemq.broker.TransportConnector.stop(TransportConnector.java:270)
        at org.apache.activemq.util.ServiceSupport.dispose(ServiceSupport.java:43)
        at org.apache.activemq.transport.vm.VMTransportFactory.stopped(VMTransportFactory.java:226)
        at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:518)
        at org.apache.activemq.broker.BrokerService.containerShutdown(BrokerService.java:1754)
        at org.apache.activemq.broker.BrokerService$4.run(BrokerService.java:1732)
Caused by: java.lang.ClassNotFoundException: org.apache.activemq.broker.TransportConnection$3
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 9 more

然后您可以看到JAR文件已被更改:

root@dbs01 ~
$ ls -l lifecycle-0.1-SNAPSHOT.jar
-rw-r--r--   1 root     root     24740243 Jun  4 20:56 lifecycle-0.1-SNAPSHOT.jar

我可以在我的Maven资源库中找到它抱怨的JmsUtils类和ActiveMQ TransportConnection类,我还能尝试什么?

root@dbs01 ~
$ jar tf lifecycle-0.1-SNAPSHOT.jar | grep JmsUtils
org/springframework/jms/support/JmsUtils.class
root@dbs01 ~
$ jar tf lifecycle-0.1-SNAPSHOT.jar | grep TransportConnection                                               
org/apache/activemq/broker/MapTransportConnectionStateRegister.class
org/apache/activemq/broker/SingleTransportConnectionStateRegister.class
org/apache/activemq/broker/TransportConnection$1.class
org/apache/activemq/broker/TransportConnection$2.class
org/apache/activemq/broker/TransportConnection$3.class
org/apache/activemq/broker/TransportConnection.class
org/apache/activemq/broker/TransportConnectionState.class
org/apache/activemq/broker/TransportConnectionStateRegister.class
org/apache/activemq/broker/jmx/ManagedTransportConnection.class

在执行期间可以修改JAR文件的状态是什么?如果我从远程计算机上附加调试器怎么办 - 这是否有任何影响(我假设没有)?

提前致谢。

- 詹姆斯

1 个答案:

答案 0 :(得分:6)

首先要尝试将jar文件的模式更改为444甚至400,然后看看会发生什么。

Java,JRE本身,根本不应该修改jar文件;它只需要读取权限。最可能的情况是某个地方错误地获取了数据文件路径的jar文件路径,只有上帝才知道如何。

将文件设为只读,并且您应该获得访问(或至少是打开)的异常。