Eclipse Gradle Wizard creates project with SubFolder -lib - java

When I create a Gradle project in Eclipse the result is a nested project with a -lib folder created automatically. Any ideas on why this is being created?

I tested this on Eclipse 2021-03 using the latest gradle version 7.0-rc-1 and reproduced your issue where a nested project with a lib subproject was created. I then made a new Eclipse project specifying Gradle version 6.6 to be used and the resulting project was not nested. I suggest trying Gradle 6.6 and seeing if you get the same behavior I got. This might fix your project.
Also try running the gradle init command from the command line and see what project structure you get there. I tested this on my PC where I have gradle 5.6 as the default version and got a non nested structure. You can of course always manually modify your gradle project in a few minutes to not be nested.

Related

Android Studio can't find java compiler

I downloaded a Android project and wanted to try it. So I imported it to Android Studio (2.2) and when running the project i get the error:
Error:Execution failed for task ':app:compileDebugJava'.
Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
Before the runnning of every project worked and i'm searching for days but still found no working solution.
EDIT: Here is my project structure:
project structure
Maybe someone of you has the solution.
This kind of problem arises when you compile old project in your new updated Android Studio IDE Version.
Technically speaking : gradle build version is old. Just update with new
This can be achieve editing inside build.gradle(Project: App name)
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
//update latese gradle build version.
}
This might do the trick.
I think, you didn't setup JDK for current project. You've just loaded the code. Do it in project structure.
You can do it here: File > Project Structure > [Platform Settings] > SDKs.
I had the same issue. It turned out to be old versions of the buildscript dependencies classpath, and the buildToolsversion, that were included in the project config files. This was not related to the JDK path, changing the JDK path didn't help.
I followed this answer, with these additions:
In step 1, the gradle-wrapper.properties file is inside the gradle/wrapper folder in my main project folder. The lowest gradle version that Android Studio accepted here was gradle-3.3-all.zip
In step 4, for the classpath gradle version I used 2.3.2, this is the latest non-alpha version that I found, that works here. (not sure why these versions are different. but it works)
I also had to change the buildToolsVersion to '25.0.0' from the old '20.0.0', inside the file build.gradle in my module sub-folder.
Now I can compile the project in Android Studio successfully.
(The file gradlew in the project main folder is generated once at the project creation, and can be regenerated. It can be used to run gradle commands manually, such as debugging this issue. But it was not needed for this solution.)
editing inside build.gradle(Project: App name)
dependencies {
implementation 'com.android.tools.build:gradle:3.6.2'
//update latese gradle build version.
}
then sync it.

I just started learning Maven. How does Eclipse build without it?

I've been coding Java in Eclipse for awhile without needing to specify dependencies. Now that I learned how Maven does it, I'm wondering: how did Eclipse build projects on its own? How did Eclipse figure out which versions of imports, and which dependencies of dependencies, are needed to make everything work?
Finally, what are the advantages and disadvantages of building a project in Eclipse by starting with New->Other->Maven Project instead of New->Java Project?
To the first question: Eclipse doesn't add any dependency in a standard Java project. You have to manually add to the Build Path all needed JARs, otherwise you'll have compilation errors.
To the second question: if you create a standard Java project Maven is not used, even if you create a pom.xml file in the root of the project. You can always convert a standard Java project in a Maven project (see Convert Existing Eclipse Project to Maven Project).
Your dependencies has always to be in the classpath
When you start a project with Maven, Eclipse will automatically add the Maven repository to the classpath.
When you start a Java project you have to link your library manually in Eclipse and the version of the library is the one you've downloaded.
You can see the difference in your project's Properties > Java Build Path > Libraries

Scala eclipse-plugin Project unmanaged dependencies of referenced projects not on classpath after upgrade from 2.9 to 2.10

I recently tried to upgrade from Scala 2.9 to 2.10 and ran into the following difficulties:
I have two scala eclipse-plugin projects. The first one has some unmanaged libraries on it's build path. This project compiles and runs fine.
The second project depends upon the first project and some Java project configured via eclipse-plugin dependencies.
Here I get four not very helpful compile errors. Three times the following
SBT builder crashed while compiling. The error message is 'bad symbolic reference. A signature in XSBInterRunner.class refers to term interprolog in value com.declarativa which is not available. It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling XSBInterRunner.class.'. Check Error Log for details. de.wwu.sdpn.wala Unknown Scala Problem
Plus another dumping the class path which actually does not contain the corresponding library.
If I manually add the missing libraries to the second project the first project isn't found anymore. Even though it was on the dumped class path previously.
When compiling the projects from the command line via SBT using a more or less equivalent setup everything works fine.
I've also tried to reconfigure the dependencies not to use the eclipse-plugin mechanism for dependency management but directly added the other project to the build path but this also didn't help. Reimporting the projects to a clean workspace also didn't help.
The problem exists both with the 3.0.1 and the nightly version of the scala-ide plugin on Eclipse 4.2 and 4.3.
Any idea how to resolve this issue? Is there any way to find out why the libraries are missing from the class path?
From the description, it looks like the unmanaged library is not exported from the first project. Verify that in project properties > Java Build Path > Order and Export, the checkbox next to the library is selected. It is needed to make jars visible to other projects.

NoClassDefFoundError on external library project for Android

I use eclipse for Google Android development.
I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.
the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.
Edit: The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)
Is there a clean way to get this working?
It has been clearly stated in offcial API here:
A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file
The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.
Update from SDK r17:
This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
For those who followed the steps(even check the projects in "Order and Export") and still have the java.lang.ClassNotFoundException in the API 17, the final step is to check that your compiler does not run with Java 1.7. If is 1.7 then you should change it to 1.6 for all your projects. After that it will ask to rebuild all the projects and successfully ran on my phone :)
To change the java compile version in eclipse, this is located in: Project properties > Java Compiler > Compiler Compliance level: 1.6
Go to project properties -> build path-> libraies
If you see your jar files like this
snmp4j.jar - e:\software\jars
Its may your problem
Add libs folder in your project and copy jar file in that folder. Right click jar file and go build path -> add to build path. Then you can see your jar as
snmp4j.jar - project_name/libs
Its worked for me.
I had two projects using the same library: one working, the other one crashing with java.lang.NoClassDefFoundError.
After nothing else helped me, I looked into the file project.properties in the root directory of my project.
The working project had the android.library.reference line (the last line below), the crashing one did not:
# Project target.
target=android-17
android.library.reference.1=../my-library-project
I manually added the line and it started working!
(Yes, I did try both (project) properties -- java build path -- projects and (project) properties -- java build path -- order and exports -- nothing helped.)
PS By the way, "project properties" has also the "project references" tab. No idea if it would work.
I had a minor issue when I upgraded to ADT17 where my libs weren't being imported properly. Turns out this is because my librarys were being linked as dependancies from my lib folder not libs!
Seems librarys have to be in the libs folder from now
I had a similar problem and non of the solutions out here fixed it.
Short version: the JAR was compiled in Java 1.7 and could not be found by Dalvik.
We build an internal JAR that we share across backend and mobile clients with Maven. The problem ended up being that the JAR was compiled with Java 1.7. Androids dalvik only supports Java 1.5 and 1.6. This is why everything works fine in Eclipse as it's not compiled to dalvik at this point.
We even specified the target and source version in the Maven compiler plugin to compile with Java 1.6. This did not work because only JDK 1.7 was installed on the build machine. A small note at the bottom of the Maven page gave us the hint: Note: Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version.
To see if you have this problem as well, rename your *.jar file to *.zip unpack it, and look in the MANIFEST.MF file for the Build-Jdk: parameter to see what Java version actually compiled your JAR.
Another thing to pay attention to is library package names.
If you are using ADT21 and you happen to have libraries that have the same package name, there will be error during compile but it will still compile and run in Eclipse, giving you an APK that is missing some of the resource classes. Hence the crash when you run the app.
If you compile it with ANT then you can see the compile error that says two or more libraries use the same package name.
To fix this, rename your library project by using Android Tools -> Rename Application Package. Then everything will go back to normal.
It took me almost entire day to figure this out...

Eclipse IDE behaves weirdly

I am getting a class not found exception for my Login Controller when I try to login to my application(It is a spring MVC Application). Before running the maven clean command the Application was running perfectly, I used maven clean and then again done a build using maven package command, suddenly it stopped working. I tried restarting the TomCat, re-deployed the application on TomCat, restarted the Eclipse IDE but nothing has worked so far.
Why this happens and what is the possible solution to this ??
Are you trying to run your project under Eclipse?
And does it generate source files?
If these are both true, you probably need to update the project config (select project or pom, right-click, Maven..Update..Project Configuration and Maven..Update..Project Dependencies).
The problem is that when Maven does a clean, it gets rid of the generated directories, which Eclipse observes and removes from your Build Path. But then when Maven rebuilds the directories, Eclipse doesn't notice it - you have to give it a hint.
Check your project for build errors and build path errors.
Make sure you've defined an M2_REPO classpath variable in Eclipse (Preferences - Java - Build Path - Classpath Variables).
If you're using the m2eclipe plugin, right-click your project and click on Maven - Update project configuration. That will configure an Eclipse build path for your project based on your pom dependencies.
If you're not using m2eclipse, execute mvn eclipse:clean eclipse:eclipse in your project folder. Then refresh your project in Eclipse.
What you haven't said is that you've checked and the missing class is in fact present.
A quick way to check is in the code editor SHIFT+CTRL+T and type the name of the missing class. Eclipse should not only show you the class if it exists, on highlighting the class, Eclipse should tell you which jar it is in.
Based on the info you have provided, I would say some dependecy in your POM has been removed by mistake or you need a newer version of some jar. If you find the class is not present, then you can figure out which jar you need by googling something like Maven 2 MyMissingClass jar that usually works for me.
Delete the .metadata folder in your eclipse workspace and then again open the workspace and import the required project.
This will solve your problem.
In .metadata folder it maintains the temporary copy of the project.
what worked in my case was simply removing the project from work space and importing it back again.
But I still don't know why it worked Vs why other things mentioned did not work (I tried updating dependencies in fact I removed all the dependencies from pom.xml and added everything again)

Categories