I have pretty much no experience with Java so I apologies if I'm not too clear.
I'm trying to create an Android application that uses another package. I only have the source code .java files from the package, which are all part of com.X.Y
I have saved this in a folder called "Database" which I have zipped and added to the build path, so it now appears under "referenced libraries" in Eclipse. However I don't know how to include this, it's not finding import com.X.Y, and I am unsure of what to do next.
I'm a little over my depth in this project, any help would be greatly appreciated
Create a folder structure com/X/Y within your source folder and put your .java file inside of that
Step #1: Move the classes out of "Database" and into the main source tree of your project.
Step #2: There is no step #2.
I strongly recommend that you step away from Android for a while and learn Java separately. There are tons and tons of materials to help you learn Java, including lots of free stuff online. Here is a blog post where I point out a number of topics in Java that Android developers need to learn.
If you want to include those files as an external library I would look at creating a proper jar of the compiled code you want to include instead of just zipping up the source. For you the easiest way would probably be to create a second project in Eclipse, compile it and use the resulting jar.
Once you have the jar, put it in the libs subdir of your Android project. I believe that's enough to get the Android ant target to work...although for Eclipse to be happy I believe you will also need to add it to your Java Build Path.
Or if you are hell bent on just including raw source you may as well just copy/paste the entire package source into your android source directory.
Related
I'm currently trying to write my first own library. It's just for testing, I want to find out how libraries are written, compiled, distributed and used in order to prepare for some upcoming personal projects.
Yet, what really causes me to wonder, is why exactly my Javadoc isn't compiled with the Library. I know that comments and annotations are not compiled, but for example the JDK (which is basically a huge library) comes with a working doc as well.
I've tried to compile a JAR (libraries aree normally JARs, right?) from not the compile output, but the sources (so I had a JAR of .java files), but this failed to be included in IntelliJ. I could add it as an external library, but neither did it show up in my explorer, not could I import or use any of my classes.
I know there must be a mistake somewhere here, all libraries I've ver used, whether it was Java, C# or whatever else always came with a working documentation (IntelliJ shold show that on mouse hover), and I'd like to know how to correctly build a library that I can share with a team partner, so he just needs to download it, add it as a library in IntelliJ and has all the functionality, but also the documentation.
Thanks to everyone in advance!
Because it isn't needed, and would bloat the file size of the executable. If you have a library in C or C++, the documentation may be bundled in a zip file, but you won't find it in the compiled .so or .dll. One just holds the binary and resources needed for the project. The .jar is equivalent of that- it's the compiled output. Documentation is hosted/downloaded separately.
When you download the JDK, you're not just downloading a giant .jar. It includes other things, like documentation in the download.
I'd like to know how to correctly build a library that I can share with a team partner, so he just needs to download it, add it as a library in IntelliJ and has all the functionality, but also the documentation.
The short answer is that you provide your team partners with your project source code as well as the binaries. They then can configure their IDE (Intellij, NetBeans, Eclipse, whatever) with the location of the source code and the IDE will be able to extract the javadoc comments on the fly and render them as requested.
Sharing the source code also has the additional benefit that your partners can debug their (and your) code better. By themselves, javadocs are rarely sufficient for debugging complicated problems.
Alright, if everyone ever has this probelm again, here's a complete tutorial:
As #Gabe Sechan already said, the Doc is not compiled into the JAR for some valid reasons. Instead, I recommend you to add the following to your JAR:
module compilation output
content of "src" directory / alternatively: module sources
Build --> Artifacts --> All Artifacts.
Now, if you add your library JAR into a project, it will show "Classes" and "Sources" in the right tab, as IntelliJ automatically recognizes you've bundled both into the JAR.
Now, IntelliJ should show your documentation, as it lives within the source files.
If, for some reason, IntelliJ switches from its "fancy" documentation popup to unformatted plain text, proceed as follows:
Navigate to File -> Settings -> Advanced Settings, and in the 5th block, where it says "Documentation Components", just tick everything you find. That's gonna fix it.
Thanks to Gabe Sechan again, your answer helped me to understand what won't work, and finally I've found a way to make it work myself.
This is my first post on stackoverflow, so I apologize if I do anything incorrectly!
I have a project I've been working on in eclipse 4.6.2 ee neon2. In this workspace folder, I have several other folders such as one that includes my database files, and another called "lib" that includes open source libraries such as joda-time and eclipselink. I'll usually export zip files straight into this "lib" folder, and import the relevant external libraries into eclipselink from this "lib" folder. However, just tonight - I'm not sure how it happened, but eclipse generated some 500 warnings/errors on html/xml files from various open source libraries in the "lib" folder - including readme.html's and so on. I've been unable to find the reason for why they all suddenly appeared. I've tried to disable validation extensively which removes nearly all the errors but I feel that that's a patch up job.
Also note that my program seems to run completely fine, and passes all tests I've written for it. There are no new errors in the src folder, all in that one folder "lib".
My question is what I possibly could have done to make these 500+ errors appear out of thin air? Should eclipse even be generating errors on files outside of the /src folder that is contained in my project directory?
Please let me know where I'm unclear or what I can provide to help things be more clear as I've not had much traditional programming experience and can have trouble phrasing things in the correct way.
Thank you!
-As per the request here are some of the errors it's generating. Note that all the files the errors originate in have not been created by me, they're from open source packages.
If these didn't show the proper information, let me know!
Double Edit - I do realize if I remove the "lib" folder altogether, and import the external jar's, this entire problem would be resolved. However I'd like to know whether the error detection outside of /src is the intended behavior of eclipse. Thanks again!
Edit many days later - SOLUTION: I had found the solution myself, which was identical to Exclude directories & subdirectories from validation in Eclipse. I had to clean my project to get the exclude rules to apply!
When I posted this question, my solution was to recreate the project and add back all the external libraries.
I then stumbled upon this problem, months later, attempting to put my external libraries in a folder called /lib/ in the same directory as my project in eclipse. This triggered a similar flood of warnings in the screenshots in the post.
The proper solution, to avoid the errors while keeping your external libraries in the same folder, was identical to the solution I found here: Exclude directories & subdirectories from validation in Eclipse.
I had to clean my project to get the exclude rules to apply, but after that worked like a charm, and all the errors cleared up.
I want to start moving some of my projects onto github repos. I'm a little overwhelmed on how to organize the files on these repos. I want to make sure I do this right. The specific project I've been working on is a Java project I've been building in Eclipse. It is essentially an 'engine' of sorts, so the ideal outcome would be that people clone the repository and build onto it as their own project that uses the engine.
Here is my local project structure.
src
--com
----myName
------projectName
test
--com
----myName
------projectName
bin
config.properties
README.md
.gitignore
.classpath
.project
One of the first things I did was gitignore everything in the bin folder and all class files.
This doesn't really feel like the 'right' way of doing things. I'm just making guesses. Are there any standard conventions I can adhere to?
Also let me ask some specific questions
Is it okay that the java packages are creating many (seemingly redundant) subfolders?
Is it correct to ignore the bin folder? Or will that complicate the project if someone else was to clone it?
I want to say that the classpath and project folder should also be ignored, but they do reflect changes in files. Am I right in thinking that these should be commitable files?
Do I need to make any special changes in organization to reflect how this particular project is an 'engine' that I intended people to clone and use in their own projects?
I feel this is a simple concept I may be over complicating but I want to make sure this is done correctly the first time. Any resources that anyone can point me to regarding git repo organization would be appreciated!
Thanks in advance.
To what my understanding of things, you can do two things :
Share your sources as a Java Library wrapped in a jar file. You can avoid all this "how do i share" questions.
Or you can share the project in a software version tool, like GIT. Ideally you will have to provide to the clients two things : The code and a way to easily setup their environment for coding.
In your case
To share the code: The code is under your java source is under src and tests folders.
To allow other persons to setup quickly their environment for working : Let's see, you are using the build system that employs Eclipse, so you should study how to share a eclipse project from a machine from other. What i can tell you in advance is... i thing the bin folder is not necessary (2). But the .classpath and .project it is. That is necessary in order to open the project within the eclipse IDE... the problem is that your IDE perhaps has some particular library or classpath configuration that other Eclipse don't and problems may arise (3).
What i recommend is to share your project using an independent-ide builder. Like maven, for example. Yes.. you always depends on something.. is only a question of what is more easier, and mankind has prove that with things like maven it is more easy.
About question (1), is not bad as long it has sense.
and (4) I think not.
Using Android Studio, for some reason, I can no longer debug my program.
I tried a bunch of stuff and I made it worse.
To make a long story short I'd rather start from scratch and just copy the .java files and folder structure from the old project to a new project.
Is this practical?
I'm am familiar with modifying the manifest to add the various activities, which I can copy and paste from the old project.
Will this work?
I guess what I'm asking is: if I just have the .java files, what's the best way to make a project with them?
If you are using any IDE like Eclipse, just create a new java project, add the java files in the src folder. Put all the dependencies in the classpath. The project will run fine.
Simply ... Use maven. It provides you a good layout, community support, and support in a choice of IDE.
You can also use netbeans . it gives easy way to create desktop applications
I'm just starting with Android developmenent using Eclipe and have already run into some basic questions. I have some beginning books such as "busy coders guide to Android..." and "Teach Yourself Android Application Dev't in 24 Hours", however, I'm not seeing some basic things covered.
Can someone tell me how to set up a library and then use it in a project? I have some example code where they have a folder appearing in Ecliple called, "DataGatherLib" Right clicking and hitting properties reveals it is of type "Linked Folder". I suspect this is what I want. So my specific questions are:
1. How do you set up your own library project (Linked Folder if that's appropriate) in Eclipse.
How then, do you use your newly created library in a Ecliple Android Project?
More generally, can someone point me to some good beginner references (books or online tutorials) that cover this. I would think that organizing your code in libaries as opposed to one big application is fairly basic, but I can't seem to find the discussion.
Thanks,
Dave
In Eclipse right-click on your project, select "Properties", then "Android" and you see a page to add a library project.
BTW, you should do the same on the library project and mark it as a library first before you can add.
Alternatively you can drag and drop jars to your project and add them to your classpath, but in this case you can only access class files and not the resource files in the jar.