Downloaded a Java library off GitHub, do I compile it now? - java

I am trying to do this simple tutorial using the JARVIS Java Speech API:
https://github.com/The-Shadow/java-speech-api/wiki/Hello-World
These import lines lead me to think that I need to link to a .jar library.
import com.darkprograms.speech.microphone.Microphone;
import com.darkprograms.speech.recognizer.Recognizer;
import com.darkprograms.speech.recognizer.GoogleResponse;
But when I go to the gitHub site, the only option is to download the .java source files. How should I go about converting them into a .jar? Is that what I am supposed to do?

On that same GitHub page, you can download the jar :
https://github.com/The-Shadow/java-speech-api/releases
You should also acquire any additional jar required by Jarvis (it doesn't seem there are any from a quick look).
That said, if you want the very last version of that library (and the associated bug/problems if any), then you will need to compile it from source, ie, something like :
clone the git repositery
compile the java sources
create the jar

Related

Import processing.video.* on Intellij

I am trying to run a mp4 video in Java using Processing.
I'm trying to use Intellij IDEA, but when I try to import processing.video.* it doesn't find the video library.
Where can I find and how can I import this library?
You need to do two things:
Find the .jar files (and any other files) required by the library.
Add those files to your classpath.
You can find the library files in your Processing directory. For me mine are in C:\Users\kevin\Documents\Processing\libraries\video\library, but it's going to depend on your OS and where you installed Processing.
You can also build the library yourself from this GitHub repo.
Now that you have those files, you can add them to your classpath. Since you're using Intellij, the links in Slaw's comment should get you pretty far:
Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
Working with libraries - Intellij

How to import source from GitHub into an Eclipse project

I am trying to use this tool from Google: https://github.com/pcj/google-options
In the example given by Google, they use:
import com.google.devtools.common.options.OptionsParser;
to allow their example code to use the command line parser.
When I do this, Eclipse says the referenced files don't exist.
I have tried putting the source file from google-options in a package in my project; no luck. I tried running Google's example, and it won't even compile. It can't find all of the classes in its own src folder.
Based on my research, I think there's either an issue with a .jar file needing to be in the build path, something to do with Apache Ant, or an issue with GitHub I don't understand.
I'm very new to GitHub; this is the first time I've tried to do anything like this.
You should first import this project from GitHub to your local machine. import statement in your class means that classes from other packages should be imported to this class you're working on. Import not from the remote source, but from local.
I figured it out. It needs the guava.jar file found here added to the buildpath. After that, it has a couple weird dependency issues with javax, but I just removed those (it was Nullable and Immutable, if anyone's interested).
First you must clone the project and compile it, to do that put the following commands:
Open your terminal and go to the workspace folder:cd {workspace}
Clone the project: git clone https://github.com/pcj/google-options.git
Compile the project: mvn clean install
Check the result, this should print: BUILD SUCCESS
In that step, maven will download all dependencies that the project needs.
To import the project: Launch eclipse, click on File /Import... choose Existing Maven project, browse your workspace where the projetc was cloned.
Create a class that extends OptionsBase and defines your #Option(s). For more information about how to use, see https://github.com/pcj/google-options#usage

How to convert library (uneditable .java/.class files) into editable .java files (standard classes in project)?

I am working with Paho project for Android. According to the instructions, while testing Android sample app, it is required to have both AndroidService.jar and JavaClient.jar included in the project. I import them in Android Studio and the app is working perfectly.
However, and that is my problem, I want to edit these precompiled java classes. But the problem is that, since they are imported as .jar files and that they are already compiled, they are uneditable in Android Studio.
I have the source code of the libraries I want to include into the project. Unfortunately, when I import them in the Android Studio, I get bunch of errors (which I do not usually get when I import .jar files).
The methods I tried up until now are to copy the source java classes into the project by creating new classes with same names and content. I also tried to import the whole source project as the module to my project. I get same errors. I also know about this great fork of the Paho project which lets you just to import whole project in Android Studio and it simply works. However, the AndroidService classes are still uneditable.
As I said, I have the needed source code. I can generate these .jar files without any problem from the source and then import them in the project. That method works. But to edit the java classes, then to compile them, then to import them in the Android Studio to test everything, and to do it every time when I change something, is a bit tiring. That is why I am asking for help.
Please, let me know if you know some approach which will let me to edit these two "libraries" while I am still in Android Studio, so I can test changes I make immediately.
P.S. I have been Googling this so much and I believe that there is no ready solution for these online. However, If you find one, I will be really happy if you point to it.
Fist of all I have no idea why you want to edit the Paho Android Service because it doesn't make to much sense. You are able to overwrite every class if necessary. Any way you would need to change the Android Service build from Maven to Gradle to include the source into you project.
To help you out I have just done that and pushed to the "withSouce" branch of my repository. https://github.com/sandro-k/org.eclipse.paho.android.service.sample/tree/withSource
If you now want to replace the compile org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 with your sources as well you have to replace that with a local dependency as well.
Jar files are really just compressed (zipped) versions of .class files (and a few other essential documents). Class files are compiled .java files. The only way to edit these jar files would be to unzip the jar with a program such as 7zip or WinRAR, then decompile the class to get the source code, edit it, and recompile. Decompiling is a very difficult, time consuming process, and would require external software. Your best bet would be to continue the process you've been using.
Note: If you still wish to decompile, you might want to check out Cavaj, a free java decompiler. But beware, it may not return the exact source code used in the jar.
Sources: Experience

implementing the NWalign.java alignment script for needleman wunsch algorithm

I'm trying to run the NWaling.java file found here. the code present at the link that I mentioned makes use of the jaligner library. I have downloaded this Java package from here. inside the zip folder there is a JAR file. I'm developing the code using eclipse. whenever I add this JAR file to the code there are some classes missing for example:
import jaligner.NeedlemanWunschGotoh;
&
import jaligner.matrix.MatrixGenerator;
also in the entire zipped folder there isn't any pom.xml file to allow me to import the entire folder as a maven project to eclipse. can somenone suggest me how to import this jaligner library and use it in eclipse? thanks.
You can download a community implementation of the jaligner algorithm from here.
Take a look at this project sources where you may perhaps find all the searched artifacts.
The full Eclipse project with the NWalign.java can be found here including .classpath file with all dependencies listed there.

BaseX Access from JAVA

This is a very basic question, but I can't seem to find an answer. I've just installed BaseX (V.7.8.1 on Win7 PRO/64- bit) and have it running successfully through their GUI. I am now trying to run queries locally via their JAVA examples (from GitHub - specifically their RunQueries.java example). I've created a test project in Eclipse and placed the RunQueries.java code there to try to run it. But, the BaseX imports are not being resolved :
import org.basex.core.*;
import org.basex.core.cmd.*;
import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.iter.*;
import org.basex.query.value.item.*;
Should the general install of BaseX put these packages in the correct place? If not, what do I need to do to find & get these package components properly into my directory structure? Appreciate any help.
You need to add the BaseX.jar file as an external JAR to your Eclipse project. You can do this by right-clicking on your project in Package Explorer, then Build Path > Add External Archives. I am assuming you also run their GUI from this JAR file, so you should have it. If not, you can download it here.
If you are also interested in the internal workings of BaseX; you can actually download their source from GitHub.

Categories

Resources