Mac os 下打开java内存分析工具 mat

  • 2019 年 10 月 7 日
  • 笔记

下载MAT后, 解压得到mat.app, 但是直接点击打开出错, 显示错误信息在文件

/Users/along/.eclipse/762171948_macosx_cocoa_x86_64/configuration/1539580415773.log中.

1. 打开错误信息

cat /Users/along/.eclipse/762171948_macosx_cocoa_x86_64/configuration/1539580415773.log显示:

!SESSION 2018-10-15 13:13:35.692 -----------------------------------------------  eclipse.buildId=unknown  java.version=1.8.0_181  java.vendor=Oracle Corporation  BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_CN  Framework arguments:  -keyring /Users/along/.eclipse_keyring  Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -keyring /Users/along/.eclipse_keyring    !ENTRY org.eclipse.osgi 4 0 2018-10-15 13:13:36.824  !MESSAGE Application error  !STACK 1  java.lang.IllegalStateException: The platform metadata area could not be written: /private/var/folders/6k/zthtjldx3p57hklv6rk636lr0000gn/T/AppTranslocation/A7533741-5F9A-499C-9ADA-6799A79C1AC3/d/mat.app/Contents/MacOS/workspace/.metadata.  By default the platform writes its content  under the current working directory when the platform is launched.  Use the -data parameter to  specify a different content area for the platform.  	at org.eclipse.core.internal.runtime.DataArea.assertLocationInitialized(DataArea.java:70)  	at org.eclipse.core.internal.runtime.DataArea.getStateLocation(DataArea.java:138)  	at org.eclipse.core.internal.preferences.InstancePreferences.getBaseLocation(InstancePreferences.java:44)  	at org.eclipse.core.internal.preferences.InstancePreferences.initializeChildren(InstancePreferences.java:209)  	at org.eclipse.core.internal.preferences.InstancePreferences.<init>(InstancePreferences.java:59)  	at org.eclipse.core.internal.preferences.InstancePreferences.internalCreate(InstancePreferences.java:220)  	at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:349)  	at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:337)  	at org.eclipse.core.internal.preferences.PreferencesService.createNode(PreferencesService.java:393)  	at org.eclipse.core.internal.preferences.RootPreferences.getChild(RootPreferences.java:60)  	at org.eclipse.core.internal.preferences.RootPreferences.getNode(RootPreferences.java:95)  	at org.eclipse.core.internal.preferences.RootPreferences.node(RootPreferences.java:84)  	at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:38)  	at org.eclipse.core.runtime.preferences.InstanceScope.getNode(InstanceScope.java:77)  	at org.eclipse.ui.preferences.ScopedPreferenceStore.getStorePreferences(ScopedPreferenceStore.java:225)  	at org.eclipse.ui.preferences.ScopedPreferenceStore.<init>(ScopedPreferenceStore.java:132)  	at org.eclipse.ui.plugin.AbstractUIPlugin.getPreferenceStore(AbstractUIPlugin.java:287)  	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:609)  	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)  	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:597)  	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)  	at org.eclipse.mat.ui.rcp.Application.start(Application.java:26)  	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)  	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)  	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)  	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)  	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  	at java.lang.reflect.Method.invoke(Method.java:498)  	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)  	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)  	at org.eclipse.equinox.launcher.Main.run(Main.java:1498)

重点是The platform metadata area could not be written: /private/var/folders/6k/zthtjldx3p57hklv6rk636lr0000gn/T/AppTranslocation/A7533741-5F9A-499C-9ADA-6799A79C1AC3/d/mat.app/Contents/MacOS/workspace/.metadata. By default the platform writes its content under the current working directory when the platform is launched. Use the -data parameter to specify a different content area for the platform.

需要使用 -data指定一个位置.

2. 指定data位置

在命令行执行 open, 显示帮助信息:

Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]  Help: Open opens files from a shell.        By default, opens each file using the default application for that file.        If the file is in the form of a URL, the file will be opened as a URL.  Options:        -a                Opens with the specified application.        -b                Opens with the specified application bundle identifier.        -e                Opens with TextEdit.        -t                Opens with default text editor.        -f                Reads input from standard input and opens with TextEdit.        -F  --fresh       Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.        -R, --reveal      Selects in the Finder instead of opening.        -W, --wait-apps   Blocks until the used applications are closed (even if they were already running).            --args        All remaining arguments are passed in argv to the application's main() function instead of opened.        -n, --new         Open a new instance of the application even if one is already running.        -j, --hide        Launches the app hidden.        -g, --background  Does not bring the application to the foreground.        -h, --header      Searches header file locations for headers matching the given filenames, and opens them.        -s                For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.                          Otherwise the highest versioned SDK in each platform is used.

注意这里的–args 是可以传递参数的.

3. 最终执行命令

使用如下命令即可正常打开该mat.app.

open -a mat.app --args -data ~/workplace/heapdump/