Where to put external banks?

I use Eclipse (3.4), and compiling classes does not raise any warnings or errors. My project uses an external jar file.

Where do I need to put this external jar file so as not to get java.lang.NoClassDefFoundError when using this class from another project (not in Eclipse)?

I could just extract the jar into the project folder, but that doesn't seem right.

Edit: This question is not about importing containers into Eclipse, but about using them outside of Eclipse.

+42
java eclipse jar ganymede
Nov 28 '08 at 11:17
source share
9 answers

If you want to include a JAR file in an Eclipse project, you usually create a "lib" folder inside the project folder and put the file there. Then you need to tell eclipse to include it in your class path so that your code compiles and runs inside eclipse.

For this:
- Go into the properties of your project
- Select "Java Build Path" in the left column
- Select the "Libraries" tab in the center of the window
- Click the "Add JARs" button - this will give you a list of your projects in eclipse - expand your project and in the lib folder - your bank will be there.
- Select the JAR, click β€œOK” and β€œOK” again from the properties window.

Now your code will compile and run.

+53
Nov 28 '08 at 11:28
source share

put it in jre/lib/ext folder

everything said about the path to classes is true, but it is a consistent and reasonable place for his life.

you can find out your jre folder by looking at the JAVA_HOME environment variable on Windows.

+19
Nov 28 '08 at 11:23
source share

It doesn't matter where you put it, but you need to set up another project without Eclipse to put external banks in its class path - or use the extension directory mechanism if necessary. (This is simpler, but making it explicit, perhaps better, is.)

+7
Nov 28 '08 at 11:20
source share

Simon's answer seems best, but a bit outdated. Share this Oracle Installed Extensions document.

Starting with Java 6, JAR extension files can also be placed in a location that is independent of any particular JRE, so extensions can be shared by all JREs that are installed on the system.

It says that for Windows you should place your extensions here% SystemRoot% \ Sun \ Java \ lib \ ext.

+4
Dec 24 '13 at 11:12
source share

You just need to reference it using the -classpath parameter in a folder that is not included in the eclipse workspace, that is, it does not depend on the eclipse at all.

Warning, you can execute your other project using java -jar if you are linking to your external jar with the -cp option ( see this question )

+1
Nov 28 '08 at 11:23
source share

I put it in a new folder. This folder must be included in the build path. It doesn’t matter if it is in Eclipse or outside. Eclipse has a specific project build path and passes that path to javac. If you want to run javac outside of Eclipse, you need to manually pass the build path.

0
Nov 28 '08 at 11:21
source share

I know this is not exactly what you are asking, but do you think you are using Maven? Some of the plugins, such as assembly, may be useful in such situations.

0
Nov 28 '08 at 11:32
source share

Take the can inside Eclipse, as James Camfield wrote.

Then, when you create (Ant, Maven, manually) for distribution, make sure that the jar file is included in or from your jar or war or ear application or any other file and that all startup scripts include it in the classpath using the command option -classpath strings for java, as VonC wrote.

Don’t worry about inserting jars into the java extensions folder, all you have to do is make you forget about it when it comes to sending your code to a third party, because they will not be configured at the end.

0
Nov 28 '08 at 11:43
source share

Create a shared lib directory and put this jar and any other common jars files you might have there. If you are using Maven, you already have it in the form of a local repo.

In Eclipse, create a classpath variable for this directory, and then use it to reference your jar file in your projects. If you have several projects that meet these conditions, it will greatly facilitate life. It also makes it easier to change the location of the root directory if you are moving from a local drive to a network drive.

In an external application, you will also include this jar file from its general location in the application class path.

0
Nov 28 '08 at 14:23
source share



All Articles