getting NoClassDefFoundError

22 views
Skip to first unread message

theonlygusti

unread,
Jan 7, 2017, 5:26:36 PM1/7/17
to jcommander
I am trying to use JCommander in a project,

import com.beust.jcommander.Parameter;
import com.beust.jcommander.JCommander;

public class Commander implements CommandExecutor {
  public Commander(Plugin plugin) {
    // ...
  }

  private class CommandTemplate {
    @Parameter
    private List<String> parameters = new ArrayList<>();
  }

  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    /* This section causes the error:
     * java.lang.ClassNotFoundException: com.beust.jcommander.JCommander
     */
    CommandTemplate template = new CommandTemplate();
    new JCommander(template, args);

    for (String parameter : template.parameters)
      sender.sendMessage(label);
    return true;
  }
}

I am wondering how i can fix the above code to not error out

Cédric Beust ♔

unread,
Jan 7, 2017, 5:28:05 PM1/7/17
to jcommander
Make sure you are importing JCommander with your build tool correctly. The doc explains how to do this with Gradle and Maven:



-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "jcommander" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

theonlygusti

unread,
Jan 7, 2017, 5:34:18 PM1/7/17
to jcommander, ced...@beust.com
I aded the dependency:

<!-- from the jcenter repository, jcommander is used to parse in-game commands -->

  4     <dependency>

  3       <groupId>com.beust</groupId>

  2       <artifactId>jcommander</artifactId>

  1       <version>1.48</version>

92      </dependency> 


-- 
Cédric


To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+...@googlegroups.com.

theonlygusti

unread,
Jan 7, 2017, 5:36:37 PM1/7/17
to jcommander, ced...@beust.com
I solved it. My maven was compiling two jars to the same location, and the one without dependencies was being loaded instead of the dependency one.


On Saturday, 7 January 2017 22:28:05 UTC, Cédric Beust ♔ wrote:

-- 
Cédric


To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages