Absolute path of java gradle project - java

I have a problem setting gradle project with absolute paths of already existing java projects.
So, I have a new gradle project admin-tool, but somewhere on my file-system I have existing java eclipse projects say ejb-services, dao-services (which are not gradle projects) so I want to integrate them in my new gradle project.
Is there any solution, that will give me freedom ejb-services and dao-services projects to be on any file-system location and integrate them in my new gradle project.
I have try with
project("dao-services").path = new File(/*absolute path*/)
include "dao-services","admin-tool"
also
project("dao-services").projectDir = new File(/* absolute path */)
include "dao-services","admin-tool"
But they all give me error that project dao-services could not be found.
From what I have search it's seems to me that gradle only uses relative paths to root project and you can't go out that scope, but I haven't found any information regarding this to be sure.
Best Regard and thanks in advance

You forgot about the ':' in the module name, as in the
project(":dao-services")

Related

Issue with building Android Bundle - throws error "File 'root/lib/commons-io-2.4.jar' uses reserved file or directory name 'lib'"

I have recently added support for 64-bit devices on my android app, making me resorting to build the app into bundle instead of apk (since the apk file size is over 100mb). When I did that, I get the following error:
File 'root/lib/commons-io-2.4.jar' uses reserved file or directory name 'lib'.
The problem is, I can't find any commons-io anywhere in the code, and its not declared as a dependency in build.gradle file in the main app project or any of the modules. I can only find commons-io.2.4 under External Libraries. I tried different things to try and to remedy this issue (clean/rebuild project, invalidate caches and restart, convert all 'compile' into 'implementation', etc), nothing seems to do the trick. Does anyone have any idea on how to get past this and build the app into a bundle? Any input would be greatly appreciated!
I had the same issue. I fixed it by following these steps:
1) add the commons-io-2.4.jar to your libs directory
2) remove this line from your dependencies
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
3) add this line
implementation files('libs/commons-io-2.4.jar')
4) synk gradle and rebuild project
P.S.: I don't think it's the right way to fix the issue, but it works.

Intellij & Gradle module file name

I'm trying to move an existing project to gradle from ant. I'm using Intellij 13, and I've managed to get one module running under gradle by deleting the iml file. However, it insists on writing an iml file that has a name that matches the directory name not the module name.
I recognize that this is probably not a problem for folks who work alone or on a single team in a large company where the IDE and version is handed down from on high. However this project involves a variety of contractors from several companies who all supply their own IDE's. Intellij's licensing model makes it impractical to supply the IDE to outside contractors because most work is done off site and there is no way to take back or de-authorize the license key once you give it out.
Since upgrading Intellij is not free, it's nearly impossible to coordinate everyone to upgrade at once and so I use the file based project format, with a project file named ourproject.ij12.ipr1 and another named ourproject.ij13.ipr and the iml files for the module in the directory foo are foo.ij12.iml and foo.ij13.iml
This works great, and the policy is that everyone has until 14 comes out to get off of 12 so that we don't get an infinite number of versions going, but we don't have to synchronize our upgrades too the nanosecond either.
Unfortunately, as soon as I try to use build.gradle in the foo directory in intellij, it writes foo.iml which totally breaks the forgoing conventions. Furthermore, it adds another module (without asking) and that leads to two modules in the same directory and the ide won't let you change either one because two modules in the same directory are an error.
Can anyone tell me how to influence the file name that Intellij writes for the iml file when using gradle? obviously having separate directory names is not going to do it unless I get very elaborate with symlinks and ant.symlinks task, and that won't work if anyone trys to run it natively on windows.
EDIT: Since folks seem to be in the habit of deleting their unaccepted answers, let me clarify. I am aware of the gradle idea eclipse plugins. I am not asking for a guide to IDE agnosticism. I find there are things of value in IDE setups, and want to share them among others using the same IDE (where "same" includes the version, cross version sharing is not expected, but more than one version at a time is).
To be more specific, I am looking for one of these:
A configuration or trick that allows me to control the file names of iml files
Another way to maintain two versions of ide files, that is not too byzantine.
Confirmation from one of the JetBrains folks who participates in SO that there is no longer a way accomplish my goal with IDEA.
EDIT2: Solutions involving gradle generating the files are not going to work. Intellij 13 changes the file name to match the directory name not the module name, which is the soruce of the problem. I need a solution that convinces Intellij not to do that. I had no problems before the upgrade to 13.
Using the idea plugin I was able to get it to generate two iml files for me based on a commandline parameter. Here is the (minimal) build.gradle file I created
apply plugin: 'java'
apply plugin: 'idea'
def imlName = name + (hasProperty('generate12') ? '.ij12' : '.ij13')
idea {
module {
name = imlName
}
}
This script will generate a '13' file for you by default. So to change that you will need to set the generate12 property.
Commands I ran:
> gradle idea
> gradle idea -Pgenerate12=true
> ls
build.gradle test.ij12.iml test.ij13.iml test.ipr test.iws
The idea module documentation might have some more useful things for you.
Side note:
I think it would be best if you gave the project without iml files to everyone and told them to run gradle idea(without the custom iml name stuff) to let the files be created. This will allow you to not have to maintain files that will get modified and overwritten by IntelliJ. We check in iml files and it causes nothing but problems when someone checks something in and breaks it for everyone.
Use settings.gradle file to change module names. Intellij should use it.
Next, you can use gradle.properties to set your prefix.
E.g.
setting.gradle:
rootProject.name = adjustName("ourproject")
include "someProject"
// ... other includes
rootProject.children.each{ it.name=adjustName(it.name)}
String adjustName(String name) {
String pref = System.properties['myIdeaVersionPrefix']
return pref != null ? name + "." + pref : name
}
gradle.properties:
systemProp.myIdeaVersionPrefix=ij13
see screenshot for the configuration at http://i.stack.imgur.com/CH2Bv.png
There doesn't seem to be a good answer for this. I have filed this as a bug in YouTrack http://youtrack.jetbrains.com/issue/IDEA-119625.

Can't find string resources from another project

I have an Android project let's call it SimpleProject in that project I get strings in this way getString(R.string.error) I keep all my strings in the projects /res/values/strings.xml. Besides SimpleProject is not a library project. Now I add my SimpleProject src folder as a linked resource to another project lets call it TestProject and then I try to build my TestProject Eclipse give me error that he can't find R.string.error. What can I do to solve this problem ?
EDITED:
I think about following issue
If I change all my applications packages to the same for example com.android.victor in that case all R-s will be same com.android.victor.R and if I add one project to another it will not bring to that that R will not be found. Am I right ? and what problems can appear in this case ?
I think you need to change the order,
1.go to Java Build Path
2.go to Order and Export and move the SimpleProject reference to be above the TestProject folders

Eclipse Build Path Nesting Errors

I'm working on a simple JSP/Servlet/Tomcat webapp for my class. The professor asked us to use a folder structure that is slightly different than the default dynamic web project structure. Rather than using the webcontent folder he wants all of our source code under src/main/java and src/main/webapp.
When I run the app my welcome file displays fine, but when I try to access my servlets I get:
Http 500 SEVERE: Allocate exception for servlet InitDb
java.lang.ClassNotFoundException. I'm pretty sure it's a build path error. I have final/src on the build path but I am receiving the warning
"Cannot nest 'final/src/main/webapp/WEB-INF/classes' inside 'final/src'. To enable the nesting exclude 'main/' from 'final/src'
I have this in my deployment assembly:
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
When I exclude main/ the warning goes away, but it doesn't fix the problem. I would appreciate any advice. Thanks.
I had the same problem even when I created a fresh project.
I was creating the Java project within Eclipse, then mavenize it, then going into java build path properties removing src/ and adding src/main/java and src/test/java. When I run Maven update it used to give nested path error.
Then I finally realized -because I had not seen that entry before- there is a <sourceDirectory>src</sourceDirectory> line in pom file written when I mavenize it. It was resolved after removing it.
I wanted to throw in a non-mavenish answer to this thread.
Due to version control and strict directory structure reasons, I was unable to follow Acheron's answer (the best answer) of doing something similar to removing src/ and adding src/main/java and src/test/java to the build path.
I had actually been off-and-on battling this nested build path issue for a couple weeks. The answer to the problem is hinted in the error message:
To enable the nesting exclude 'main/' from 'final/src'
Fix
In your build path, you need to edit your Inclusion and Exclusion Patterns by clicking on Excluded: (None) and then Edit...:
Go to the navigator and press right click on the project
Build Path
Configure Build Path
Source (tab)
There you can add main/webapp/WEB-INF/classes as an Exclusion Pattern. Then it should allow you to add main/webapp/WEB-INF/classes to the build path as a separate source folder.
Here is a simple solution:
Right click the project >> properties >> build path;
In Source tab, Select all the source folders;
Remove them;
Right click on project, Maven >> Update the project.
Try this:
From the libraries tab:
Eclipse -> right click on project name in sidebar -> configure build path -> Libraries
Remove your web app libraries:
click on "Web App Libraries" -> click "remove"
Add them back in:
click "Add Library" -> click to highlight "Web App Libraries" -> click "next" -> confirm your desired project is the selected option -> click "Finish"
Highlighting "Web App Libraries":
I had the same issue and correct answer above did not work for me. What I did to resolve it was to go to Build Path->Configure Build Path and under the source tab I removed all the sources (which only had one source) and reconfigured them from there. I ended up removing the project from eclipse and import the maven project again in order to clear up the error.
In my case I have a gradle nature project in eclipse, the problem was in a build.gradle, where this sourceSets is specified:
sourceSets {
main {
java {
srcDir 'src'
}
}
}
This seems to works well with intelliJ,however seems than eclipse doesn't like nest src, src/java, src/resources. In eclipse I must change it to:
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
}
You have to separate your sources and your target directory where the build output goes. It's also important to note that no class files ever can end up in the source directory. This is not against your professor's advice - actually he's promoting the maven standard source structure going for ./src/main/java and ./src/main/webapp. The second one should hold eg. the mandatory WEB-INF/web.xml file but you will never put actual classes there.
What you need to change is your target directory. I suggest going with the same standards and choosing the name "./target" for this. All the built files will go in here and packaging that up will result a correct deployable artifact. Should you migrate to using maven later, it'll also help doing this in a scripted, repeatable way.
Hope that clears up your issue.
The accepted solution didn't work for me but I did some digging on the project settings.
The following solution fixed it for me at least IF you are using a Dynamic Web Project:
Right click on the project then properties. (or alt-enter on the project)
Under Deployment Assembly remove "src".
You should be able to add the src/main/java. It also automatically adds it to Deployment Assembly.
Caveat: If you added a src/test/java note that it also adds it to Deployment Assembly. Generally, you don't need this. You may remove it.
This started taking me down a huge rabbit hole of fixing glitches with Eclipse, however I just deleted the project from Eclipse and reimported it to fix it.
Got similar issue. Did following steps, issue resolved:
Remove project in eclipse.
Delete .Project file and . Settings folder.
Import project as existing maven project again to eclipse.
For Eclipse compiler to work properly you need to remove final/src from the source path and add final/src/main/java instead. This may also solve your problem as now the build directory won't be inside the Java source folder.
It depends on which folder one is telling "Use as Source Folder" to. In the structure on the picture if one says it to the folder "target" or "generated", he gets the "nested" error. But on "cxf" folder, which is the last, mentioned in the pom.xml's 'plugin' section and where from the package structure begins (as shown on .wsdl file), i.e. - the right folder to do it 'source' one, then there is no error
If other solutions did not work and you are using any plugin adding sources in your pom.xml check it. I used build-helper-maven-plugin to add classes generated from openapi specification with incorrect configuration:
<source>${project.build.directory}/generated-sources/openapi/src</source>
instead of correct:
<source>${project.build.directory}/generated-sources/openapi/src/main/java/</source>
So after correcting:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Make two folders: final/src/ to store the source java code, and
final/WebRoot/.
You cannot put the source and the webroot together. I think you may misunderstand your teacher.

java.lang.NoClassDefFoundError: com.google.ads.AdView

I am attempting to incorporate admob ads in my app. So far I have added the following code
in the onCreate method of my app's main activity...
adView = new AdView(this,AdSize.BANNER,"my code number");
adView.loadAd(new AdRequest());
The program compiles without error but at run time I get the message java.lang.NoClassDefFoundError: com.google.ads.AdView. I have seen a supposed explanation of the problem and the cure here but I could not see how it was applicable to my project because I do not have either a "lib" or "libs" directory within my project.
According to eclipse's SDK manager, I have the most up to date version of everything that I use.
I had a similar problem, but did not have to add the libs folder; I tried, with no success, then removed them afterwards, when I realized that I had just forgotten to export the included Jar archived.
Fix:
Select project settings > Java Build Path, then Order and export.
Here, check the GoogleAdMobAdsSdk-package.
This should solve the NoClassDefFoundError-issue.
Just create manually the "libs" folder, and add your libraries there. By default, they doesn't exist
Project-> Clean
Project settings -> Java Build Path. Open "Order and export" tab.
Check GoogleAdMobsAdsSDK.
It is worked for me.
Was getting this error updating from android 16 to 20.
Solved by going to Java Build Path, Order and Export tab, checked and moved GoogleAdMobAdsSdk just under my source. For some reason that fixed it.
Changing the order back didn't break it. So some setting must have needed to be initialized.
I had this problem, and this problem too:
Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode and Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode
Despite many hours of following all solutions listed the only way I could get my app to work was to use the AdMob banner example here:
https://github.com/googleads/googleads-mobile-ios-examples/tree/master/admob/SmartBannerExample
And re-build my project around it, copying my files in to that project. If you are stuck, try it.
Don't know why it worked, but now it does. Something in my project was very wrong. Now I can carry on with my work. I love Google/Android, but really what a mess!
See this answer Android update 17 seems incompatible with external Jars.
You need to put all jars in libs folder insted of lib.
It's not enough only to add "GoogleAdMobAdsSdk-6.4.1.jar" in Java Build Path,then you should switch to table:Order and export.check the "GoogleAdMobAdsSdk-6.4.1.jar" here.
UPDATE:
Select project settings > Java Build Path, then Order and export.
Here, check the google-play-services.jar.
This should solve the NoClassDefFoundError-issue.
In my case I needed to click on the "Android Private Libraries" on the "Order and Export" Tab
Go to Properties - Java Build Path - Order and Export and check every Checkmark! That did the trick for my project.

Categories