I have seen similar questions on SO and I'm just not getting it. I have a bunch of Java classes I need to import as a library. How do I make the jar file, save it in the right place, then tell Eclipse to import the jar file?
The classes I want in my library are here: StdIn library code
and this is the java code I want to import the library into:
Sattolo algorithm code
There is a further library I would need to import to make the Sattolo algorithm run, but once I get the general idea...
I am a very, very new Java coder, so please be patient with me not understanding what must seem very basic.
Step 1: create a jar from you classes, if your using eclipse then simply
https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm
Step 2: add the jar dependency to your eclipse project
How to import a jar in Eclipse
Related
I want to model and simulate the electricity grid, however, there is not any Anylogic library that help me with this purpose and the powerflow calculations. I have searched for java packages that may help, and I could find PowSyBl at:
"https://www.powsybl.org/index.html".
However, I have no clue how to import and use this package:
https://www.powsybl.org/pages/download/
or any of its Java libraries:
https://www.powsybl.org/pages/documentation/developer/repositories/
to Anylogic after downloading from GitHub. There is no "Jar" file there, and there is no Java classes inside the zip file to call within Anylogic. There is a tutorial page that guide how to write Java code to do powerflow calculations, but I cannot run or configure the package to be able to follow its instructions:
https://www.powsybl.org/pages/documentation/developer/tutorials/loadflow.html
Can you guide me how to use this Java package with Anylogic? Is there anyway to do that at all?
I have imported the PowSyBl distribution zip file into Anylogic, but it is not functional and I cannot understand how to call its classes and make use of them.
I want to create one external jar for Logging Purposes,so that i can import this jar in any java project.But i would like to use the classes and methods of java project in external jar.
Is it possible ?If yes,please help.
I think it's possible from Reverse Engineering,but not able to figure out how to use class and specially methods in external jar.
It is possible, but very bad practice.
You need to import each project into eachother.
Project A imports Project B
and
Project B imports Project A.
I would recommend you to use eclipse and add the projects as source. You can read how to do that here:
Creating a java library with Eclipse
You can read about the bad practice of what you ara about to do here:
Two java libraries importing each other?
I'm working with a code snippet that came with a bunch of import statements, which I copied as well. The problem is that the libraries apparently aren't packaged along with Intellij, so the usual Alt+Enter doesn't help. The IDE shows a "cannot resolve symbol" at almost all of the libraries. Now, I solved one of them by grabbing the correct .jar on the internet somewhere and adding it to the project structure, but I'm having a much harder time locating another one, plus this seems to me like an awfully inefficient way to work.
How do I locate, download, and add the required classes/libraries to the project in an efficient, clean way, based on import statements only?
Imports just for reference:
import org.apache.log4j.Logger;
import org.junit.Test;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
You need to find out in which jar your class is included. I often use http://www.findjar.com/index.x to help finding it.
Then, you will find the download site for this jar. eg. http://www.java2s.com/Code/Jar/g/Downloadgson222jar.htm
Then you download it and you include the jar in the classpath of your project. Or you can include the folder where all your jars are in the classpath.
If you find this all too complicated, you can also try to migrate your project to Maven which you will tell the name of the requiered dependencies (easily found online) and it will take care of downloading the jar and include it in your classpath.
I think there is no particular way to do it. If you grabbed the source code from an entire project, I would suggest you to look at the build script. The dependencies would be listed down there.
Else please search for with the FQCN on search engine.
For your imports, I did it for you and found out the source.
Apache Log4j 1.2.17
google-collections
Gson
JUnit
Hope this helps!
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
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.