eclipse你不知道的.classpath
题目是噱头,用的人都知道。我想说的是classpath中不太注意的classpathentry excluding。
昨天在跑junit测试时,报错提示springframe.test.jar多次加载。 nnd,前天跑还一切正常,今天切了一下版本,又切回来,就不行了。
找了一个小时都没找到原因。
项目背景是该模块使用的是osgi框架,框架中包含spring的所有包。但是在编译时,需要单独把测试包加进来。
根据问题,我怀疑是classpath,但是如果去掉jar包引用,连编译都编译不过去。
最后翻到eclipse的.classpath文件才找到原因,classpathentry excluding这家伙被覆盖掉了。
excluding标签是保证项目在启动时不会讲指定的目录jar加载到内存,只做编译引用。
我在切换版本时,将其覆盖了。
昨天在跑junit测试时,报错提示springframe.test.jar多次加载。 nnd,前天跑还一切正常,今天切了一下版本,又切回来,就不行了。
java.lang.IllegalStateException: Unable to dynamically start generated unit test bundle
at org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests.postProcessBundleContext(AbstractOnTheFlyBundleCreatorTests.java: 527 )
at org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests.postProcessBundleContext(AbstractConfigurableBundleCreatorTests.java: 223 )
at org.springframework.osgi.test.AbstractOsgiTests.startup(AbstractOsgiTests.java: 262 )
at org.springframework.osgi.test.AbstractOsgiTests.prepareTestExecution(AbstractOsgiTests.java: 374 )
at org.springframework.osgi.test.AbstractOsgiTests.runBare(AbstractOsgiTests.java: 203 )
at org.springframework.osgi.test.AbstractOsgiTests$ 1 .protect(AbstractOsgiTests.java: 184 )
at junit.framework.TestResult.runProtected(TestResult.java: 124 )
at org.springframework.osgi.test.AbstractOsgiTests.run(AbstractOsgiTests.java: 181 )
at junit.framework.TestSuite.runTest(TestSuite.java: 230 )
at junit.framework.TestSuite.run(TestSuite.java: 225 )
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java: 130 )
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 38 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 460 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 673 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 386 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 196 )
Caused by: org.osgi.framework.BundleException: Cannot import a package more than once " org.springframework.osgi.test "
at org.eclipse.osgi.internal.resolver.StateBuilder.checkImportExportSyntax(StateBuilder.java: 533 )
at org.eclipse.osgi.internal.resolver.StateBuilder.validateHeaders(StateBuilder.java: 185 )
at org.eclipse.osgi.internal.resolver.StateBuilder.createBundleDescription(StateBuilder.java: 49 )
at org.eclipse.osgi.internal.resolver.StateObjectFactoryImpl.createBundleDescription(StateObjectFactoryImpl.java: 32 )
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.updateState(BaseStorage.java: 1112 )
at org.eclipse.osgi.internal.baseadaptor.BundleInstall.commit(BundleInstall.java: 128 )
at org.eclipse.osgi.framework.internal.core.Framework.installWorkerPrivileged(Framework.java: 965 )
at org.eclipse.osgi.framework.internal.core.Framework$ 2 .run(Framework.java: 854 )
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.Framework.installWorker(Framework.java: 905 )
at org.eclipse.osgi.framework.internal.core.Framework.installBundle(Framework.java: 849 )
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.installBundle(BundleContextImpl.java: 234 )
at org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests.installAndStartBundle(AbstractOnTheFlyBundleCreatorTests.java: 539 )
at org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests.postProcessBundleContext(AbstractOnTheFlyBundleCreatorTests.java: 524 )
15 more
at org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests.postProcessBundleContext(AbstractOnTheFlyBundleCreatorTests.java: 527 )
at org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests.postProcessBundleContext(AbstractConfigurableBundleCreatorTests.java: 223 )
at org.springframework.osgi.test.AbstractOsgiTests.startup(AbstractOsgiTests.java: 262 )
at org.springframework.osgi.test.AbstractOsgiTests.prepareTestExecution(AbstractOsgiTests.java: 374 )
at org.springframework.osgi.test.AbstractOsgiTests.runBare(AbstractOsgiTests.java: 203 )
at org.springframework.osgi.test.AbstractOsgiTests$ 1 .protect(AbstractOsgiTests.java: 184 )
at junit.framework.TestResult.runProtected(TestResult.java: 124 )
at org.springframework.osgi.test.AbstractOsgiTests.run(AbstractOsgiTests.java: 181 )
at junit.framework.TestSuite.runTest(TestSuite.java: 230 )
at junit.framework.TestSuite.run(TestSuite.java: 225 )
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java: 130 )
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 38 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 460 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 673 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 386 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 196 )
Caused by: org.osgi.framework.BundleException: Cannot import a package more than once " org.springframework.osgi.test "
at org.eclipse.osgi.internal.resolver.StateBuilder.checkImportExportSyntax(StateBuilder.java: 533 )
at org.eclipse.osgi.internal.resolver.StateBuilder.validateHeaders(StateBuilder.java: 185 )
at org.eclipse.osgi.internal.resolver.StateBuilder.createBundleDescription(StateBuilder.java: 49 )
at org.eclipse.osgi.internal.resolver.StateObjectFactoryImpl.createBundleDescription(StateObjectFactoryImpl.java: 32 )
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.updateState(BaseStorage.java: 1112 )
at org.eclipse.osgi.internal.baseadaptor.BundleInstall.commit(BundleInstall.java: 128 )
at org.eclipse.osgi.framework.internal.core.Framework.installWorkerPrivileged(Framework.java: 965 )
at org.eclipse.osgi.framework.internal.core.Framework$ 2 .run(Framework.java: 854 )
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.Framework.installWorker(Framework.java: 905 )
at org.eclipse.osgi.framework.internal.core.Framework.installBundle(Framework.java: 849 )
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.installBundle(BundleContextImpl.java: 234 )
at org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests.installAndStartBundle(AbstractOnTheFlyBundleCreatorTests.java: 539 )
at org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests.postProcessBundleContext(AbstractOnTheFlyBundleCreatorTests.java: 524 )
15 more
找了一个小时都没找到原因。
项目背景是该模块使用的是osgi框架,框架中包含spring的所有包。但是在编译时,需要单独把测试包加进来。
根据问题,我怀疑是classpath,但是如果去掉jar包引用,连编译都编译不过去。
最后翻到eclipse的.classpath文件才找到原因,classpathentry excluding这家伙被覆盖掉了。
excluding标签是保证项目在启动时不会讲指定的目录jar加载到内存,只做编译引用。
我在切换版本时,将其覆盖了。