Eclipse (probably) doesn't compile external jars - java

Suddenly, all my code depending on external jars doesn't work.
For example:
Jsoup.parse(str)
gives:
could not resolve type: org.jsoup.Jsoup
And i'm 100% sure that it is in the build path.
Maybe it happenned because I updated the ADT plugin and the platform tools to the latest version, but it doesn't make sense...
But it started occuring since I updated those.
So apparently eclipse doesn't compile those jars. (In code, it DOES resolve the jars types)...
Do you maybe know what is the problem?

This has nothing to do with compilation: jar's are already compiled.
You only need to add the jar to your project classpath so Eclipse will know to run java with the .jar. You can do this with "Context/Right click menu->Properties > Java Build Path > Libraries" (source). For portability I recommend placing the .jar in a subdirectory of your project. A "lib" folder in your project root (where "bin" and "src" are too) is commonly used.
Also note that to run your program you will need to add the dependency .jar to your java command, but with a little searching you can find out how to include the dependency .jar in your own combined .jar.

You have to put the libraries in /libs folder of your project (if you are using Eclipse you choose "Add JARs.." not "Add external JARs..")

Related

Difference between Run in eclipse and going to the project folder and using the .jar

I'm trying to find more information on how eclipse handles Running a project.
I want to understand it more because I have an issue I'm currently having where apache-poi .jar files which have been included into the classpath of my project will work properly when the project is ran through eclipse, but will not be detected when going to the same projects folder and running the main jar file to start the program.
It gives me the error: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell (although sometimes instead of Cell, it's Sheet)
What could I consult to understand what is going on here, and possibly solve this issue?
Your NoClassDefFoundError indicates that the library was not available while running the jar.
This depends upon how you are exporting your project into the jar file.
If you're using eclipse to do so, you can:
Export->Java->Runnable Jar to create a jar that includes its dependencies
Make sure to check Package required libraries into generated JAR.
This will make all your jars (in build path including apache-poi.jar) as a part of the final jar.
It runs from eclipse because libraries are on the build path of the eclipse which makes them available in the classpath.

Running an executable jar of SWT/JFace project on the other Computers

I am creating a SWT/JFace project and exporting as executable jar. But this jar is not working on the other computers. When use double clicks the jar nothing happens. I am sure that other user has JRE installed.
I think problem is the Referanced Libraries. Beause near the libraries its written
C:\Users\Turgut - İhracat.p2\pool\plugins\org.eclipse.osgi_3.12.50.v20170928-1321.jar
Here is the Screen capture of libraries. Any helps will be apriciated..
Remove all referenced jars,
Create a 'lib' folder in your project,
Paste your referenced jars into
'lib' folder;
Add these jars into 'classpath'
If this not work, execute your jar via command line to see the error.

Ant Java Build Path set by Eclipse is Missing a Library at Compile Time

I'm using eclipse and ant to compile a java project. The ant compile script calls javac using a classpath refid of classpath, which is set based on System Property variable java.build.path.
My java.build.path variable is missing a library that was specified in
Project->Properties->Java Build Path->Libraries.
That is, the external jar was properly added to the list of libraries to add to the build path, is not missing or corrupt, and I have every expectation that eclipse would include the library in the build path. My build fails because java.build.path is missing this library.
Furthermore, the file <projectDir>/.classpath contains a valid classpathentry element for the missing jar file.
When building, javac fails at an import statement, claiming that the package does not exist. The value of java.build.classpath contains many of the libraries I set in the project properties, but does not include the missing library. Its as if the project property for that external jar was never set.
For what its worth, the missing library is jboss/lib/jbosssx.jar
Any help here would be appreciated.
At first,
Download jbosssx.jar jar file from this link
Then keep the jar file in the folder jboss/lib
Hope it will solve your issue.
UPDATE:
Sometimes jar files need to keep in lib folder physically. For this reason, you can put the jar file in your project lib folder.
I found where my configuration was messed up.
Using External Tools Configurations within eclipse, I found another Classpath settings tab for my ant build that did not contain my library.
Adding my library here caused the build to succeed!
Skywalker, thanks for the suggestion. :)

External jars in eclipse plug-in

I'm creating an eclipse plug-in and I'm having trouble with external jars. In my plug-in I start an application which requires some external jars. What do I have to do to export them automatically with the rest of the plug-in?
Thanks in advance :)
Open your plugin.xml
Go to Runtime tab and add your JAR in the classpath section
By following the steps below, the external JARs will be included when you export your plug-in:
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
Open the build.properties in your plug-in project and check the JARs you want to include in the build in the Binary Build section on the left.
This is an easy way, though it does create an additional plug-in.
In Eclipse:
Choose New>Other, then Plug-in Development>Plug-in from existing JAR archives.
Choose the jars you want to include.
On the next page, configure the plug-in.
In your plug-in's manifest, add the new plug-in as a dependency.
In your plug-in's Properties, add the new project under Java Build Path on the Projects tab.
Edit: You may be able to combine the jars into your plug-in by instead combining both suggestions of Zsolt and user714965 below.
This is what has worked for me. If they are truly external, and this is a project for your company that is not going to be in the "wild" and you control the environment, and you have them out on the file system say at /opt/java/lib/somedir/some.jar you can tell the bundle where to find them by adding them to the Bundle-ClassPath entry in the MANIFEST.MF under META-INF. The syntax is:
Bundle-ClassPath: .,
external:/opt/java/lib/somedir/some.jar,
external:/opt/java/lib/someotherdir/someother.jar
Also it would be prudent to use these in your build path so that you are working with the same jars in both build and runtime environments.
I have done this where the Jars are multi-purpose (such as apache-commons) on our file systems and again we control the environment.
Reference the following:
http://www.eclipsezone.com/eclipse/forums/t51870.html
Copy the required external JAR files into a folder in your plug-in project; I like to call this folder lib, but whatever works for you.
..but as apposed to Zsolt Török (his solution did not work for me) I double-clicked on the plugin.xml, went to the build tab, at the bottom, I clicked Add JARs..., and hey presto, it showed my project, and I then navigated to lib and included the external jar, as per step 1.
The approach from Andy Thomas mostly works, but you also need to export the packages needed by the existing plugin in the new wrapper plugin so that they can be accessed by the plugin at runtime.

Add python module to JAR classpath in Eclipse

I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-path entry for 'C:Projects/this_project/src/com/company/python/'
When browsing through the generated JAR file with an archive manager, the python module is in fact inside of the JAR, but when I check the manifest, only "." is in the classpath. I can overlook this issue by manually dropping the module into the JAR file after creation, but since the main point of this project is automation, I'd rather be able to configure Eclipse to generate properly configured JAR automatically. Any ideas?
*NOTE*I obviously cannot run the program successfully when I do this, but removing the Python source folder from the classpath in "Run Configurations..." makes the error go away.
Figured it out, had to add the source folder with the Python module in it as a class folder in the Build Path project properties. Not sure if this next part is necessary or not, but since the module is not compiled, I added the folder again as "Attached Source" after adding the class folder.
Have a look at the maven-jython-compile-plugin and its demo project at http://mavenjython.sourceforge.net/ . It allows bundling jython with dependencies into a standalone jar.

Categories

Resources