Tom Klino
Tom Klino

Reputation: 2514

Packages not found while compiling java

I'm trying to compile my java file to class. It is a plugin to a much larger program and it runs fine from eclipse when running from source.

I work in Linux, and in shell I type the following javac MyPlugin.java

This is just some of the output:

MyPlugin.java:11: package javolution.util does not exist
import javolution.util.FastList;
                      ^
MyPlugin.java:12: package javolution.util does not exist
import javolution.util.FastMap;
                      ^
MyPlugin.java:14: package org.apache.log4j does not exist
import org.apache.log4j.Logger;
                       ^
MyPlugin.java:15: package org.jwebsocket.api does not exist
import org.jwebsocket.api.PluginConfiguration;
                         ^

My assumption is that the rest of the errors are caused because the imports cannot be reached.

Do I need to add something to the original command to have these imports included?

Upvotes: 0

Views: 4398

Answers (3)

Reimeus
Reimeus

Reputation: 159844

You are missing jars from the following projects:

http://javolution.org/

http://logging.apache.org/log4j/1.2/

http://jwebsocket.org/

You can download the missing JARs and include them in your compilation classpath.

Alternatively, you could let maven manage the download and compilation of your application.

Update: Gathering all external jars together in one location

To get all your external libraries in one place you could create a runnable JAR in eclipse using:

Export...->Java->Runnable JAR File

Enter your_temp_jar.jar and click

Copy required libraries into a sub-folder next to the generated JAR

After clicking Finish all the required jars will be in a folder called your_temp_jar_lib.

Upvotes: 1

bmargulies
bmargulies

Reputation: 100153

Typing javac at the command line is not a viable or scalable way to build java code. While you could use -cp to javac to add the required dependencies to this compilation, you'd be far better served by learning ant or maven.

Upvotes: 0

Bharat Sinha
Bharat Sinha

Reputation: 14373

You should specify the jar files which contains following classes in your classpath.

javolution.util.FastList
javolution.util.FastMap
org.apache.log4j.Logger
org.jwebsocket.api.PluginConfiguration

you can use -cp to specify classpath of jars.

Upvotes: 0

Related Questions