Building android-maven project in netbeans - java

I am trying to get up and running a new android-maven project in Netbeans 7.1.1. I keep getting this error
Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1:dex (default-dex) on project myproject: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0_03\jre\bin\java" -Xmx1024M -jar "C:\Program Files\Android\android-sdk\platform-tools\lib\dx.jar" --dex "--output=C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\MyProject\target\classes.dex" "C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\MyProject\target\classes"", Result = 1 -> [Help 1]
This is the pom file: http://pastebin.com/k1ZzfEYY

No. You don't have to downgrade to a Java 6 SDK from Java 7 SDK to use Maven with Android.
The problem is that after you made some updates with the SDK Manager something got corrupted and you no longer have the dx.jar file in your android-sdk\platform-tools\lib folder, and when you try to build with Maven your project doesn't have that jar in the path and it fails to build.
To fix this you need to open the SDK Manager and delete the "Android SDK Platform-tools" that you currently have installed and reinstall it. After that go to the android-sdk\platform-tools\lib folder and see if the dx.jar file is there and try to build your project with mvn clean install android:deploy.
I've tested this with the sample helloflashlight application and it worked correctly after I've reinstalled the platform tools.
Also make sure that you have the environment variables JAVA_HOME, ANDROID_HOME, M2_HOME pointing to the right paths.

Related

VS Code Showing 'mvn' is not recognized as an internal or external command

I'm trying to create a maven project with VS Code but when I run the command it says :
'mvn' is not recognized as an internal or external command,operable program or batch file.
but mvn -version is running on command prompt
Environment varaible for User :
MAVEN_JOME : C:\apache-maven-3.6.1,
M2_HOME : C:\apache-maven-3.6.1,
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_212\jre and
System Variables
path is set to C:\apache-maven-3.6.1\bin, C:\Program Files\Java\jdk1.8.0_212\bin for maven and java respectively.
The command I'm running to create the project is:
mvn archetype:generate -DgroupId=com.cs.test-project -DartifactId=test-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false The Reference to Command
And the VS Code Reference to Command
The same command is running in Command prompt and it created the project successfully on Desktop.
I fixed this problem by simply restarting VSCode as I had set my PATH variable while my VSCode was running so the changes were not reflected to the VSCode integrated terminal until I restarted it.
It's kindy counterintuitive as path has to be pointed to the actual mvn command, instead to a M2_PATH folder. Also once properly pointed, a new error will be shown if your environment is missing proper jdk within JAVA_HOME. The error is trown by maven. Maven plugin is kinda stupid as it will ignore your default JDK configured within settings.json (java.home or/and java.configuration.runtimes properties) and will happly NOT set java for maven. You have to configure it specificly for maven plugin as this:
"maven.executable.path": "c:\\apache-maven-3.8.1\\bin\\mvn",
"maven.terminal.customEnv": [{
"environmentVariable": "JAVA_HOME",
"value": "c:\\openjdk-1.8.0_232-redhat",
}]
Of course, both paths should be pointed to proper folders/files in your environment.
The way I fixed was by changing the exec path in Vs Code settings from CMD to Powershell.
Open
settings -> features -> terminal
Change the windows exec path from cmd to where you have PowerShell.
For example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Windows exec setting
On Tuesday Oct. 25, 2022 while trying to solve the same problem, I went through all of these previous solutions for Windows and finally had to resort to the official installation docs:
Installing Apache Maven
Unzipped the download and located the bin directory and manually added that directory location to my: System Properties>Advanced>Environment Variables>'Path'
For good measure, restart the computer.

Hadoop 3.1 build fail at `protoc --version`

I am trying to compile Hadoop 3.1 from its source code.
Once inside docker container i am building it with maven following included instructions in BUILDING.txt inside Hadoop's source code files.
While Apache Hadoop Common ............................... FAILURE [ 0.458 s] is trying to build, i am getting the following error, regarding protoc --version
[ERROR] Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:3.1.0:protoc (compile-protoc) on project hadoop-common:org.apache.maven.plugin.MojoExecutionException: 'protoc --version' did not return a version -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:3.1.0:protoc (compile-protoc) on project hadoop-common: org.apache.maven.plugin.MojoExecutionException: 'protoc --version' did not return a version
However, the protoc command is working on my installation:
$ protoc
Missing input file.
$ protoc --version
libprotoc 2.5.0
Same thing is happening with protoc version 3.0.
Anyone experienced something similar?
After not finding the exact solution, here is a workaround.
Hadoop's source code, comes with ./start-build-env.sh. Upon running the script, a Docker container will be launched by it, in which Hadoop can be build with Maven.
All the necessary libraries exist in the container, but are only included in user's $PATH, and not root's $PATH. That's a problem because it comes handy using sudo to build the package, and that's the reason that protoc --version could not return something.
Now every container launched by ./start-build-env.sh seems to be temporary, and you can't edit the root's $PATH via ~/.bashrc. A workaround is to launch the container through ./start-build-env.sh and from another terminal window, log into the container using the command: sudo docker exec -it <container> bash. Now you can download a simple editor (like nano or vi through apt-get), and edit the default $PATH in visudo.
Then the command sudo mvn package -Pdist... inside the container, wont stuck in the problem I described above

Jenkins Maven how to fix wrong command

Learning Jenkins. Windows 7 running jenkins-2.73.3, a maven project gives following output:
20:29:11 [test] $ "C:\Program Files\Java\jdk1.8.0_102/bin/java" –Xmx1024m –XX:MaxPermSize=256m -cp "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven33-agent-1.12-alpha-1.jar;C:\Apps\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar;C:\Apps\apache-maven-3.3.9/conf/logging" jenkins.maven3.agent.Maven33Main C:\Apps\apache-maven-3.3.9 "C:\Program Files (x86)\Jenkins\war\WEB-INF\lib\remoting-3.10.2.jar" "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven33-interceptor-1.12-alpha-1.jar" "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.12-alpha-1.jar" 50129
20:29:11 Error: Could not find or load main class –Xmx1024m
20:29:41 ERROR: Failed to launch Maven. Exit code = 1
20:29:41 Finished: FAILURE
The problem is obvious: java takes -Xmx1024m as the main class. But the command is generated, how can I move "-Xmx.. -XX:Max.." to the end of the command?
Removing "–Xmx1024m –XX:MaxPermSize=256m" from Maven Project Configuration / Global MAVEN_OPTS on Jenkins fixed the issue.

Installing opencv on openshift for java development

I am trying to install opencv on openshift. following the post mentioned here
http://codingexodus.blogspot.in/2013/04/how-to-install-opencv-on-openshift.html
I am developing in java so i have installed jdk1.8 and apache ant into the $OPENSHIFT_DATA_DIR
I had to install apache ant also so i did the same again in the $OPENSHIFT_DATA_DIR
my JAVA_HOME is set to the jdk and even ANT_HOME is also pointing to the right place
JAVA_HOME="$OPENSHIFT_DATA_DIR/jdk1.8.0_05"
I am doing a cmake in the end to generate the makefile with the command
cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_SHARED_LIBS=OFF ..
going through the cmake output i do see that for java it has found the ant, jni etc. finally when i execute a
make
make install
i get the error
make: *** No targets specified and no makefile found. Stop.
there is no make file generated. what am missing.

can't get Ant to work

I am trying to run Cordova on my ubuntu 12.04. When I try to create the project, its throwing me this error
k#k-cm:~/Development/Android/ionic/hello$ cordova platform add android
Checking Android requirements...
Creating android project...
[Error: An error occured during creation of android sub-project. Looks like your environment fully supports cordova-android development!
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.ionic.toderp
Name: toderp
Android target: android-17
Building cordova-3.2.0.jar
{ [Error: Command failed:
BUILD FAILED
/home/k/Dev/android-sdk-linux/tools/ant/build.xml:710: The following error occurred while executing this line:
/home/k/Dev/android-sdk-linux/tools/ant/build.xml:723: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-7-openjdk-i386/jre"
Total time: 0 seconds
] killed: false, code: 1, signal: null }
]
Here is my PATH
/usr/lib/jvm/java-7-openjdk-i386:/home/k/Dev/android-sdk-linux/tools:/home/k/Dev/android-sdk-linux/tools:/home/k/Downloads/android-ndk-r8e:/home/k/Downloads/android-ndk-r8e:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/k/Home/k/Dev/android-sdk-linux/tools:/home/k/Home/k/Dev/android-sdk-linux/platform-tools:/usr/lib/jvm/java-7-openjdk-i386/bin
JAVA_HOME
/usr/lib/jvm/java-7-openjdk-i386
Please help!
This issue is due to that Ant can not find the tools.jar file.
You need to copy the tools.jar file and put it in the lib folder for the ant to work.
Do a search for tools.jar file in the lib folders from other sdk libraries and put that in the above path in error.

Categories

Resources