uwol / proleap-vb6-parser

ProLeap ANTLR4-based parser for Visual Basic 6.0
MIT License
79 stars 26 forks source link

java.lang.NoClassDefFoundError: io/proleap/vb6/VisualBasic6BaseVisitor #15

Closed Iter-Ator closed 6 years ago

Iter-Ator commented 6 years ago

I tried to follow the "Getting started" steps. I added the repository and dependency. My code looks like this:

package com.mycompany.app;

/**
 * Hello world!
 *
 */
public class App 
{

    public static io.proleap.vb6.asg.metamodel.Program program;

    public static void main( String[] args ) throws java.io.IOException
    {
        //System.out.println( "Hello World!" );

        // generate ASG from plain VB6 code
        java.io.File inputFile = new java.io.File("src/test/resources/test.cls");

        program = new io.proleap.vb6.asg.runner.impl.VbParserRunnerImpl().analyzeFile(inputFile);

        // traverse the AST
        io.proleap.vb6.VisualBasic6BaseVisitor<Boolean> visitor = new io.proleap.vb6.VisualBasic6BaseVisitor<Boolean>() {
          @Override
          public Boolean visitVariableSubStmt(final io.proleap.vb6.VisualBasic6Parser.VariableSubStmtContext ctx) {
            io.proleap.vb6.asg.metamodel.Variable variable = (io.proleap.vb6.asg.metamodel.Variable) program.getASGElementRegistry().getASGElement(ctx);
            String name = variable.getName();
            io.proleap.vb6.asg.metamodel.type.Type type = variable.getType();

            return visitChildren(ctx);
          }
        };

        for (final io.proleap.vb6.asg.metamodel.Module module : program.getModules()) {
          visitor.visit(module.getCtx());
        }

    }
}

The building is successful. But if I try to run it, I get this error:

Error: Unable to initialize main class com.mycompany.app.App
Caused by: java.lang.NoClassDefFoundError: io/proleap/vb6/VisualBasic6BaseVisitor

What do I wrong? Did I miss something?

My test.cls is the same as the "Input: VB6 code" from the example

uwol commented 6 years ago

Seems, that your MAVEN project dependencies are not set up correctly, so not an error in the parser or parser library.

  1. Please put following MAVEN pom.xml in your project folder:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <name>vb6-example</name>
    <description>VB6 example</description>
    <groupId>io.proleap</groupId>
    <artifactId>vb6-example</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <repositories>
        <repository>
            <id>maven.proleap.io</id>
            <url>http://maven.proleap.io</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>io.github.uwol</groupId>
            <artifactId>vb6parser</artifactId>
            <version>2.1.0</version>
        </dependency>
    </dependencies>
</project>
  1. If you are using Eclipse: Right click project -> Configure -> Convert to MAVEN project
  2. Save your App class somewhere in src/main/java
  3. Compile errors should be solved, the main method should work.