Total Pageviews

Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

2020/06/09

[Eclipse] [Maven] missing artifact xxxxxx

Problem
I copy libraries (under .m2/repository) from other's machine.
As I tried to update maven in my eclipse project, I got missing artifact error.
I had confirmed these jar files which existed in my .m2/repository.

How-To
Go to specific directory and delete _remote.repositories, thenthe problem will be resolved.

2019/03/06

[Eclipse] Get the power to write better code with sonarlint

You can install sonarlint plugin to get the power to write better code.
For example, if you forgot to close IO resource properly, you will get this hint:

And it will tell you how to fix this problem:


2017/11/04

[Eclipse] How to know current worksapce ?

Problem
How do I know which eclipse workspace I am working currently?

How-To

File->Switch Workspace->Other... and it will show the name of current workspace.


2017/07/10

How to Clear Code Coverage Highlight in Eclipse

Problem
I am using EclEmma, a free Java code coverage tool for Eclipse, to generate code coverage analysis report. The report looks like:


EclEmma provide source highlighting to show the result of code coverage. If I would like to clear code coverage highlight, how to do it?


How-To
Click "Remove All Sessions" in Coverage tab



2017/06/09

[Eclipse] project configuration is not up to date with pom.xml

Problem
I have Maven Project in Eclipse Mars.

One day I have an error in my project, but it does not have any negative effect to my implementation or maven build :


How-To
Although the root cause is still unclear, it works to follow these steps to get rid of this annoying error:

Step 1. Click this error => right click => Quick Fix


Step 2. Click Finish in Quick Fix window

Fixing problem in progress:

After fixing process, the problem is disappeared:

2017/06/08

[Eclipse] EclEmma - Java Code Coverage for Eclipse

In computer science, code coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. A program with high code coverage, measured as a percentage, has had more of its source code executed during testing which suggests it has a lower chance of containing undetected software bugs compared to a program with low code coverage.

EclEmma is a free Java code coverage tool for Eclipse, it brings code coverage analysis directly into the Eclipse workbench.


Prerequisite
Prepare your unit test programs:



Execution
After you installed EclEmma Plugin, you can run  Coverage as => JUnit Test


Then you can get the converge analysis report


Summary
While 100% code coverage is nice, it's not a good metric to blindly follow. 100% code coverage doesn't tell you anything other than you have tests that execute all your lines of code. Your code can still have bugs if that covered code does the wrong thing or doesn't do enough. 


Reference
[1] https://en.wikipedia.org/wiki/Code_coverage
[2] http://www.eclemma.org/
[3] https://stackoverflow.com/questions/26360245/try-with-resource-unit-test-coverage


2017/06/06

[Eclipse Plugin] EasyShell

While working in eclipse you may want to open selected file from project explorer to Windows File Explorer. 
One way is by selecting file, go to properties, copying path and open Windows File Explorer then paste that path. 



Another convenient way is to utilize EasyShell plugin

This Eclipse plugin allows to open a shell window or file manager from the popup menu in the navigation tree or editor view. Additionally it is possible to run selected file in the shell, copy file or directory path or run user defined external tools. 

EasyShell usage looks like:



Reference
[1] https://marketplace.eclipse.org/content/easyshell

2017/01/02

[Eclipse] "Annotation processor 'lombok.core.AnnotationProcessor' not found"

Problem
I fail to startup my Spring boot application, and get this error : "Annotation processor 'lombok.core.AnnotationProcessor' not found".

My tools is :
(1) Eclipse with Mars version
(2) Spring Boot 1.4
(3) JDK 1.8
(4) Lombok 1.16.10


How-To
The root cause is still unknown. But after I reinstall Project Lombok jar file, the problem has been fixed.

Steps:
(1) Close Eclipse
(2) Download jar file from https://projectlombok.org/
(3) Install Lombok
(4) Launch Eclipse


2016/11/03

[Eclipse] Source not found Problem

Problem
I am working in a Maven Project in Eclipse.
As I tried to check the Apache POI's source code, but it show Source not found error message as bellows:



Solution
Step1. Go to Preferences => Maven
Step2. Check "Download Artifact Sources" and click "OK"


Check result:



2016/02/27

How to import a git non-Java project into Eclipse

Assume I import a non-Java project from GitHub into Eclipse

1. Import non-Java project from GitHub: File => Import


2. Choose Git => Projects from Git => Next


3. Select Git Repository => Click Next


4. Choose "Import as general project" => Click Next


5. Click Finish


Import project successfully !



Owing to the project which import from GitHub is non-Java project, so I would like to change it to Java Project.

1. Right click on this project => properties


2. Click Project Facelets = > Covert to faceted form


3. Check Java => Apply => click OK


4. Done !



2015/05/04

[Maven] Error instantiating builder ‘org.eclipse.m2e.core.maven2Builder’.

Problem
My eclipse had shut down unexpectedly. As I restart eclipse, and try to do maven clean.

The console show this error message
1
2
3
4
Errors occurred during the build.
Error instantiating builder org.eclipse.m2e.core.maven2Builder.
Plug-in org.eclipse.m2e.core was unable to load class org.eclipse.m2e.core.internal.builder.MavenBuilder.
An error occurred while automatically activating bundle org.eclipse.m2e.core (524).

Solution
Step 1. Shut down eclipse
Step 2. execute eclipse with -clean parameter, i.e. "eclipse.exe -clean"
Then the Maven is working fine.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building FMS :: Entity Classes 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ fms-entity ---
[INFO] Deleting D:\git\fms\fms-entity\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.229s
[INFO] Finished at: Mon May 04 17:42:59 CST 2015
[INFO] Final Memory: 5M/120M
[INFO] ------------------------------------------------------------------------


Reference
[1] http://stackoverflow.com/questions/25929458/building-workspace-has-encountered-an-error

2015/03/26

[Eclipse] Open Call hierarchy

I am tracing Java code in Eclipse
Assume it is my tracing Java code hierarchy structure, I may trace from top to down. 

But sometimes, it may be difficult to trace and debug if the call hierarchy has many layers.

DbmAuthorizationServices (class)
   |
   |--doAuthorizeProcess (method)
           |
           |--AuthorizationRepositoryCustomImpl (class)
                 |
                 |--updateAndInsertForIssueAndYByAdmin (method)
                       |
                       |--createDbm130faFromDbm130f1 (method)
                             |
                             |--copyDbm130f1ToDbm130fa (method)



Supposed I had trace to createDbm130faFromDbm130f1 method, I forgot the caller method name
1
2
3
4
5
6
7
8
9
    private Dbm130fa createDbm130faFromDbm130f1(String userId, Date today, Dbm100fa dbm100fa,
            Dbm130fa dbm130fa, Dbm130f1 dbm130f1) {
        copyDbm130f1ToDbm130fa(dbm130f1, userId, today, dbm130fa, Boolean.TRUE,
                dbm100fa.getIssueSeqNo());
        dbm130fa = dbm130faRepository.create(dbm130fa);

        log.debug("[Insert DBM130FA] dbm130fa = " + dbm130fa.toString());
        return dbm130fa;
    }

I can click
ctrl+alt+h or Navigate=>Open Call hierarchy in this method, it will show call hierarchy. Then you can easily to know the hierarchy relationship.




Reference
[1] http://tw-hkt.blogspot.tw/2012/08/eclipse-ide.html
[2] http://mcuoneclipse.com/2012/04/15/10-best-eclipse-shortcuts/

2015/02/02

Generating entities from tables in Eclipse


Using this following procedure to generate Java persistent entities from database tables. 

1.  File => New => JPA Project => Click Next

2. Assign Project Name => Click Next


3. Click Next


4. Assign Platform and configure database connection => Click Finish


5. The sample JPA project, JPA_Project, had been created


6. Click src => Right Click => New => JPA Entities from Tables


7. Checked the tables which you would like to generate entities => Click Next


8. Click Next


9. Assign package name where your entities would like to place => Click Next


10. Click Finish


11. Check Result


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gov.nta.entity.fms;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

/**
 * The persistent class for the FMS406FF database table.
 * 
 */
@Entity
@NamedQuery(name = "Fms406ff.findAll", query = "SELECT f FROM Fms406ff f")
public class Fms406ff implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "YYY_MM")
    private String yyyMm;

    @Column(name = "REMARKS1")
    private String remarks1;

    @Column(name = "REMARKS2")
    private String remarks2;

    @Column(name = "REMARKS3")
    private String remarks3;

    @Column(name = "UPDATE_DATE")
    private Timestamp updateDate;

    @Column(name = "USER_ID")
    private String userId;

    public Fms406ff() {
    }

    public String getYyyMm() {
        return this.yyyMm;
    }

    public void setYyyMm(String yyyMm) {
        this.yyyMm = yyyMm;
    }

    public String getRemarks1() {
        return this.remarks1;
    }

    public void setRemarks1(String remarks1) {
        this.remarks1 = remarks1;
    }

    public String getRemarks2() {
        return this.remarks2;
    }

    public void setRemarks2(String remarks2) {
        this.remarks2 = remarks2;
    }

    public String getRemarks3() {
        return this.remarks3;
    }

    public void setRemarks3(String remarks3) {
        this.remarks3 = remarks3;
    }

    public Timestamp getUpdateDate() {
        return this.updateDate;
    }

    public void setUpdateDate(Timestamp updateDate) {
        this.updateDate = updateDate;
    }

    public String getUserId() {
        return this.userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

}

2014/12/15

How to revert changes in EGit

Assume I have a form bean in gov.nta.dbm.web.dto

The form bean is as following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package gov.nta.dbm.web.dto;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

import lombok.Data;

@Data
public class Dbm915rFormBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int year = 0;
    private int month = 0;
    
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

If I add one more attribute in this form bean:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package gov.nta.dbm.web.dto;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

import lombok.Data;

@Data
public class Dbm915rFormBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int year = 0;
    private int month = 0;
    private String type;
    
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

We can see this form bean had been modified and add ">" icon before file name to remind us this file had been modified.

If I would like to revert its changes, just right click => Replace with => HEAD Revision

Click OK to make sure to discard changes.

We can see the ">" label is disappeared.

And the form bean had been revert to original version:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package gov.nta.dbm.web.dto;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

import lombok.Data;

@Data
public class Dbm915rFormBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int year = 0;
    private int month = 0;
    
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}


If you find out your revert action is success, but the ">" label still show in Eclipse.
Its EGit bug, go to its website ( http://eclipse.org/egit/download/ ) to update your EGit version.