Adding an External .jar File to Eclipse

I'm having trouble adding a .jar file downloaded for my Java project. This is really the first time I have used an eclipse, so please bear with me for some reason (I don’t know why), I just find it somewhat confusing.

I know that to reference different class files you just need to create a class library and add it to the build path. From there, everything that needs to be done (if I do not understand this for any reason) uses the "import" keyword to import any .jar, .java or .class / .interface files needed into the project.

I tried this with my .jar. I refer to the build path (all I did was just copy the jar into the project directory and then use the build path parameter to add it from the outside), but ever try to call the delegate object, which is obviously part of the file .jar, he will not read.

Am I missing something? Seriously, anyone who knows the answer to this question - you rid your mother of a headache. And before anyone asks - yes, I looked for it to death. I found similar questions, but nothing that really struck what I was looking for. Either that, or I just lack common sense.

+6
source share
6 answers

There are several possible reasons because the question did not mention the specific failure and where it occurred. The following is a list of possible reasons I could think of, but this may not be exhaustive:

  • You can import a class in another package only if the class is publicly available. The only exception is when you use the class in one package. If the class is an inner class designated as private, then you are well and truly out of luck. The expert class may not be publicly available and why you cannot use it. This problem should be caught by the compiler.
  • The directory structure in the JAR may not match your package import statements in your classes. This may not be necessary since Eclipse should provide possible fixes, but it is best to check this. Again, the compiler should complain if that is the case.
  • If the problem is at run time, then most likely the JAR is not available in the path to the runtime. You need to configure the Runtime to add the JAR to the runtime path. Refer to the Eclipse documentation for startup configurations if you need to know how to change the path to the runtime.

Note:

  • Exporting classpath string entries will be relevant for other projects that depend on the respective project; unprocessed records should be re-imported if required by other projects. This does not apply to startup configuration.

Update

Every Java application needs a main(String[] args] method to start execution. This is the entry point for the application. From the comment, it looks like the main method is in another class. If so, this class should be used to start the application. In Eclipse, for a class that lacks this entry point, “Run configuration” can be used, which will lead to the described error. This can be fixed by creating a new Run configuration for the class with the specified entry point. This can be done in one of the following ways:

  • edit your existing Run configuration to use the class you want (the one that has the main method). See the above link in the third paragraph. Edit the value of the class to be launched.
  • Create a new launch configuration for the required class. Usually you need to go to the desired class and start the application (using the Alt+Shift+X+J shortcut) from the specified class.
+5
source

Right click on the project-> BuildPath-> Libraries-> Addexternaljar , and then click ok, and if it doesn’t work, you should go to

  Order and Export tab 
and check the jar that you just added to your project. This will solve your problem.
+6
source

i ran into a similar problem with spring jar files, but then I tried with different jar files and it works, so I think the classes defined in jar files were private and inaccessible outside of jar, so you could not access the file,

thank you Raju Rati

+2
source

Right-click on the project ---> Build Path ---> Configure Build Path ...---> On the left side you should select Java Build Path ---> Libraries ---> Add External JARs --- > OK ---> OK

+1
source

Steps to add a jar file to eclipse 1. right-click on the project 2. click Path Bullets-> configure path 3. click on the Java build path 4. Go to the libraries tab. 5. Click on the add external tab jar 6. select the jar file 7 click OK

0
source
  • Copy the .jar file to the libs folder that you want to add to your project.
  • Right click on .jar file -> Add build path

Done.

0
source

Source: https://habr.com/ru/post/890117/


All Articles