How to import projects (i.e from github) to my application - java

So I have been working on a project where I need to process some Java code. To do this I decided to use JavaParser.
On their website JavaParser, I see a 'Getting Started' guide that explains how to include JavaParser in Maven and Gradle but as I am not using either, what I think I need to do is get some javaparser.jar and add that to my classpath?
My question is, I couldn't find anywhere to download this .jar file on the JavaParser website or JavaParser GitHub, so is this the right way to do this? Should I be cloning projects I want to make use of and create my own jar files? Do I need to be using Maven?
I ended up finding the jar file on a third party website instead of finding it on any official JavaParser page and that gave me the impression I was doing something wrong.
All answers appreciated!
-James

You can manually download the necessary jars from public maven repositories. As I see you need these two:
https://mvnrepository.com/artifact/com.github.javaparser/javaparser-core
https://mvnrepository.com/artifact/me.tomassetti/java-symbol-solver-core
Pick a version you like and on its page there is a download jar link.

Related

How to implement RichTextFX in JavaFX project

I started to work on a JavaFX project in which I want to add a copied text without to change the format and images from my driver (it should work like open office). The images should be able to be placed within the text on different positions.
Therefore, I need a controlfield which can handle a rtf format.
For this purpose I found RichTextFX. In the documentation is explained how to run RichTextFX with Maven or Grandle. I dont use Maven or Grandle, therefore I would like to know if there is a possibility to run RichTextFX without using neither of them. I added the jar file to my project and copied the source code of RichtextFX Demo. Afer that i got many errors and it is not able to run.
Can someone maybe guide me trough this problem?
I already figured out how to use RichtextFX.
For everyone who wants to use RichtextFX but doesn't use Gradle or Maven here is an explanation how to run RichtextFX-Demo:
get the fat JAR file (including dependencies)
integrate the JAR in your project
copy all classes in your project from the following link :enter link description here
add the pngs and the rich-text.css to your project from the following link : enter link description here
I can't answer other questions. I hope this helps to run the Demo.

Simplest way to download a jar from the command line given the fully qualified name of a class

For example, if I know that I have to do the following import in my program
import org.apache.commons.math3.distribution.NormalDistribution;
what is the fastest/simplest way to determine in command-line what is the package containing this class and download its jar for the current version?
I read this question and it is about Eclipse and every answer assumes you already have the jar file you're looking for, not going into details about downloading it though e.g. Maven Central.
On the one hand, the answer is very simple and on the other it isn't. The easiest way with almost no setup is to download the jar directly from the project site, in your case this one. If you can't find the project host, you may search on Maven Central. Don't forget to add the jar to your classpath after the download.
A complete command line solution requires a build tool like Maven or Gradle. They require some setup but once set up, you just tell them which library you need and they'll do the download for you.
You should be able to "curl" grepcode.com's website, parse the results to identify the jar file. By parse, I mean, you may have to write your own code to parse the results by command line. Jsoup can help with a lot of this.
Example class
http://grepcode.com/search/?query=org.apache.commons.math3.distribution.NormalDistribution
Jar file -> commons-math3
Then "curl" search.maven.org using the advanced search. Parse the results, identify the link you need.
http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22commons-math3%22
You can play around with the advanced search here. http://search.maven.org/#advancedsearch%7Cgav
Be careful as sometimes the same jar file is listed multiple times on search.maven.org. So I gravitate towards the ones that supply source jar or have the most versions.
There is no simple solution. Hundreds of different artifacts in Maven Central can contain a particular class. How would your command line decide which one to give you?
As per this link, there is a REST API to search.maven.org. You can use this to retrieve the (long) list of artifacts for a class. So, you could write an (e.g.) python program to do something, but it would not be very useful.

Adding External jar copy to Project

I created a project but I am using an external library for it. enter link description here
I added the library to my Beans as follows:
Right click on folder "Libraries"
Add Library
Create...
Gave it a name "gson 2.7"
Picked the class, source and javadoc files.
I went on and continued programming and then I added my code to Github. Then when I cloned it my Library was missing.
How can I fix this ? How can I make it dynamic so I dont have to worry about this anymore. In other words I need to add the library to my code and not just the reference.
Thanks a lot for the help
Just upload a copy of your library to github.
I have not used netbeans, but from what I understand it adds the jar somewhere outside of your project directory, and it simply adds the location of the jar to your classpath. When you upload and then clone the project from github, the jars are not uploaded/cloned, and the project structure metadata for your project is also lost from netbeans.
My suggestion is to learn and start using a build tool like maven. It takes up the responsibility of adding your dependency libraries everytime, given that you have an internet connection. It also adds the libs to the target directory of your project folder, so you probably will need the internet connection only once. The libs will be uploaded and cloned back from the github repo everytime.
IDEs like eclipse have inbuilt support for maven, so you don't even have to worry about executing the mvn commands. Here's a tutorial that will get you intrigued - with the IDE that you prefer.
https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
Thanks a lot for all the replies and comments.
Technically there are two approaches to my problem. For this articular example I chose to copy the external jar files to my project.
1. Copy jar files to your project.
Go to project properties
Under Libraries folder make sure to set up a libraries folder by following the steps.
Add Library at the bottom ( you can create or import; since I already had gson in Netbeans I just imported it.)
Press ok to confirm and you are done!
2. Use Maven
Go to plugings and make sure you have all Maven plugins installed, if not do so.
Create an new project and choose maven/java application
Follow the prompts
At this point you can start coding (in my case I just imported my class files from the other project)
Right click in "Dependencies folder and then "Add Dependency"
Under query type the repository you are looking for; in my case "com.google.code.gson : gson : 2.7"
Click add and you are done!
Thanks a lot to everyone for the help :)

Edit Library in Eclipse

I am trying to enhance a library. The library is in the Referenced folder of eclipse. I presume in that folder I can't just edit the code so I guess I have to import the whole .jar file as kind of a project, but how can I do it in eclipse .....
The right way to do it is to find/download the source code for the library. The ugly way to do it is to decompile the library.
After that, edit the source code, and run against your custom version.
You probably need some sort of Java code decompiler to get the source code for that library and then make an eclipse project based on its source. It will be tedious and you will need to setup the dependencies and all that. However you might want to see if the source for that project is already somewhere on internet, eg open source libraries. One better approach could also be extending that library by means of extending classes and that.

How do I use API's in Netbeans for JAVA?

Ok so there are tonnes of API's out there. I need to use some of them like JIntellitype, iText, docx4j etc. But the problem is I do not know how to go about it in Netbeans.
I tried following the instructions in readme for all these API's but it does not work since there is something I am doing wrong. I am a newbie at JAVA and Netbeans.
Thanks!
[Update]
This is what I tried to do.
I downloaded the JIntellitype API. It contains lots of files including JAR,DLL,CPP etc. When viewed through File->Open Project from Netbeans this folder is displayed as a project.
I created a new JAVA Application project from Netbeans.
I right clicked the Project->Properties->Library and added the API folder there.
Then I tried importing one of the classes from the API called HotkeyListener as follows:
import jintellitype.HotkeyListener;
I received an error saying package does not exist.
Generally you have to add your API jar to your project. Open project properties, find where external libraries are added and add them. Once you are done you can import library classes and use them.
like AlexR said, you should add the jar file with the jintellitype.HotkeyListener in it, not just the directory. You can open jar files with winrar, winzip, 7zip etc...
Regards

Categories

Resources