分类: Eclipse Coding

  • eclipse内Tomcat启动失败错误解决Could not publish server configuration for Tomcat v8.0 Server at localhost

     今天又碰到了Tomcat启动失败的错误,错误提示如下:

        Could not publish server configuration for Tomcat v8.0 Server at localhost.
        Multiple Contexts have a path of “/项目名”

     

    通过查阅网上,解决方法如下

    解决方案:
    if:使用的eclipse tomcat 插件

    在工作空间 workspace找到如下文件:.metadata.pluginsorg.eclipse.wst.server.coretmp0conf中的server.xml

    if:使用自己安装的tomcat服务器

    在Tomcat的安装目录下的confserver.xml中

    将<Context>标签所对应的重复名称项目删除

  • Eclipse中安装MemoryAnalyzer插件

    Eclipse作为JAVA非常好用的一款IDE,其自带的可扩展插件非常有利于JAVA程序员的工作效率提升。

      MemoryAnalyzerTool(也叫MAT)是一款JAVA虚拟机内存映像分析工具,可以在JAVA程序运行的时候有程序抛出的异常加上已经设置好的参数(-XX:+HeapDumpOnOutOfMemory)调试出内存泄漏或者异常的位置以及原因跟踪,MemeoryAnalyzer可以对Dump出来的堆转储快照进行分析,重点是确认内存中的对象是否是有必要的,也就是要先确认到底是出现了内存泄漏(Memory Leak)还是内存溢出(Memory OverFlow)。

  • eclipse 使用MAT分析堆栈

    1.介绍
    Eclipse MAT是eclipse提供的插件用于分析JAVA heap。试过很多分析heap的,但是没有比这个更好用的了。

    PS:在mac high sierra上直接下载独立运行的MAT貌似会出问题卡死,我是本地直接下载了个。

    请先阅读下MAT官方的DOC:MAT官方DOC

    2.基本概念

    2.1 堆中包含的内容
    All Objects:Class, fields, primitive values and references
    All Classes:Classloader, name, super class, static fields
    Garbage Collection Roots:Objects defined to be reachable by the JVM
    Thread Stacks and Local Variables:The call-stacks of threads at the moment of the snapshot, and per-frame information about local objects
    2.2 Shallow VS Retined heap
    Shallow heap size : 对象本身占用的大小,不包含其引用的对象Retained heap: 对象本身大小加上其所有引用对象的真实大小

    PS: 可见实际占用看见或者回收的空间要看Retained heap

    2.3 Dominator Tree
    一个Object构成的树(DAG),最顶端的节点的retained memory由其所有子节点构成,作用主要是方便找占用retained heap size最大的对象

    2.4 gc root
    GC ROOT本质就是一个对象,这个对象包含了一系列必须保证活跃的引用(可以理解成一个DAG)。JVM的GC就是判断哪些不能被回收,剩下的全部回收就行。即,遍历所有对象做GC ROOT可达性分析,可达的则不回收,不可达的则进行GC。

    用MAT文档里面的话来解释就是:A garbage collection root is an object that is accessible from outside the heap. The following reasons make an object a GC root

    可作为gc root的对象,完整列表参考下MAT官方文档,我重点罗列几个

    JNI相关的对象和引用
    静态变量
    持有监视器锁的对象
    native栈上的对象和引用

    2.5 一些选项说明

    biggest object by retained size:显示在内存较大的对象信息
    list objects — with outgoing references : 查看这个对象持有的外部对象引用。
    list objects — with incoming references : 查看这个对象被哪些外部对象引用。
    show objects by class — with outgoing references :查看这个对象类型持有的外部对象引用
    show objects by class — with incoming references :查看这个对象类型被哪些外部对象引用
    paths to gc root : 显示不同类型引用(上文中提到的Strong ,soft,weak )到跟节点的路径。
    merge shorest path to gc root : 合并最短路径到root节点。
    java basics:
    classloader 该对象对应的classloader信息 。
    thread details :线程信息
    thread stacks :线程堆栈
    find String : 在这个对象中查询需要的字符串
    group by : 根据某个字段统计出现的个数
    leak Identification — top consumers :几个大消耗内存的对象
    另外计算retsined size也是很常用的功能,MAT默认不显示这一列,如果有需要的可以自己勾选算一下:

    3.实践

    3.1 classloader内存泄漏排查
    参考文献2和4讲了classloader内存泄漏问题排查方法,可以学习下。我没有内存泄漏的例子,但是实际过程中有碰到个perm oom的问题。

    例如产生一个perm gen OOM,就猜测可能由classloader内存泄漏引起。因为perm区主要就存放一些class元数据、静态变量。比如有时候载入了一些java agent,一些classloader载入了不少类,但是分配的perm gen太小,就导致perm gen OOM了。当然这个OOM也不一定是内存泄漏,可能是分配的perm区真的太小了,我就碰到了这样的情况:

    总共分配了32M的PERM,平时使用就达到了29M,因为开了个java agent多加了几M就直接OOM了,因此也顺便用MAT 分析了下heap

    打开classloader浏览器

    看classloader的retained size,合起来差不都32M的样子,有个叫ArthasClasssLoader的,就是我说的java agent,差不多占用2M。。也是本次OOM的罪魁祸首。

    PS: classLoader和一般的Obect不太一样,右键勾选的时候会问你要看Class Loader本身的信息还是其定义的Classses信息。class Loader本身信息如果查看Immediate Dominators信息的话只有个ROOT。这也很好理解,class Loader是rt.jar里面的,是通过boorstrap classloader加载的,属于system class,自然其gc不会依赖别的class,属于最dominant的class了

    3.2 某些类一直没有被GC问题排查
    有时候要看为什么这个类没有被GC,不符合预期,那么只要看看他在哪些GC ROOT对象的引用链上。按照如下操作,这里我排除了一些虚、弱软引用,只关注强引用即可。因为其他程度弱的引用反正都会被GC的,不会是对象异常没被回收的罪魁祸首。

    最后按照罗列出来的引用链,下钻去查看,肯定最后会找到一个gc root object:

    这里可以看到这个Java Local类型的对象就是之前罗列的可以作为gc root object的

    3.3 immediate object和gc root来查找某个对象的root dominated not的区别
    某个对象肯定会关联一个immediate object,当这个immediate object的所有实例被GC后,那么这个对象也肯定会被GC。通过如下方式查找关联的immediate object是最快。但是这种方式只能查找和哪个immediate object关联,不能查看immediate object的引用信息。

    如果需要查看immediate dominators的引用信息,还要按照如下操作,该dominator object有哪个外部对象持有的引用,从而了解需要哪些对象

    当然很容易联想到用GC ROOT查找也是可以的,只不过gc root查找的话展现的内容层次更多些,本质上一样的, 可以看到最后都是定位到ResuableIterator@)xe0a54ce0这个对象

    3.4 查看某个对象dominate 了哪些对象
    3.3节我们是查看某个对象被其他什么对象和引用dominate。有时候需要查看某个对象dominate 哪些子对象也很简单,直接操作Open in Dominatoe Tree

    3.5 线程相关
    持有某个对象实例的线程,直接按照如下操作即可:

    4.总结

    MAT功能强大,本身针对其主要用法配合一些应用场景做了一些介绍,更多可以自己再配合官方文档使用一番,加强理解。

  • 在用eclipse中的windowbuilder的时候,突然闪退,在桌面产生错误报告,请问这是什么意思?

    在用eclipse中的windowbuilder的时候,突然闪退,在桌面产生错误报告,请问这是什么意思?

  • Cannot complete install of CodeMix 3.5.0

    Received the following error when I tried installing CodeMix 3.5.0 (replacing 3.2.0):

    Cannot complete the install because one or more required items could not be found.
    — error: Software being installed: MyEclipse 2019 for DN 16.0.0.c0000018t201910151709 (package.5165-jlg-1527.windows.x86_64 16.0.0.c0000018t201910151709)
    — error: Missing requirement: JSjet Commons 1.11.0.me201904021204 (com.genuitec.eclipse.common.jsjet.feature.feature.group 1.11.0.me201904021204) requires ‘org.eclipse.equinox.p2.iu; com.genuitec.eclipse.common.typescript.feature.feature.group [1.11.0.201903271150,1.11.0.201903271150]’ but it could not be found
    — Cannot satisfy dependency:
    —- error: From: MyEclipse 2019 for DN 16.0.0.c0000018t201910151709 (package.5165-jlg-1527.windows.x86_64 16.0.0.c0000018t201910151709)
    —- error: To: org.eclipse.equinox.p2.iu; com.genuitec.eclipse.common.jsjet.feature.feature.group [1.11.0.me201904021204,1.11.0.me201904021204]

    Is there a simple thing I missed? Verify in SDC worked, but when I tried to apply the updates, I got the above error.

    ——

    we tried some scenarios trying to reproduce the problem you are having, but, we were not able to do it. Everything worked fine. These are the diff package setup used:

    We build TPLs for CodeMix 3.2 and CodeMix 3.5

    ME CI 2019.4.0 and Update to install CodeMix 3.5 – Installs correctly
    ME CI 2019.4.0 + CodeMix 3.2 – Installs correctly
    ME CI 2019.4.0 + CodeMix 3.2 and Upgrade to CodeMix 3.5 – Install Correctly

    Can you please provide some more info like:

    – What is the ME version?
    – What are the steps you are following ?
    – Are you using only ME Components + CodeMix as extra software for your package?

  • Remote Workspace like VSCode Extention

    VS Code has a Remote Workspace.

    How I configure in codemix?

    ——

     

    Currently, the extensions for Remote Workspace cannot be installed to CodeMix due to some incompatibilities. 

    On the Eclipse side, you can try Remote Systems Explorer (RSE) which allows you to connect and work with a variety of remote systems.
    Please see this for more details about RSE

  • Can’t find net.sf.exmorph.Morpher Should be org.kordamp.exmorph.Morpher?

    Hi. My code dies. It can’t find the class it needs.

    I don’t know Java all that well. Either the caller shouldn’t be looking for it at net.sf.ezmorph.Morpher, or I should supply Morpher at that location.

    I have edited my library list, and re-inserted the ezmorph library. But it didn’t make any difference.

    I thought MyEclipse was supposed to work out these details for me.

    What am I doing wrong?

    Oct 11, 2019 9:49:22 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [GetModels] in context with path [/EFM] threw exception [Servlet execution threw an exception] with root cause
    java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at com.aaa.rap.fleet.GetModels.doPost(GetModels.java:36)

     

    ——

     

    It’s likely that the dependencies haven’t been added in the right way. However, before we can provide further assistance, we need to know more about what you are actually doing:

    1) What sort of project is this – a Java EE Web project? Is it a Maven based project (are you managing dependencies through Maven)?
    2) What sever are you deploying to? From the stack trace, I’m assuming Apache Tomcat – if so, which version?
    3) When & where do you see this error? When the server is starting up, in the Console?
    4) What version of MyEclipse are you using? Please see Help > About for the build Id.
    5) Can you share details on how and where you’ve edited the library list – a screenshot would help as well.

    Thanks!

     

    ——

     

    Answering in order.

    1) What sort of project is this – a Java EE Web project? Is it a Maven based project (are you managing dependencies through Maven)?

    I would say that’s exactly what it is. A Java EE Web project. A server runs at a port, and if you go to a certain localhost url, it shows you a Web page. The browser (Javascript) communicates with the server using Ajax. (My background is C++ servers and Javascript single-page applications.)

    2) What sever are you deploying to? From the stack trace, I’m assuming Apache Tomcat – if so, which version?

    It says “MyEclipse Tomcat v8.5”

    3) When & where do you see this error? When the server is starting up, in the Console?

    No. It runs fine, until I try to open a certain drop-down. Then, in the doPost method in the server, it tries to do this:

    JSONObject responcedata = new JSONObject();

    and that’s where it fails. I guess ezmorph must be involved in the JSONObject constructor.

    4) What version of MyEclipse are you using? Please see Help > About for the build Id.

    MyEclipse Enterprise Workbench

    Version: CI 2018.9.0
    Build id: 16.0.0-20180903

    5) Can you share details on how and where you’ve edited the library list – a screenshot would help as well.

    Ah. I am embarrassed by this part. There were some red x’s. We are constrained to use Java 5. I took two steps:

    [1] I tried to activate the Maven dependencies piece, thinking Maven could sort it out for me. Still red x’s.

    [2] I copied the .classpath from a project that didn’t have red x’s. That eliminated the red x’s.

    But it failed at runtime.

    I am including a screenshot of the project facets, as well as the java build path, because I have a feeling it might matter. Note that I have unchecked Maven Support – Dependencies Only.

    ——

     

    Thank you for the details. Maven can help, but you do need to know at least a bit of Maven and configure the project correctly.

    Here’s a quick suggestion:
    1) Shut down the server and undeploy the project.
    2) Remove all the JAR files from the Libraries tab and apply this change.
    3) In your project, there will be a WEB-INF/lib folder. Physically copy all those library files into this folder. MyEclipse will automatically add them to the build path, so your project should compile fine. If you still see Red X’s … that would mean that you’re still missing some libraries and you shouldn’t bother with deployment until you resolve this.
    The benefit of copying the JARs to the lib folder is that this will also ensure that the libraries are deployed to the server correctly.
    4) Deploy the project and start the server.

    Hopefully this will resolve the issues you are now facing, please let me know if this works!

  • Run/Debug Errors with JDK 11.0.4 Error: Could not find or load main class

    After migrating a working Vendor SDK based project with a complex classpath from 1.8.0 to 11.0.4 using compliance level 11 most run configurations are failing. I reverted changes and restored use of 1.8.0 and everything works. Change preferences to use 11.0.4 and compliance level 11 and again fails same issue.

    Message received:
    Error: Could not find or load main class CSDWCSDWBORepositorybin;C:libApachecommons-lang3-3.7commons-lang3-3.7.jar;C:usrMyEclipseWorkSpace
    Caused by: java.lang.ClassNotFoundException: CSDWCSDWBORepositorybin;C:libApachecommons-lang3-3/7commons-lang3-3/7/jar;C:usrMyEclipseWorkSpace

    There is a major difference in the Run Commands between these JDKS.

    With JDK 1.8.0_201
    C:Program FilesJavajdk1.8.0_201binjavaw.exe -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:52137 “-Dlog4j.configuration=srclog4jConfig.xml” -Xms1024M -Xmx1024M -Djava.net.preferIPv4Stack=true “-javaagent:C:usrMyEclipse CIconfigurationorg.eclipse.osgi853.cplibjavaagent-shaded.jar” -Dfile.encoding=Cp1252 us.nc.state.dhhs.csdw.businessobjects.repository.RefreshRepository wv1hhcsdwAP01d:6400

    With JDK 11.0.4
    C:usrMyEclipse CIbinarycom.sun.java.jdk11.win32.x86_64_1.11.2binjavaw.exe -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:53420 “-Dlog4j.configuration=srclog4jConfig.xml” -Xms1024M -Xmx1024M -Djava.net.preferIPv4Stack=true “-javaagent:C:usrMyEclipse CIconfigurationorg.eclipse.osgi853.cplibjavaagent-shaded.jar” -Dfile.encoding=Cp1252 “@C:usrMyEclipseWorkSpace CSDWCSDWBORepository.temp-RefreshRepositoryDev-classpath-arg-1570715104463.txt” us.nc.state.dhhs.csdw.businessobjects.repository.RefreshRepository wv1hhcsdwAP01d:6400

    It appears classpath is now set in 11.0.4 by temp file using “@C:usrMyEclipseWorkSpace CSDWCSDWBORepository.temp-RefreshRepositoryDev-classpath-arg-1570715104463.txt”

    This file starts as follows notice the unquoted path (attached file below):
    -classpath C:usrMyEclipseWorkSpace CSDWCSDWBORepositorybin;C:libApachecommons-lang3-3.7commons-lang3-3.7.jar;C:usrMyEclipseWorkSpace CSDWApache Commons Langbin;

    The failure is occurring with the first non-quoted classpath entry resulting in the execution using CSDWCSDWBORepositorybin; as the main class.

    I haven’t been able to find an option to force quoting of this generated classpath.

  • [WebLogic] Defining a WebLogic 12 Runtime

    Some users have understandably been confused about the folders that need to be specified when creating a new WebLogic runtime (either directly or through the new Server wizard). This FAQ hopefully clarifies the locations to specify.

    For the “BEA home directory“, specify the folder containing the domain-registry.xml file. This will also include the folder in which the actual WebLogic server is installed and may contain other software that is common to a number of BEA products (“BEA” is the name of the company that previously owned the WebLogic product now owned by Oracle). For example, on my Linux machine this folder is /home/tony/dev/servers/weblogic12/wls12210, though the key folder here is wls12210.

    For the “WebLogic installation directory“, specify the folder containing the server folder, which itself contains the main server executable code, though the parent folder will contain other server code. The parent folder is typically named wlserver, and is a child of the BEA home directory. On my Linux machine, for example, the WebLogic installation directory is /home/tony/dev/servers/weblogic12/wls12210/wlserver. Note that you will see an error message, at the top of the wizard page for specifying most runtime details, about an invalid WebLogic installation directory until it is specified correctly; once you select the correct location, you may continue to see an error message but it will be concerning a invalid domain directory, so ensure you select that from the browse button against that text field.

  • MyEclipse Unattended Installation

    MyEclipse Unattended Installation

    The following applies to release 2013 and above (for earlier releases, please get in touch).

    Running a Silent Installer

    1. Create an unattended response file.
    2. Run the installer with:

       

       

      For example:

       

      The name of the <offline-installer> file varies with each release; just use the name as downloaded. The “–unattended” switch indicates that the install is to proceed without user intervention. The path to the response file must be absolute, so you need the full path, even if the response file is in the same folder as the installer or in the current directory.

    Response File Format

    The response file is a simple text file specifying various (case-sensitive) properties. For example (showing sample values):

    directory.profile=c:/Genuitec/MyEclipse
    osgi.os=win32
    osgi.ws=win32
    osgi.arch=x86_64
    result.file=c:/Genuitec/unattended.log

    Response File Properties

    directory.profile
    This is the directory into which the specific MyEclipse configuration will be installed

    osgi.os
    Can be any of: win32, linux & macosx

    osgi.ws
    Can be any of win32, gtk & cocoa

    osgi.arch
    Can be x86 for 32-bit or x86_64 for 64-bit (note that 32 bit is not supported in all releases)

    result.file
    The absolute path to a file to which the installer will add notes and errors. A more comprehensive log is also created in the temp folder (the path to that log will be in the result file).

    Additional Notes

    • Ensure that the properties in the the response file have the correct names. Although incorrect values for properties will generate an error, an incorrect property name will effectively just be ignored.
    • The directory.profile value is only respected if you do not have a <home>.deliverycenter.installs file that contains a path for the release being installed, which could exist as a result of a prior MyEclipse installation. In this case, the directory that the file points to will be used as the profile directory.

      Edge case: If the .deliverycenter.installs file isn’t present but you point to a folder that contains an installation of the same release, the installation will not proceed.

    • If the release stream you are trying to install is already installed on the system (for example, if you are trying to install, say, MyEclipse 2017 Stable 2.0 but you already have MyEclipse 2017 Stable 1.0 installed), then:
      • The installer will update that release if an update is available – your directory.profile value must point to this existing location. If it points to a different location, the installer will do nothing.
      • The installer will do nothing if an update is not available
    • For uninstalling MyEclipse in unattended mode, see Unattended Uninstallation.