Eclipse使用 junit测试 报 “The builder launch configuration could not be found” 错误的解决办法

 eclipse, junit  Eclipse使用 junit测试 报 “The builder launch configuration could not be found” 错误的解决办法已关闭评论
4月 112022
 

Eclipse使用 junit测试, 报 “The builder launch configuration could not be found” 错误

解决方法如下:

  1. Package Explorer 视图下选中项目名
  2.  右键项目名,然后选择Properties 或者 在Eclipse 工具栏中选择 Project -> Properties
  3. 弹出的 Properties 对话框中,点击 Builders
  4. 将没有勾选,缺失的 builder 移除掉
  5. 点击 OK 按钮

DONE!

eclipse: workspace出错导致无法启用的解决

 eclipse  eclipse: workspace出错导致无法启用的解决已关闭评论
3月 222016
 

启动eclipse选择workspace后, 启动失败,提示查看.log文件。

可以试验下面的方法

1. 可以试下这个方法:workspace\.metadata\.plugins\org.eclipse.core.resources\目录下有一个.snap文件,把它删除掉,顺利的话,eclipse就可以用该workspace启动了,启动后,把所有project给clean一下


2. 首先进入workspace的.metadata/.plugins/org.eclipse.core.resources/.projects文件夹中,你会发现一些项目的文件;
然后估计一下哪个项目出错(一般情况下是eclipse异常关闭时正在使用的项目),进入项目对应的文件;再后找到里面有个叫.SNAP的文件,把它删除掉。最后重新启动eclipse,问题应该会解决


Good Luck!

在eclipse中使用pydev插件进行远程调试python

 eclipse, python  在eclipse中使用pydev插件进行远程调试python已关闭评论
2月 172016
 

介绍下在eclipse中使用pydev插件进行远程调试,供参考。

先看下官网的资料,后面有测试总结:

Remote Debugger

In PyDev you can debug a remote program (a file that is not launched from within Eclipse).

The steps to debug an external program are:

  • Start the remote debugger server
  • Go to the debug perspective
  • Start the external program with the file ‘pydevd.py’ in its pythonpath
  • Call pydevd.settrace()

Let’s see a simple ‘step-by-step’ example on how this works:

1. Start the remote debugger server: To start the remote debugger server, you have to click the green button pointed by ‘1’ in the image below. After doing that, it will show a message in the console (indicated by ‘2’) to confirm that the server is listening for incoming connections.

Note: Those buttons should be present at the debug perspective and they can be enabled in other perspectives through Window > Customize perspective > Command groups availability > PyDev debug.

Image: Remote Debugger Server

2. Go to the debug perspective: This is needed because it has no actual ‘signal’ that it reached a breakpoint when doing remote debugging. So, if you already have it open, just cycle to it with Ctrl+F8. Otherwise, go to the menu: window > Open Perspective > Other > Debug.

Note that there should appear a process named ‘Debug Server’ in the debug view (see ‘1’ in the image below).

Image: Debug perspective

3. Make sure pydevd.py is in your pythonpath: This file is included in the org.python.pydev plugin. So, you’ll have to add it to the pythonpath. It’s exact location will depend upon the eclipse location and the plugin version, being something like:

eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd.py

(so, the container folder must be in your pythonpath). If you choose to execute it from another machine, you need to copy all the files within that folder to the target machine in order to be able to debug it (if the target machine does not have the same paths as the client machine, the file pydevd_file_utils.py must be edited to properly translate the paths from one machine to the other – see comments on that file).

4. Call pydevd.settrace(): Now that the pydevd.py module is already on your pythonpath, you can use the template provided: ‘pydevd’ to make the call: import pydevd;pydevd.settrace(). When that call is reached, it will automatically suspend the execution and show the debugger.

Image: pydevd.settrace called

Important Notes

NOTE 1: the settrace() function can have an optional parameter to specify the host where the remote debugger is listening. E.g.:pydevd.settrace(‘10.0.0.1’)

NOTE 2: the settrace() function can have optional parameters to specify that all the messages printed to stdout or stderr should be passed to the server to show. E.g.: pydevd.settrace(stdoutToServer=True, stderrToServer=True)

NOTE 3: You can have the running program in one machine and PyDev on another machine, but if the paths are not exactly the same, some adjustments have to be done in the target machine:

Aside from passing the files in eclipse/plugins/org.python.pydev_x.x.x/pysrc to your target machine, the file pydevd_file_utils.py must be edited to make the path translations from the client machine to the server machine and vice-versa. See the comments on that file for detailed instructions on setting the path translations.

我在看完上面的资料后还是很疑惑,感觉没说清楚。 经过使用测试后总结下经验,使用中大家需注意以下四题:

1.  eclipse端是debug服务端 , 即端口的监听端, 也就是说远端要调试的python代码文件是作为客户端连接eclipse端的端口(如:默认端口 5678), 切记!!我在这里吃了大亏

2.  在eclipse插件plugins目录查找到pydevd.py文件后,将文件所在的整个个文件夹copy到需要调试的机器的python文件的site-packages目录下,并保证可以访问到pydevd.py(我使用了在site-packages目录下建立pysrc.pth文件指定路径方式),可参考文章最后的url。

3.  如果远程调试,一般python代码的路径在eclipse端与远程机器上的路径是不一样的,一定记住修改pydevd_file_utils.py中的PATHS_FROM_ECLIPSE_TO_PYTHON值,修改具体值可以看下文件中关于这个变量的注释,而且注释中还有举例说明。

4.  在需要调试的代码中使用下面代码:

        import pydevd
        pydevd.settrace(‘eclipse端服务器地址‘, port=端口5678, stdoutToServer=True, stderrToServer=True)

官网参考: http://www.pydev.org/manual_adv_remote_debugger.html

其它参考:http://blog.csdn.net/tantexian/article/details/47003385

eclipse无法启动的各种解决方法

 eclipse  eclipse无法启动的各种解决方法已关闭评论
2月 162016
 

当选择完workspace之后,eclipse开始加载启动,在这个阶段经常出现闪退出的情况,这主要有两个原因:

原因一、eclipse.ini的配置问题:

可能配置的内存太小,或者系统本身内存不够了,比如我的就配置成这样:

-Xms128m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=512m -Dorg.eclipse.swt.browser.DefaultType=mozilla

具体配置方法和参数说明网上很多,不再赘述。

 

原因二、之前错误的关闭,workspace的问题:

这个问题比较棘手,因为很难找到问题出再哪,可能之前的操作有误,可能某个插件BUG,等等。

最狠的解决方法是删除workspace/.metadata/目录,也就是把这个workspace从eclipse的记忆中删除,缺点是要重新加载每一个项目…

网上很流行的一个方法是:

$ rm YOUR_PROJECT_DIR/.metadata/.plugins/org.eclipse.core.resources/.snap

但是我没成功。

我用的这个方法成功了:

复制代码
0, 进入workspace/.metadata/.plugins/目录 1. Rename org.eclipse.core.resources to org.eclipse.core.resources_old. 2. Start eclipse 3. Close eclipse 4. Delete org.eclipse.core.resources 5. Rename org.eclipse.core.resources_old back to org.eclipse.core.resources 6. Star eclipse
复制代码

这个方法相对完美,不用重新加载任何项目,推荐!

转自:http://www.cnblogs.com/coding-way/archive/2012/10/17/2727481.html

MAT 之 Incoming and Outgoing References

 eclipse  MAT 之 Incoming and Outgoing References已关闭评论
3月 162015
 

虽然是英文,但对理解MAT有帮助,贴出来

Eclipse MAT: Understand Incoming and Outgoing References

In [1], we have shown how to use OQL to query String instances starting with a specified substring (i.e., our objects of interest) from a heap dump.[7,8] To determine who is creating these objects, or find out what the purpose of some structures are, an object’s incoming and outgoing references become handy.

In this article, we will examine the following topics:
  • What are incoming references or outgoing references of an object?

Then look at two topics related to incoming references:

  • Path To GC Roots
  • Immediate Dominators

Outgoing References

Using the following OQL statement, we have identified total 7 entries (see Figure above) as our objects of interest:

SELECT * FROM java.lang.String WHERE toString().startsWith(“http://xmlns.oracle.com/apps/fnd/applcore/log/service/types”)

After expanding the first entry, it shows two outgoing references:

  1. a reference to the Class instance for the String object
  2. a reference to an array of char values

Outgoing References show the actual contents of the instances, helping to find out their purpose. In our Stringinstance, it holds two references. The memory overhead of this String instance is shown in two values: [3]

  • Shallow Heap
  • Retained Heap
These sizes of String instances depends on the internal implementation of the JVM. Read [2,4] for more details.

Incoming References

To get incoming references of the first entry, choose List Objects with Incoming References from the context menu.



Now a tree structure is displayed, showing all instances with all incoming references (note the different icon highlighted in red). These references have kept the object alive and prevented it from being garbage collected.

Immediate Dominators

Similarly, from the context menu, you can display immediate dominators of the first entry (see Figure below). AnObject X is said to dominate an Object Y if every path from the GC Root to Y must pass through X. So, immediate dominators is a very effective way to find out who is keeping a set of objects alive. For example, the immediate dominators of our first entry (note that we have used “java.*|com.sun..*” as our filter) is:

  • oracle.j2ee.ws.server.deployment.WebServiceEndpoint



Path To GC Roots

From context menu, you can also show “Path to GC Roots” of the first entry (see Figure below). Path to GC Rootsshows the path to GC roots which should be found for a given object. As you can expect, its immediate dominatorsmust also be on this path. Note that, when you display Path to GC Roots, you can specify which fields of certain classes to be ignored when finding paths. For example, we have specified that paths through Weak or Soft Referencereferents to be excluded.

Live Data Set

Now we know

  • oracle.j2ee.ws.server.deployment.WebServiceEndpoint

is keeping our String instance alive. Instead of viewing Path to GC Roots, it is easier to see it the other way around. So, we have chosen to display the outgoing references of WebServiceEndpoint instance (see Figure below). As you can see, our String instance is displayed as the leaf node of the tree structure.

References

  1. Eclipse MAT: Querying Heap Objects Using OQL (Xml and More)
  2. Java memory usage of simple data structure
  3. Shallow vs. Retained Heap
  4. Create and Understand Java Heapdumps (Act 4)
  5. Diagnosing Java.lang.OutOfMemoryError (Xml and More)
  6. I Bet You Have a Memory Leak in Your Application by Nikita Salnikov-Tarnovski
    • Classloader leak is the most common leak in web applications
  7. How to analyze heap dumps
    • Leak can be induced
      • Per call (or a class of objects)
      • Per object 
  8. Diagnosing Heap Stress in HotSpot (Xml and More)

eclipse中调试 python代码时出现错误提示:“SyntaxError: Non-ASCII character 'xe6' in file…", 解决方法

 eclipse, python  eclipse中调试 python代码时出现错误提示:“SyntaxError: Non-ASCII character 'xe6' in file…", 解决方法已关闭评论
7月 312014
 

eclipse中调试 python代码时出现错误提示:“SyntaxError: Non-ASCII character ‘xe6’ in file…”, 解决方法如下:

在.py文件的最上面添加下面一行:

# -*- coding: utf-8 -*-


搞定!

eclipse 远程调试 jetty/tomcat

 eclipse, MAVEN, tomcat  eclipse 远程调试 jetty/tomcat已关闭评论
3月 142014
 

A:

1.在eclipse的run configurations中创建一个maven build,选择好Maven工程,在Goals一栏中输入jetty:run。然后进入“jre”Tab,在vm arguments一栏中输入-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

2.打开debug configuration,创建一个remote java application,在host中输入服务器地址,一般就本机localhost。在port一栏中输入上面配置中端口号8000。这样,当服务器启动后,就可以进行远程debug了。这种debug方式的好外是可以在debug依赖的jar包,并在上面设置断点。(前提是你已经获得了jar包的源代码)

 

B:

如果是Tomcat,只需要在tomcat/bin/的catalina.bat文件的开头加入下面的设置即可:

SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

然后在eclipse新建一个remote debug,端口填入8000即可。

eclipse + Spring + junit的测试

 junit, spring  eclipse + Spring + junit的测试已关闭评论
3月 062013
 

转自:http://xuyufei1985.blog.163.com/blog/static/13164348200911212942824/

开发一个eclipse3.4+Struts2.0+hibernate3.2+Spring2.5+oracle10g的项目。实现完DAO层后,想对Dao层做下测试。以前都是用的Junit3.8,这次换了最新的Junit4.4,但是在写测试类时遇到不少麻烦,将碰到的问题和解决方法记录下来,供后来的朋友们参考。

下面分别讲解在Junit4.4和Junit3.8下如何写测试类。
对于Junit3.8:
Spring的DAO层的测试,spring-test.jar包里有个AbstractTransactionalDataSourceSpringContextTests类,只要继承它,然后重写getConfigLocations方法就可以了。比较简单,而且又支持回滚,没有数据库的耗时操作。
对于你所有的applicationContext.xml等spring配置文件,你都不用动。Eclipse默认的classpath路径是项目路径下的build/classes,注意不要被你的ant写的build覆盖了,而ant的build又没有编译test包。最终找不到测试类。
 
下面先写一个基本的测试类,其他的只要继承这个类并添加test方法即可。

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
 
public class BaseDaoTestCaseJunit3 extends
AbstractTransactionalDataSourceSpringContextTests {
 
protected final static Log log = LogFactory.getLog(BaseDaoTestCaseJunit3.class);
 
@Override
protected String[] getConfigLocations(){
this.setAutowireMode(AUTOWIRE_BY_NAME);
return new String[]{"classpath:/applicationContext.xml","classpath:/spring-config-*.xml"};
}
 
public void testConfig() {
       assertNotNull("spring-mock context has bean init()",this.applicationContext);
    }
}

下面这个类继承自上面的BaseDaoTestCaseJunit3,只是测试了下CustInfoDao里面的findByEmail方法。
import com.psi.domain.CustInfo;
 
public class CustInfoDaoTests3 extends BaseDaoTestCaseJunit3 {
private CustInfoDao ciDao;
private CustInfo ci;
 
public CustInfoDaoTests3(){}
 
public void setCustInfoDao(CustInfoDao ciDao){
this.ciDao = ciDao;
}
 
public void getList(){
try{
ci = ciDao.findByEmail("[email protected]"); //此方法直接返回对象.
assertNotNull(ci.getId());
}catch(Exception e){
e.printStackTrace();
}
}
}

 
下面讲讲Junit4.4的写法:
Junit4用了完全不同于Junit3的写法,它的配置文件等都只需要在annotation里标注即可。TransactionManager是你在application里配置的TransactionManager。

package com.psi.dao;
 
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/applicationContext.xml","classpath:/spring-config-*.xml"})
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)
@Transactional
public class BaseDAOTestCaseJunit44 {
//本类作为基类,所有要用到的东西都在annotation里配置了。所以什么内容都不用写了。
}
 

//Dao测试类继承自上面的基类,并添加了个测试方法findByEmail。

 
import static org.junit.Assert.*;
 
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
 
import com.psi.domain.CustInfo;
 
public class CustInfoDaoTests extends BaseDAOTestCaseJunit44 {
private CustInfoDao ciDao;
private CustInfo ci;
 
public CustInfoDaoTests(){}
 
@Autowired
public void setCustInfoDao(CustInfoDao ciDao){
this.ciDao = ciDao;
}
 
@Before
public void init(){}
 
@Test
public void getList(){
try{
ci = ciDao.findByEmail("[email protected]");
assertNotNull(ci.getId());
}catch(Exception e){
e.printStackTrace();
}
}
}


就这么简单,但是要注意要加载相应的包,Spring-test.jar, apache的commons-下的包最好都加上。(项目中你基本都能用上)

还要注意你的配置文件路径。
我还碰到过下面这个错误:
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)

这是Eclipse的Bug,它在测试环境下不能自动加载到SystemLibrary下的所有包,所以你需要将你的Library改成user-library即可。