How to add a JAR library withou an IDE? - java

I'm facing difficulties on adding a JFreeChart library on my Java project (I use Windows 8). This is what I've already done:
1 - Unzipped JFreeChart
2 - renamed the archive jfreechart - 1.0.19 to jfreechart
3 - Added it's path to classpath: .;C:\Users\Victor\Desktop\projects\EP2 - IA\jfreechart - 1.0.19\lib\jfreechart.jar;
4 - Added in the beggining of my Java file: import jfreechart.*;
5 - Copied the jfreechart archive to the same directory of my project
But when I try:
java -classpath jfreechart.jar MyClass.java
it returns that the "jfreechart package does not exists"
As I'm an old school programmer that still uses Notepad, I've found nothing useful on Google about it.

You are using the wrong import statement. Try this instead:
import org.jfree.*;
You also may need the following library:
jcommon-1.x.y.jar
For future reference, you can view the contents of a JAR file using the command line jar command:
jar -tvf jfreechart-1.0.19.jar

Related

How to resolve "error: package javax.json does not exist" for Oracle Java 8?

I have been using 3rd party libraries to process JSON, but I hear Java has one, and I'd rather use that instead. I made a test class that did nothing but import the package and print hello world, but I got the following error.
JsonTest.java:1: error: package javax.json does not exist
import javax.json.*;
^
1 error
I updated my jdk to the latest version (jdk-8u281 as of Feb 28, 2021) and tried again, but it didn't work. Then after some research, I found out that JSON capabilities ONLY exist in Java EE, not Java SE.
After figuring that out, I went to this link HERE to download the Java EE version, but then I didn't know what to do. I extracted the zip file as instructed, and ended up with a folder called /glassfish5. I didn't know what to do with it, so I just tossed it into the /Java directory containing my other jdks.
I looked up guides and youtube videos, but they all seem to stop after you unzip the file. Some show you how to start the database/domain/whatever, but none really tell you how to get the ability to use Java EE (and thus, the JSON functionality contained within it).
And what's even more confusing is that, according to the website, I definitely downloaded Java EE, but why is it giving me a folder called /glassfish5? Is glassfish5 the new Java EE? How do I move forward from here?
This is really obtuse, but the jar file containing Java EE is located deep within that /glassfish5 folder.
You can find the Java EE jar file by navigating to {download location}/glassfish5/glassfish/lib/javaee.jar -- After you have this, just add it to your classpath, then you are done.
~
I don't understand why they would do that, but if you click around and just aimlessly wander through your /glassfish5 folder, you will find plenty of other jar files around.
Of course, if you don't want to do that, just go to your /glassfish5 folder, go to /bin, then do ./asadmin start-database (using powershell or gitbash). Around the halfway point, you'll find a list of jar files that might be useful.
------------------ Java Information ------------------
Java Version: 1.8.0_281
Java Vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_281\jre
Java classpath: C:\Program Files\Java\glassfish5\glassfish\lib\asadmin\cli-optional.jar;
C:\Program Files\Java\glassfish5\javadb\lib\derby.jar;
C:\Program Files\Java\glassfish5\javadb\lib\derbytools.jar;
C:\Program Files\Java\glassfish5\javadb\lib\derbynet.jar;
C:\Program Files\Java\glassfish5\javadb\lib\derbyclient.jar

import java package into a jython project in Eclipse or PyCharm

Using Eclipse + PyDev + jython. Need to import a java package to use a Java class inside a Python program (using Max OSX).
For import, I mean statement in Python like from com.a.b.c. Wondering where should I put the Java jar file which contains com.a.b.c? Thanks.
BTW, if any PyCharm + jython based solution, it will be also great. :)
This question is not duplicate from the other one, the other one's title is bit mis-leading, and that one is about how to install jython.
The import semantics do not differ that much from CPythons from what I see in the Jython Docs.
First a search is made for the .jar file in the current directory; if it is not found there, it is looked up in the directory containing the core Jython libraries. The classpath which corresponds to Javas CLASSPATH is then searched along with the site-packages directory containing external libaries. I am not yet sure what __pyclasspath__ is.
So if a package is not found in those directories an import error is raised. You have two options:
Either add the .jar in one of the directories (typically you should never add it to the directory containing the core libs.
Add the .jar to your CLASSPATH.
Add the path to your .jar in sys.path.
For the first case, either move it to the current direcory or in site-packages.
For the second case see here on how to add a .jar to your CLASSPATH.
For the third simply call sys.path.append("path_to_jar") to include the directory containing your .jar file to sys.path.

Netbeans automatically cloning my jar based packages with their empty 'name equivalents'

I'm new at java programming so i just wanted to try something with ssh understand how it works and so i downloaded a java library which is mentioned in this Stack Overflow answer
. After a lot of failed attempts on importing this library into netbeans. I decided to simply put the files into my src folder. But Netbeans ide duplicating packages in the jar file with their 'name equivalent' empty packages and this prevents me to reach the classes in the packages because the IDE and the Code completion automatically sees the empty packs.I've search the network couldn't find anything about this problem.I 'm ready to share any log files if there are any of them .Here is my screenshot about this situation.
Screenshot Attachment
OS : Linux Mint Rosa
IDE : Netbeans 8.1 Linux version
Edit : I Already looked these topics
How to use .jar files in NetBeans? : At first i've tried this and in this solution netbeans not duplicating any empty packs but when i start to type somethin' like that import sshj.foo.*; Auto Complete can't find anything and also if i try to write the whole path to a specific class which is in an specific pack IDE gave me an error the pack that you're looking for is not exist.Secondly I've tried this
and got the same issue at first try.I can see the packs,classes and other stuff but still can't reach them in a random class which is imported project.
How can I include external jar on my Netbeans project : I've tried this and also this ran perfectly without errors as they said but when i try to reach classes still got the same problem so nothing changed.
How to add a JAR in NetBeans :
In this topic all of the replies explained types of libraries.That's not even related to my problem
How to use classes from .jar files? : I've tried to do explained in this reply also and I've transfered my jar file into a compiled .class extension file and this didn't solve my issue too.
I've just solved that problem with downloading part of the libraries from here.
All libraries need to contain three kind of jars ;
1 . Compiled files containing jar (with extension .class)
2 . Source files containing jar (with extension .java)
3 . Javadoc files containing jar (optional)
Open a project find libraries folder on ide right click and choose Add JAR/Folder specify the directory that contains the compiled files.After importing library hit right click over it and choose edit then specify the source files and javadoc files directories you are ready to roll.

How to run Java source file with multiple packages using Eclipse

I am a beginner of Java and Eclipse. Now I have a Java plugin and its source file. I want to debug the source file in Eclipse to see how each part of the code runs. I created a new project named first trial, and the structure is like this:
src\analyser: 1.java,2.java,3.java...
GUI: 1.java,2.java,3.java,4.java,5.java...
GUIPanelWindow: 1.java...
main:1.java...
segmentation: 1.java...
tracking: 1.java
There are more than 5 classes in each package. It's based on the third party-Fiji, so at the beginning of each class it shows the syntax like this "import ij.Prefs","import ij.plugin.PlugIn" and so on.I have also added external JAR files into the library, but it also shows the error "The import ij cannot be resolved ". Thus, the result of debug shows that
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at main.LineageTracker.main(LineageTracker.java:320)
I want to know if I can debug a Java source file like this or what other steps I should do? I will appreciate your help.
Following up on PM 77-1's comment, assuming ij is in one or more JAR files, here's how to add those JAR files to your Build Path (tested on Eclipse Kepler, the most recent version):
Right-click on your project (first trial) in the Package Explorer.
Select the Build Path submenu.
Choose Add External Archives.
In the resulting JAR selection dialog, choose the JAR files for ij. You can select more than one file.
Hit OK.
The JARs you selected will appear in the Package Explorer, below src, under Referenced Libraries.
Build and hopefully it will work!

Can't import packages from jsqlparser library

I added the jar jsqlparser-0.7.0 to my Netbeans IDE (right clic on libraries / Add Jar file) but i still can't use its packages. what could be the reason . The library is created on 2011 it could be it is not supported by JDK7?
The JAR file "jsqlparser-0.7.0.jar" is not a regular Java library. It is a simple zipped file containing several artifacts: a source and a documentation directory, some testfiles, and - what you need - another JAR called "jsqlparser.jar" in a lib directory.
This JAR is the "real library" that you must add to your project. Additionally, all packages inside this library start with "net.sf.jsqlparser".
Just put this:
import jsqlparser.*;

Categories