EnderEgg
EnderEgg

Reputation: 335

How to compile in Eclipse so I can use outside? (without opening eclipse)

I searched for an answer but didn't found it, so here it goes.

When I try to execute the program from cmd (with javac, I guess), I get this error:

D:\Libraries\workspace\bucky\bin\bucky>java apples
         Exception in thread "main" java.lang.NoClassDefFoundError: apples (wrong name:bucky/apples)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I wanted to be able to send the application to my friends. I'm very new to this, so if it's a stupid question, it's because I only started a few days ago. I'm using java.util.Locale and java.util.Scanner if that is important. If I need to past the code, tell me. It's about 130 lines.

Thanks (If you noticed, I'm learning on Youtube, "thenewboston" is the user that made the turorials)

Upvotes: 1

Views: 55

Answers (2)

alpham8
alpham8

Reputation: 1362

That should be really simple. Eclipse got an export dialog. I think it was at File -> Export. There you can choose you desination for your compiled JAR and which external JARS should be inlcuded (e. g. JDBC).

Upvotes: 1

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285450

You should post how you try to run your code and the error message here as text. Just copy and paste from the Windows cmd box -- easy to do:

right click cmd window -> click select all -> press enter

and now it's copied to the clipboard.

It looks like you may be trying to run this without taking packages into consideration.

i.e., from the bin subdirectory, call `

otherDirectories/bin>java bucky.apples

But more importantly, if this were my project I'd have Eclipse export it first as a runnable jar file, and then simply run the jar file.

The menu order is:

Right-click on Project -> Export -> Java -> Runnable Jar File

Upvotes: 2

Related Questions