i've been searching all the web for a definitive solution for this simple problem of adding an external directory with .java files and .jar libraries to my Android Studio project.
Here's what I want to do:
Create a default project in Android Studio, and import from git the library I will work on, which is a bunch of .java files and a .jar (jsoup). These java files need this jsoup. The java files are not for Android, just simple java files.
I need it to be from github because I'm working on this lib and I need AndroidStudio to automatically update it to its newest version.
This is how I compile my project:
javac -cp ".:jsoup-1.8.3.jar" Main.java Class1.java Class2.java;
Then I run:
java -cp ".:jsoup-1.8.3.jar" Main
Well, I already loaded this library from github using Android Studio, so now I have:
Project/app/src/main/java/com.myname.myapp
Project/MyLibraryFromGithub
Of course I seen answers like this and I followed everything, but there are some problems. For example, it kept searching for a AndroidManifest.xml file which I don't know how to write because it's a simple java project, not a Android Project. Also, I think this answer is outdated, and won't work properly in AndroidStudio 2.0.
I've read some tutorials on Gradle but it won't say anything about external folders and so. Also, when I make it happen, how do I import my library? For example, in
Project/app/src/main/java/com.myname.myapp/Main.java
How do I import the library? import myLibrary? Or I just need to create new objects with the classe's names? Like Class1 myObject = new...?
This is so congusing! I whish I could compile everything by hand, Gradle is hiding too much from me and I can't find a good tutorial.
To add an external jar to your project you should do the following steps:
Select File >> New >> New Module.
Select Import JAR/AAR Package.
Give the file name in the File name text box and click on Finish.
Select File >> Project Structure.
Select app under the modules section on the left hand side.
Choose Dependencies tab at the top.
Click on the + on the right hand side.
Select Module Dependency
Select the JAR file that you have just imported.
Close both the open windows by clicking OK
Have you tried this?
Place X.jar into the libs folder
Right click on X.jar and 'Add as Library'
(In build.gradle) Place this in dependencies: compile files('libs/X.jar')
Related
I am attempting to create a JavaFX project using IntelliJ IDEA. The instructions for doing so appear here: Create a new JavaFX project. This issue is, I am encountering a popup that does not appear in the official instructions, and it is preventing me from using the library.
This is the step I am having trouble with:
However, when I select the lib folder, I see this popup before I am allowed to proceed and pick a module:
No matter which option I pick, the classes from that library are still not recognized in the program. What do I do?
Edit: The lib folder is not empty, so that can't be the cause of the issue.
When you go to the lib folder select all .jar files and src.zip file then press ok. You have to manually add all files in the lib folder.
I had a problem loading sound using the sound.processing library, so I am trying to use the ddf.minim library.
My Instructor imported the sound.processing library into processing AND Eclipse, and I don't remember how he did it. I tried going into processing and downloading minim from the sketch
When I try to import ddf.minim into my project, I get a red line under ddf. I also manually downloaded ddf.minim from github, removed the one previously installed, and I believe I had replaced it with the github files. I then went to add libraries in processing, and I still can't even import ddf.minim in Processing, let alone Eclipse!
Please help, I am just trying to get my sound to work in my Java project!
You need to add the Processing library and the Minim library to your classpath.
In Eclipse, to set your project’s classpath, right-click your project, and then click the Properties option. This brings up a dialog with all the settings you can specify for your project. Click the Java Build Path menu, and then the Libraries tab, which takes you to this screen:
This is your project’s classpath, and any library jars you want to use should be added here. Click the Add External JARs... button and select the .jar files that come with Processing. For basic sketches, I believe you only need the core.jar file.
Then for Minim, you can download the library .zip file from here. Unzip that wherever you want, and it should contain the .jar files that you need to add to your classpath.
Shameless self-promotion: here is a tutorial on using Processing as a Java library, and here is a tutorial on using Eclipse.
I'm working on an android game that requires a server. We've set up a git in which there are three folders: Client, Server and Shared:
Client contains the Android-Studio project.
Server contains an Eclipse project which is our server and database.
Shared contains java classes that I would like to use in both the Eclipse and Android-Studio project.
In Eclipse I successfully loaded the files from Shared by importing them as "file system". (It created a package and everything works great)
In Android-Studio, I can't find a solution that doesn't require me to copy-paste the classes in the project. The aim here is to have those file at only one location as they're susceptible to change but must me identical in both the projects... So those solutions don't fit my needs.
I'm looking for something like a way to link files from outside the project. (I managed to link libraries from inside the project already but not from outside)
The simple solution is to copy the desired java files into your project structure. Of course, you may have to change package names manually.
Found a solution that might not be optimal but at least in my case it solved the problem.
In Android-Studio:
Create a folder called something like "CommonEclipseAndroid" following a path similar to this one: project/Android/app/src/main/java/com/example/myapplication/CommonEclipseAndroid
Paste the code you need to use in both project inside this folder.
In Eclipse:
Right click on your project: Properties > Java Build Path > Source > Link Source and choose the folder we've just created.
Now your projects use the same code. You only need to modify it once for both projects and there's no risk of error.
Hope I helped :).
You can import the shared folder as a module .
go to file> new> import module
Now use the same imported folder in eclipse as well.
I want to use methods in Java Mail API, so I am trying to import its jar into my project on IntelliJ IDEA. How do I import or download this new jar? I am not new to IntelliJ IDEA, but haven't imported new jar in two months now.
Also, do I need other setup in order to use Java Mail API?
1) You need to create a Project in IntelliJ IDEA.
Now you have two options.
2.1.) Open the Project view in the IDE. Then right
click on your Project and do Open Module Settings (or press F4).
2.2.) From the File menu just choose Project structure.
3) Then go to Libraries on the left side. Then click the + sign (add new library).
Then locate your JAR and select it, this will import it as a library.
Note: The JAR you need to have downloaded first on your local machine.
Here is a screenshot, with added one JAR to a project I just created.
To make an example that works you'll need some mail servers.
See for example here.
http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/
You can go to 'Project structure' with this short key 'Ctrl+Alt+Shift+s'
and in Library you can add your jar files
I have a program I am making for a friend. It contains one class, references two libraries (sqlite4java and poi by Apache), and sqlite4java contains many native libraries (.so, .dll, .jnilib) that are within my lib folder. The program also reads and writes from a swimTeam.db file.
My question is how do I package this all into one program that can be run cross-platform? I have tried exporting the project as a runnable jar, but when I ran it it couldn't access the native libraries because they weren't exported. Any idea how to do this?
First thing is create a java project remove all the java files and copy all the Jar file you need to import into that project.
now add the the created project to your working project as "project references" (right click on the project and click on properties)
now add all the Jars in the Java buildpath->libraries
now export your project as JAR. open it and make sure that all the JARs u need are in it.