jar to eclipse project - eclipse

I got a .jar file which I need to import into Eclipse. However, I don't want to have the jar as a referenced library. I need the .jar to be included like a "normal" project, with packages(!) and .java files.
I tried to do the following: New Java project -> Import -> General -> Archive File. In this case, when I place this jar also as a referenced library, it is imported but with .class files.
New Java Project -> Import -> General -> File System. Imports the .java files, but the packages are lost and are normal folders. Also, the files are somehow strange, because the "j" in the icon looks differently, and errors are not noticed (no underlining)
Importing "Existing Projects into Workspace" doesn't work at all, it says that there is no project. I also tried to import the jar as a zip after extracting it, this gives me the -java files, but it destroys the packages.
Does anyone know how to import this correctly?

What are you trying to do here ? .jar files would contain .class files not .java files. Either you need to have the corresponding source in the jar or you gotta get a decompiler associated with Eclipse.

Related

Import a war in IntelliJ

I have worked on eclipse before and new to IntelliJ.
I have a war with me(its an example from apache). I want to import it to intellij. but it seems that IDEA does not support importing. I also have unpackaged version of the war file.
How can I import or do equivalent in Intellij and get all the contents?
If you mean that war also contain the source java Code, "myclass.java" here is the answer :
There isn't a direct way I know about :
first open WinRAR
drag the war file into WinRAR
extract content
copy the HTML, JSP, etc. files and css, javaScript folder to the "web folder in your project" (you should create new one before starting).
navigate to class folder deleted all .class file keep only .java files
take all folder copy to " src folder in your project "
the import thing don't forget to copy the deployment descriptor "web.xml"
finally rebuild the project

Getting imported files from sample java program to new program

I'm trying to make a small java program revolving around Google Calendars. I've never worked with java before but I was able to get Google's sample code working. In Eclipse, I simply used Import -> Maven, and then made some small changes to the code so that it worked on my Calendar.
Ok, great, now I want to write my own code. I started a new project and imported the Google Calendar API. At the very beginning, there are several import actions:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
.
.
.
It turns out that I'm missing the second and third files. How do I find these files and how to do import them to the new project?
Please note: I ultimately don't want to rely on importing the Google Calendar API or anything similar, as I will be using another non-java program to run and control this one.
Here's what I tried:
I go back to the sample code, expand Maven Dependencies and find:
google-oauth-client-jetty-1.19.0.jar
google-oauth-client-java6-1.19.0.jar
I see that these files are in:
C:\******\.m2\repository\com\google\oauth-client\google-oauth-client-jetty\1.19.0
C:\******\.m2\repository\com\google\oauth-client\google-oauth-client-java6\1.19.0
I tried to add these with Import -> Java EE -> App Client JAR file
Didn't work, do I need to change the file name or import name? Maybe these aren't the correct files anyway.
I also tried to add these by creating a lib folder in my project folder and add the JAR files directly there.
I guess from your question your project is just an Eclipse project rather than a Maven project. Obviously Maven automatically add the required jars of the dependencies stated in pom.xml for example google-oauth-client-java6-1.19.0.jar is a dependency of google-oauth-client-jetty-1.19.0.jar.
To add external jar to your project in Eclipse you need to select the project then from the Project menu select Properties. On the properties popup click on the Java Build Path, you have two options depending where the jars are stored, if you are referring to the maven .m2 directory then choose 'Add External Jars' otherwise if you added them to a lib folder in the project choose Add Jars

Eclipse cannot find twitter class

I downloaded twitter4j-core-3.0.3-sources.jar and put under my project's lib folder.I did this step : project->Build Path-> ConfigureBuildPath->Add jar ... But now my project cannot find twitter class, I cannot import twitter.Status . I can import twitter.*;
You downloaded the sources file, which is full of .java files that Eclipse will use when you want to see the library's classes' source code.
In order for Eclipse to use the classes, you'll have to add the binary .jar to your build path (and remove the *-source.jar one). You can then link the binary .jar to the -source.jar to be able to navigate to the library classes' definitions.

Missing files while Exporting and importing a Maven project in Eclipse

I have created a Maven (normal) project in Eclipse. Now I want to export it. I exported it to .jar archive. But just for testing, if I am importing the same back to Eclipse, then the actual source files are missing. :-) What is the actual process to export Maven project to a .jar archive with the original source files so that I can import it back somewhere else (e.g., Eclipse) and have access to the source files?
Thanks.
To Export project you should use Export.. / General / Archive File wizard.
Then you could use Import... / General / Archive File wizard to import it back.
If you need a jar, you should use Maven launch configuration, with goals like package and source:jar (to generate Maven source archive).
While exporting as a .jar, select the checkbox Export Java source files and resources.

How to export GWT project classes into JAR file

I find it difficult to export classes from one project into JAR file, so that I could import it in another project.
How do I try?
I right-click on project in Package Explorer -> Export -> Java -> JAR file -> select all the packages I need. 'Export generated class files and resources' option is checked, other options are left unchecked. Then I click Finish.
When I import such generated .jar file into the dependent I encounter a list of errors:
The import pl.abc.xyz cannot be resolved
Xyz cannot be resolved to a type
It seems like the classes from the JAR file were not found by the compiler.
Please correct me, if I do it in a wrong way. Thanks.
It seems that you need to include in jar also java source files from the client package (sometimes also shared package depending on your GWT module structure as defined in *.gwt.xml file).
The GWT compiler requires java source for the part which has to be compiled into Java Script, to be availabe as classpath resources along with compiled classes. It is simple to achieve with ant or maven build.
You can also check Export Java source files and resources when exporting, but it will add all the source code, not only the client part.
Make sure you inherit the module in your .gwt.xml file. You want to inherit the .gwt.xml file from the GWT jar you are importing, for example:
<inherits name="com.example.youmodule.Name" />