Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » IProgressMonitor missing(JDT ASTParser)
IProgressMonitor missing [message #1781408] Tue, 06 February 2018 22:59 Go to next message
Laura Lala is currently offline Laura LalaFriend
Messages: 6
Registered: November 2017
Junior Member
Hi!
I'm using Eclipse Oxygen 2 and trying to parse Java source code using the ASTParser. (I added all the JDTSource-4.7.2 jars.) However, when I try to create the AST I get this:
- The type org.eclipse.core.runtime.IProgressMonitor cannot be resolved. It is indirectly referenced from required .class files
- The method createAST(IProgressMonitor) from the type ASTParser refers to the missing type IProgressMonitor.
Other people had the same problem and said that if I add the org.eclipse.equinox.common jar, this error will disappear and indeed it did. However when I run the program, I get this: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource


The code is below (it's not mine, I got it from programcreek):

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

public class Main{

private static String readFile(String filePath)
{
StringBuilder content = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filePath)))
{

String currentLine;
while ((currentLine = br.readLine()) != null)
{
content.append(currentLine).append("\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
return content.toString();
}

public static void parse(String str) {
ASTParser parser = ASTParser.newParser(AST.JLS9);
parser.setSource(str.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);

final CompilationUnit cu = (CompilationUnit)parser.createAST(null);
ASTVisitor visitor = new ASTVisitor() {
Set nodeNames = new HashSet();

public boolean visit(VariableDeclarationFragment node) {
SimpleName nodeName = node.getName();
this.nodeNames.add(nodeName.getIdentifier());
System.out.println("Declaration of '"+nodeName+"' at line"+cu.getLineNumber(nodeName.getStartPosition()));
return false;
}

};
cu.accept(visitor);
}

public static void main (String[] args) {
String file = readFile("src/Person.java");
parse(file);
}
}
Re: IProgressMonitor missing [message #1781416 is a reply to message #1781408] Wed, 07 February 2018 06:57 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Of course when you run the program, you just include the jar that provides IProgressMonitor in your launch.

Note that even is you are developing a stand alone application it is still much easier (in my opinion) to convert the project to a Plug-in project so that the classpath is managed for you via dependencies specified in the MANIFEST.MF. Then you don't need to put anything specific on the classpath; the dependencies are automatically on the classpath via PDE's plugin container classpath entry; the even works for a Java Application launch.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Java 9 problem with eclipse (installation problem ) - [solve ]
Next Topic:Modular project: How add dependency to other project only on runtime to solve cyclic dependency?
Goto Forum:
  


Current Time: Thu Apr 25 08:34:31 GMT 2024

Powered by FUDForum. Page generated in 0.02832 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top