I have a Mule project (created with Mule Studio, a flavor of Eclipse.) I would like to use the android.net MailTo class, which requires a few other files within the package, such as a ParseException and URI class. I could add the files into its own package in my project, however I've read I could import the package as a jar file. I can't find the jar file anywhere, and was wondering if there's a way to create a jar file out of only a portion of the package (without classes I don't need.)
Where can I find a copy of android.net as either source or JAR file? And if I get only the source, how can I compile into a JAR file?
Thanks,
Where can I find a copy of android.net as either source or JAR file?
There is no JAR file, strictly speaking, except as part of a firmware build.
The Android source code is available online, including the Java classes that are part of the android.net package.
However, getting this code to work on standard Java may be painful. I would recommend finding existing ordinary Java code.
Related
I have a question, perhaps it was already answered, but i didn't manage to find it and I appologize if the solution already exists (let me know if it is before deleting my thread).
Problem is:
I have created a program on another PC and exported it from eclipse as a .jar file. It works on my main PC when I double click on it but when I import it in Eclipse I can't find the .java file. So i can't edit it.
What I have done so far:
In eclipse I have created a new empty project
I have right clicked,import, archive file, selected the .class files that eclipse sees, but when I am in the Project Explorer in Eclipse I can't find the .java file where the main is. I mean I can click run as a program and it works, but there is no .java file, only .class files. What am I doing wrong?
That cranes.class should be cranes.java. At least on my other PC it is.
Program works fine, but I can't edit it on my main PC. What am I doing wrong?
Thanks and best regards
You need to select the Export Java source files and resources option while creating the jar file and then your Java files will be available on importing the project from the jar file.
This is similar to how you use other libraries. You depend on the Jar file which contains class bytecode (compiled) of java code. You can't edit any of such files directly in the project you are using it. Thought you can always extends functionalities in your current project using simple inheritance concepts.
If you think such functionalities are trivial you should prefer to change in the original project rebuild the jar and use the newer version of jar.
However if you feel similar things for 3rd party library you can
always make changes after taking fork from those library source
code (if open source) and build and use your own version or go
ahead and raise pull request if you are confident about your
changes.
Mostly when you build a jar file, all you have in it are .class files; these are the result of compiling .java files, and so are not editable with text editors.
You CAN create a jar file that contains .java (also known as source) files, and even a jar file that contains both .java and .class files, but if you ask eclipse to create a jar file, by default it is just going to put .class files and files from resource folders in it, not .java files.
Assuming from the question, the jar is a library created by OP, by compiling java files into class files and packing/exporting them. Although the class files can't be edited in any IDE, they can be de-compiled into Java files by using third-party applications.
I personally use IntelliJ for this de-compiling source files authored by me
Note: Although this gives OP the desired functionality, it may lead to violations if the classes are Copyrighted.
As IntelliJ states, they neither encourage nor discourage de-compiling class files and the decision is purely to the user's discretion.
EDIT: It is always recommended to use the original source files for editing. Try to host them on git so that it may be retrieved anytime required
It may be simpler to not use eclipse but jar/zip/tar your project directory on the one computer and simply extract it onto the other, then open that folder as a new project in Eclipse.
Best is the suggestion from #SanjayBharathi to use git and clone the repo on your other machine.
I have the following line of code in a .groovy file for testing:
GenerateShipConfirmsForBatch gscb = new GenerateShipConfirmsForBatch();
Ctrl-clicking on the GenerateShipConfirmsForBatch takes me to GenerateShipConfirmsForBatch.class in a .jar, and not the .java file, even though I have the class correctly imported at the top. I want it to reference the .java file so it will pick up changes I make to the .java file.
Any help would be greatly appreciated!
First guess - Wrong import
What you wrote seems to me like you have class with the same name in 2 different packages or in imported project instead of in open-able java class. When you import class be careful that you import the one you want to use.
Eg. annotation class Service is wildly used in different packages.
import org.springframework.stereotype.Service;
import com.google.web.bindery.requestfactory.shared.Service;
Just check that you are using the correct import.
Second guess - Incorrectly set modules
If you are having the multi-module application you have to set correctly the parent project to properly address this issue as well as child projects where the links should be as well.
In Maven it is done using pom.xml. It is very nicely addressed in Maven - Guide to Working with Multiple Modules.
In Gradle it is done using build.gradle. You can read more about it Gradle Multi-Module Project Setup.
Basics about classes
Local class
Idea is linking local .java files in preference instead of .class therefore if this is happening I'd recommend reinstalling Idea as I cannot find the correct approach.
Linked class (from external library)
If you have imported external library it WILL link to .class as it is decompiled from .jar file.
What you can do is either download .jar with source codes, if you are using Maven Projects click on Download Sources and/or Documentation.
Just because you have the class imported at the top does not mean that you can view the source code (e.g., .java file). If this class is coming from a dependency defined in your pom.xml or build.gradle file then you likely won't have access to view the source code. However, if this is a separate module you have at the top level of your project, then you'll be able to view the .java file. If this library is open source then I'd suggest cloning it in your project and adding it as a module. That will solve your problem.
You can install Java Decompiler IntelliJ Plugin from here: https://plugins.jetbrains.com/plugin/7100-java-decompiler-intellij-plugin
It allows you to display all the Java sources during your debugging process, even if you do not have them all
I'm learning Java from Bruce Eckel's Thinking in Java. After reading about packages early through the book, I thought I had got it, but when I decided to use the supplementary code(in the form of a single ZIP), I'm not so sure anymore.
The ZIP file contains packages in the correct hierarchy. I've an extracted copy of the ZIP too. Let's call this folder TIJ4. Both the ZIP and the folder are located on my Desktop. I'm working with an example Shapes.java which has an import statement like this:
import polymorphism.shape.*;. I imported this folder in the Project Properties>Libraries>Add external class folder. The strange thing is that Eclipse does not show an error on the import line, yet it cannot resolve names to types. I could manually create a package, then a class from within Eclipse, but isn't there an easier way to do this?
I've gooogled about this but nobody seems to have the exact problem as me. Here's what I've got so far:
1)New Java Project created. Created a class file Shapes.java in the project:
2) Project Properties>Libraries>Add External Class Folder. Selected my folder TIJ4. Notice that the error on the import is now gone. Apparently Eclipse has found the polymorphism package.
3)But I still get XXX cannot be resolved to a type errors all over the place!
what do I do? I also tried Project>Build Path>Add external archives and selected the ZIP, however, ended up in the same place.
As the Zip file contains only Java sources, you will have to compile them. Simple way, right now, is extract them into the src directory in your eclipse project. That way they will be compiled and automatically included in the classpath.
The reason for not able to resolve the classes even the import error goes away, is the zip file contains the directories that satisfy the package structure but there are no compiled classes (the .class files) are found in them.
I'm making an Android library to implement generalized OAuth Authentication(both 1.0a and 2.0). I'm using the signpost libraries for signing the Http Requests. Now when I try to export my project as a .jar file(using Eclipse, right click on Project->Export->Java->Jar file), the jar gets created successfully, but it hasn't exported the signpost libraries.
When I open the .jar file, I find that the libraries are present, but they aren't visible to the project I'm importing it in. How can I expose these libraries from the jar?
EDIT: Once I import the library into my test application and call the function, OAuthFactory#authorize() (A custom class that handles OAuth authentication), I get the following compile error: The type oauth.signpost.exception.OAuthCommunicationException cannot be resolved. It is indirectly referenced from required .class files.
this question has also been discussed here.
How to combine library with my jar?
Of course, you can extract the library-jars and add the extracted class-files into your own jar,
but you would lose the clear view to the external lib's versions this way.
The solution that works best for me is to ship your JAR-file with an additional folder that contains all external JAR-Files and then refer to them in your /META-INF/MANIFEST.MF:
Class-Path: lib/kxml2-2.3.0.jar lib/log4j-1.2.16.jar
You can leave the JAR-Files external this way and won't have to blow up your own JAR-file.
Greetings
Christopher
I get path to .jar file as user input of my java application. I need to add one class that is on my class path to that .jar file and then send the .jar file to external service (over network). The service on the other site must be able t load classes from the .jar file including the one I added in my application.
The solution should have these properties:
universal: should work for any thinkable .jar containing classes user can give me.
automatic: class addition must by done by my java application.
The class to be added to .jar file has name that does not collide with any other class in that JAR.
Since jars are regular zip files, you can use the facilities provided by java.util.zip.
To add upon what others have said, if you are needing to load the JAR on the other end, you should examine http://docs.oracle.com/javase/7/docs/api/java/net/URLClassLoader.html
I understand that you have a class on your classpath, and what you want to do is to get its bytearray representation for the purpose of injecting it into an existing JAR file.
Neat.
Hava a look at the javax.tools package, available with JDK 1.6 and up:
http://docs.oracle.com/javase/6/docs/api/javax/tools/package-summary.html
You can programmatically compile code and serialize bytecode using mechanisms available there. If not, ASM could be of help as well: http://asm.ow2.org/