How to replace a core jar file in OH2?

I would like to try a snapshot version of the org.eclipse.smarthome.core.jar file, but I don’t know what’s the right way to replace this jar. I tried to just replace the jar file in the folder /usr/share/openhab2/runtime/system/org/eclipse/smarthome/core/org.eclipse.smarthome.core/0.9.0.b5 but that didn’t change anything.

After that I tried to uninstall the 0.9.0.b5 core bundle in the karaf console and added the snapshot jar file to the addons folder and started it using karaf. Now I get some strange errors in the log and PaperUI isn’t working anymore:

2017-07-11 12:12:50.896 [INFO ] [org.eclipse.smarthome.ui.paper      ] - FrameworkEvent INFO - org.eclipse.smarthome.ui.paper
org.osgi.framework.BundleException: The bundle class path entry "patch/" could not be found for the bundle "osgi.identity; osgi.identity="org.eclipse.smarthome.ui.paper"; type="osgi.bundle"; version:Version="0.9.0.b5"; singleton:="true""
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassPathEntry(ClasspathManager.java:176)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.buildClasspath(ClasspathManager.java:154)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.<init>(ClasspathManager.java:83)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.loader.EquinoxClassLoader.<init>(EquinoxClassLoader.java:57)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.loader.BundleLoader.createClassLoaderPrivledged(BundleLoader.java:277)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.loader.BundleLoader.getModuleClassLoader(BundleLoader.java:224)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.loader.BundleLoader.findEntries(BundleLoader.java:777)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.ModuleWiring.findEntries(ModuleWiring.java:289)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.storage.ManifestLocalization.findResource(ManifestLocalization.java:200)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.storage.ManifestLocalization.lookupResourceBundle(ManifestLocalization.java:131)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.storage.ManifestLocalization.getResourceBundle(ManifestLocalization.java:102)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.storage.ManifestLocalization.getHeaders(ManifestLocalization.java:63)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.storage.BundleInfo$Generation.getHeaders(BundleInfo.java:124)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.privGetHeaders(EquinoxBundle.java:471)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.getHeaders(EquinoxBundle.java:466)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.getHeaders(EquinoxBundle.java:460)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.apache.aries.spifly.BaseActivator.addConsumerWeavingData(BaseActivator.java:96)
	at org.apache.aries.spifly.ConsumerBundleTrackerCustomizer.addingBundle(ConsumerBundleTrackerCustomizer.java:37)
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:469)[org.osgi.core-6.0.0.jar:]
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:415)[org.osgi.core-6.0.0.jar:]
	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[org.osgi.core-6.0.0.jar:]
	at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[org.osgi.core-6.0.0.jar:]
	at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:156)[org.osgi.core-6.0.0.jar:]
	at org.apache.aries.spifly.BaseActivator.start(BaseActivator.java:81)
	at org.apache.aries.spifly.dynamic.DynamicWeavingActivator.start(DynamicWeavingActivator.java:37)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at java.security.AccessController.doPrivileged(Native Method)[:1.8.0_131]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:941)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:318)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.Module.doStart(Module.java:571)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.Module.start(Module.java:439)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]

What is the correct way to install a snapshot of core jar files and how do I revert back to the release versions?

I have never tried to update a core jar in OH2… in theory it is possible but I wouldn’t recommend it (check tmp and cache dirs also)
You could switch from OH2.1 stable to OH2.2 snapshot if you would like (if this works for you)
You can then revert back to OH2.1

Reinstalling openhab2 fixed the problems, but I’m still wondering if it would be possible to replace a single core jar.

I don’t think that would be wise because there are often changes in the library APIs and class interactions that can cause an older version of some libraries to no longer work with the newer libraries. It is best to upgrade all of the core all at once, not jar by jar.