0

I have following code:

package deerangle;

public class Renamer implements org.jetbrains.java.decompiler.main.extern.IIdentifierRenamer {

    public static void main(String[] args) {
        System.out.println("HEY");
    }

    public long counter = 0;

    public boolean toBeRenamed(Type elementType, String className, String element, String descriptor) {
        return !(elementType == Type.ELEMENT_CLASS && className.length() < 4);
    }

    public String getNextClassName(String fullName, String shortName) {
        return "Class" + ++counter;
    }

    public String getNextFieldName(String className, String field, String descriptor) {
        return "field" + className + "C" + ++counter;
    }

    public String getNextMethodName(String className, String method, String descriptor) {
        return "method" + className + "C" + ++counter;
    }

}

This file, Renamer.java, is inside the folder deerangle.

First, I run javac deerangle/Renamer.java.

Then I run jar cvf Renamer.jar deerangle/Renamer.class.

This creates a jar file which contains my class file.

When I now run java -cp Renamer.jar deerangle.Renamer, it says: Error: Could not find or load main class deerangle.Renamer

I don't think It really matters, but here is the Class I implement in my code:

// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.main.extern;

public interface IIdentifierRenamer {

  enum Type {ELEMENT_CLASS, ELEMENT_FIELD, ELEMENT_METHOD}

  boolean toBeRenamed(Type elementType, String className, String element, String descriptor);

  String getNextClassName(String fullName, String shortName);

  String getNextFieldName(String className, String field, String descriptor);

  String getNextMethodName(String className, String method, String descriptor);
}

Why am I getting an error? What am I doing wrong?

Ian Rehwinkel
  • 2,486
  • 5
  • 22
  • 56

1 Answers1

1

If I take out the interface you've specified and follow all your steps, everything works fine and they word HEY prints out to my console. So I suspect this has to do with the IIdentifierRenamer interface your implementing and that all your dependencies are being found at compile-time but not during run-time.

An option is to package all your dependencies into your jar file, so that the are available during run-time.

I would recommend you use a build tool such as Maven to Gradle for this.

Just recently helped someone with a similar issue, but they had "mavenized" their project ... Error: package does not exist

Ambro-r
  • 919
  • 1
  • 4
  • 14