How to import git java project to Eclipse - java

I've tried every option explained step by step here and here: and here
And I can't get it to work.
What I want to do is pick this project: , however it may be done (I've tried both through maven and git), and use its code in eclipse. And what I mean by that, is that I get to the point of seeing the folders in eclipse, but I can't create packages since it's not a java project, and if I mess up the code on the files that appear, it doesn't give me a warning nor in general interacts with said code.
So I guess I'm missing some piece of knowledge and I don't know where else to look for it. What should I do to use that project in my eclipse, and create my own code that calls and uses the classes and methods from said project?
Thank you in advance.

Just download it with git, then import it as a maven project. If this fails, create new "java project from existing sources", pointing as a source the simmetrics-core/src and simmetrics-example/src directories. If it fails, point separately simmetrics-core/src/main, simmetrics-core/src/test etc.

Since this artifact is present in the maven repository (https://mvnrepository.com/artifact/com.github.mpkorstanje/simmetrics/4.1.1), you can create your own new maven project in Eclipse and add simmetrics as a dependency to it in its pom.xml file
<dependency>
<groupId>com.github.mpkorstanje</groupId>
<artifactId>simmetrics</artifactId>
<version>4.1.1</version>
</dependency>
This will put simmetrics to the classpath of your own project and you should be able use its API

Related

How do I add dependencies/3rd party java libraries into Maven for Intellij and/or VS Code?

I am trying to make a JSON parser for a project using GSON in java with Maven in Intellij or VS Code. Whenever I try to compile/run the debugger on the file (ex: javac jsonParser.java) it always says the "com.google.gson" and related objects such as "GSON gson = new Gson();" does not exist.
Things I have tried:
Watching many tutorials/read many walkthroughs on how to add a dependency/3rd party JAR, however, the best I was able to do was make the App.java file in a default Maven project template be able to use the GSON library, but any additional java files in the folder would still get the above compilation error.
Manually add the dependency information in the pom.xml file
Use the built in "add dependency" features in both Intellij and VS Code
I have tried on both Ubuntu and Windows 10 (including adding things to the environment variables)... Often times, I am able to see the dependency automatically added to the pom.xml file, as well as see the JAR file in my project folder
Running sets of Maven commands in VS Code ---> "mvn install" "mvn package" "mvn dependency:resolve" which run fine with no errors
TLDR:
Would someone be able to walk me through adding a 3rd party library in Maven/Gradle and/or Intellij/VS Code? If it helps, I am willing to use Gradle or some other (freely available) software if that is easier/preferred? I am new to any sort of software development (first year CS student) so I have no experience in terms of making a completed project.
You look up the GSON coordinates (groupId, artifactId, version) in MavenCentral(http://search.maven.org)
You take the XML from MavenCentral and copy it to the <dependencies> section of your pom.xml
You use GSON in your Java code
You build your project with mvn clean verify

Maven: including utils in Java project

The case is quite simple, but I still can't solve it:
INFO: All 'projects' I am talking about are Maven projects.
I have certain Java project that I am working on right now. Recently, I have written a lot of general-purpose code in this project. I also have an 'utils' project with some Java utils in it, so I decided to move the general-purpose code from my main project (let's call it 'A') to the utils project. This would be practical because:
I have less clutter in A
I can reuse the code in other projects without bringing the unrelated content of 'A' in scope.
The problem is that utils is, of course, an utility project, a library if you want. And it does not have a main class. When I try to install (mvn install) it, no sources are included because there is no proper entry point.
So, after trying a lot of things, I have the concern that I am approaching this problem completely wrong and that's why I came here. I do not have any experience with Maven except the simple use case (e.g. including external libraries from Maven Central). Therefore my question is:
Which steps are required to make my utils library available in project 'A'?
I am not aiming to install my project on Maven Central or any other remote repository. I just want it available in my local mvnrepo. I am aware that this means that I'll have to clone my utils project and install it everywhere where I try to use project 'A'.
EDIT 1: I am using Java 11 (openjdk11), Maven 3.6.0, IntelliJ IDEA Ultimate with Maven Helper plugin and also GitHub in order to make my projects available anywhere.
Also, I have just checked that project 'A' correctly includes the jar from the utils project and actually adds it to the classpath (but the jar is empty). So, the problem really seems to be in the utils project.
A maven install would place your compiled code in the local maven repository (.m2/repository).
Sources are packaged by the source plugin.
mvn source:jar

How to add a dependency to module path?

I am very new to programming, and while working on my first software development project I came across the error: "package javax.activation is not visible." I have read other posts that have said that in order to fix the error, one must add a dependency to the module path?
Because I'm just starting out, I really don't know what this means and how to go about that, and was wondering if someone could point me in the right direction? Thanks in advance. (I'm also using JGrasp if that matters)
Broadly speaking, a dependency is code (often written by someone else) which your application needs to compile.
A dependency in your case, is a java library which has classes that need to be on your class path. You can find more about class paths here: https://docs.oracle.com/javase/tutorial/essential/environment/paths.html. In order to overcome error mentioned in a question, you need to have javax.activation module dependency on your class path.
You could do it in few ways. In the majority of IDEs (in your case we are talking about JGrasp) there is a way to add a dependency to the project directly. Then, your IDE would compile the code with given dependency on a class path and problem would be solved. And that would be the first and most beginner-friendly way, unfortunately I haven't a faintest idea about JGrasp so I'm going to focus on other solutions.
The second way you could do this is to build your program with build automation tool, such as Apache Maven or Gradle. You should definitely check those guys out, as they are insanely useful when it comes to building Java code and, sooner or later, you will probably start using them anyway. Let's say you have chosen Apache Maven. In your project you would then have a pom.xml file and you would simply look-up the needed dependency in Maven Central repository, add it to your dependencies section in pom.xml file and build the application. Your pom would look something like this:
<project>
...
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
...
</project>
Of course Apache Maven is not a lightweight tool so you would have to take some time to learn how to build code with it. I recommend starting with this tutorial:
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
I also encourage you to get your hands on Apache Maven docs, as it is quite readable and transparent.
And the last way I can think of is to manually compile your application and include the required dependency during the compilation process. There are plenty of tutorials on SO that tell you how to do this, so I'll simply summarize and indicate the resources. What you need to do is to find the required dependency jar package. You will want to search the maven central repository (see: https://mvnrepository.com/) and from there download your .jar file. The next thing you need to do is to learn how to compile your Java code to .class files including the downloaded jar. To acquire such a wonderful skill, please see this one: How to include jar files with java file and compile in command prompt
Amongst those three ways, the recommended one is to get to know with build tools such as Apache Maven or Gradle. Hope I helped you! Good luck

Importing a GitHub library into java eclipse

I have researched the internet extensively but still cannot figure out how to properly import a GitHub source code library into my java project in eclipse and use it successfully. I can do this perfectly if the library is in a jar format, but I don't know how to do it with source code provided in GitHub. I have tried everything from maven to downloading a zip file with the source code and manually putting it in my code (I know this is terrible practice). It seems like the library I am downloading references other libraries and this chain seems to go on for a long time.
I have had trouble with all libraries but this one is an example: https://github.com/thiagolocatelli/parse4j
I am relatively new to this kind of stuff, so can someone provide a detail step by step guide on how to do this?
Thank you so much!
Akarsh.
Download the parse4j github project into same directory as your project. Refer below screenshot
add <dependencies></dependencies> section of the pom.xml of your project, in the above image, it's jparse.
<dependency>
<groupId>com.github.thiagolocatelli</groupId>
<artifactId>parse4j</artifactId>
<version>1.4</version>
</dependency>
Now you will be able to use parse4j classes in your project.

figure out how I got a Java package

I am very new to Java. I am running somebody else's program on my computer, and they have imports like:
import weka.classifiers.CostMatrix;
import weka.classifiers.Evaluation;
import weka.classifiers.meta.CostSensitiveClassifier;
import weka.core.*;
The program actually works for me, but I am surprised because weka is a pretty specialized program, so I doubt it is distributed with Java. I never installed weka using any package manager, and I have searched the program code and it doesn't contain any weka packages explicitly.
Do you have any tips for figuring out 1) where these packages are installed, and 2) how I "got" these packages on my local computer? I have read that Java doesn't have a centralized package manager like Python or Perl do, so that might make it harder. I am super new to Java so any basic tips about package management would also be appreciated.
These packages are dependencies of your project, so they have probably been downloaded automatically by a tool that manages dependencies.
There are several possible build tools that can do that. Since you are working with Java/JVM, the usual suspects are Maven and Ant or maybe (less likely) Gradle or SBT.
In your case, the most probable scenario is:
A Maven plugin somewhere in your IDE manages the dependencies and downloads the jars (mvn in console less likely: you would have noticed if you used it)
A pom.xml build definition file lists all the dependencies
A weka dependency is probably declared somewhere in the pom, it should look roughly like this:
-
<dependency>
<groupId>nz.ac.waikato.cms.weka</groupId>
<artifactId>weka-stable</artifactId>
<version>3.8.0</version>
</dependency>
The JARs are stored in a hidden directory .m2 (or maybe .ivy) in your home directory.
The idea is that you can simply get the source code files and the pom.xml, and let Maven (or a similar build tool) download all dependencies, get all the required compiler plugins (or test-coverage tools, or whatever), and build your project. If you tried to do without a build tool, you would have to pass around eternally long lists of dependencies with version numbers that have to be obtained somehow before your program can be compiled, and this would be just a huge mess.
Edit: It is probably downloaded from here: Maven Central: weka-stable
It wouldn't run unless those packages are on the classpath and passed at runtime via
java -classpath
Or you're running an uber JAR file that does contain the libraries.
Common solutions for dependency management include a pom.xml (Maven), build.gradle (Gradle), or build.sbt (SBT).
While those aren't the only options, another solution would be those JAR libraries have been copied into your Java installation somehow

Categories