I know this is not a smart question.
I need to use ant from command line and there is Ant plugin in Eclipse, so I have tried to specify ANT_HOME in Eclipse to be set to the directory of that plugin.
C:\Users\Nikolay>ant
'ant' is not recognized as an internal or external command, operable program or batch file.
Should I install a separate Ant from Apache to enable Ant from command line?
Probably the best solution is to install ant, but you can use the binaries that are from Eclipse too. You will find the binaries under eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030. Note that the plugin the version may be different on your machine. Something like:
${eclipse_location}\plugins\org.apache.ant_1.8.2.v20120109-1030\bin\ant
should work. But this should be used only for solving something quick, until you can install ant. Since you will upgrade your Eclipse/plugins and the paths will change and you will need to keep updating your environment variables this way.
Related
assuming my Eclipse uses an 'internal' Maven, located in the path: C:\Eclipse\plugins\org.eclipse.m2e.maven.runtime_1.6.2.20150902-0001
How can I launch from the system console commands that use that EMBEDDED Maven?
Specifically, to launch a class packA.packB.MyClass and its dependencies to load correctly.
thanks!
As far as I know you cannot use the internal Maven of Eclipse on the command line.
You need to get a command line Maven as well and use that.
When I run mvn clean test, it gives me the following error:
'mvn' is not recognized as an internal or external command, operable program or batch file."
This is the link of my project.
I can run the tests by right-clicking on the Runner.java => Run as => JUnit Test. I can also run the tests from the JUnit 4 Test Explorer Tab.
I have read some articles where it's suggesting to set the PATH for Maven but all of them are about the case where you are installing Maven separately. I am not sure what PATH do I need to set when Maven is coming with Eclipse.
I did not install Maven separately, it came with my Eclipse version.
My Eclipse Version :
Eclipse IDE for Java Developers
Version: 2019-03 (4.11.0)
Build id: 20190314-1200
Some IDEs (IntelliJ for example) have their own version of maven for internal purpose. But it doesn't mean that's able to be used by the command line. If you want to compile your project using mvn clean install/package/deploy/test/etc you must install maven in your machine and set de VARs in the OS.
I guess Eclipse has the same behavior that Intellij, so please also install maven in your machine
This error means that Windows cannot find an executable program called "mvn". This means it is not on your path/current directory.
When you right click and run your junit tests, it invokes it using the JVM, using the java command. I suspect if you type "java -v" into CMD, it will not give you the same error.
Since Windows does not know where to look for maven, you must tell it implicitly, by setting your path to the directory containing the mvn executable. You can lookup "eclipse bundled maven default location" to find this, although it might be worth downloading it separately from the Apache website, and manually specifying the path.
TL;DR: Is there a standard way in the Java world, to have the build tools install the executables they just built (like the make install of the C world)?
(I would be happy with a solution that would work only on Linux)
More details:
I have a Java project distributed via github. Compilation and dependencies are managed with maven 2. Running mvn package builds a tarball with my jar and the dependencies needed at runtime, plus an executable script which set the classpath and launch the main jar:
#!/bin/bash
cpBase="$(dirname "$0")"
java -cp "$cpBase/*" dw.cli.Program $#
So, if someone wants to install this on her computer, one need to:
run mvn package
and then to unpack the tarball and to copy the content in a directory on her PATH.
On the other hand I like the way the autotools are working: the user doesn't need to copy anything manually, because the build step make install handles the installation for her.
I could emulate this behaviour using cp through ant tasks in my pom.xml, but I'm more interested in learning the Java good practices than to provide non standard behaviors.
It seems maven doesn't provide this behavior. On the other hand, I'm totally ignorant of what the other Java build tool can do wrt to this.
Edit:
As far as I understand mvn install and mvn deploy don't fit my need, because they will install my jar in my local or remote repository. Whereas I want to install my executables on my PATH (eg: to install my wrapper script in /usr/local/bin)
The question is tagged "gradle", so I'll supply the Gradle answer.
I take it you're building an application, not a library. In that case, Gradle is thoughtfully supplying the application plugin.
apply plugin: 'application'
The plugin will supply you the run, distZip, distTar and installDist tasks, which do just what they sound like. Check out the documentation at
the official web site.
Note that the installDist task doesn't, by default, put the software anywhere centrally on the system. Rather, it will install in a subdirectory of build, where temporary files are kept. You could set the destinationDir property on the task to remedy this.
You can created a distribution archive (zip, tar.gz) which can be downloaded by the user and only needed to unpack and add the bin folder to the path.
The problem is that you can't automatically enhance you path environment variable. But if you use the generated scripts from appassembler-maven-plugin you can simply can call directly the generated scripts without enhancing your path. This works on linux as well as on windows.
This can be achieved by a combination of appassembler-maven-plugin and maven-assembly-plugin.
The appassembler-maven-plugin will create the appropriate shell/bat/cmd files for you and the maven-assembly-plugin can create the appropriate archives (tar.gz, zip) for you.
As an example you can take a look here:
https://github.com/khmarbaise/supose/tree/master/supose-assembly
"make install" works by copying your built artefacts into their target location. This behaviour is quite easy to emulate in ANT, because like make it allows you to specify your own build logic:
<target name="install" description="Copy binaries into install location">
<mkdir dir="/opt/myapp/bin"/>
<copy file="${dist.dir}/myproject.jar" todir="/opt/myapp/bin"/>
<copy file="${dist.dir}/myproject.sh" todir="/opt/myapp/bin"/>
<chown owner="${install.owner}">
<fileset dir="/opt/myapp" include="**/*"/>
</chown>
</target>
Course you'd have to run this target as root:
ant build
sudo ant install
Maven on the other hand is a highly opinionated build tool that does not support this kind of workflow. Why? This is really a deployment action. Of course you can customize the Maven setup using ant ANT plugin, but I'd advise to just have a shell script you run afterwards. Lot easier to understand:
mvn install
sudo install_myapp.sh
The script can pickup the built jar from the Maven local repository "$HOME/.m2/repository" or better still download it from a Maven repository!
You have other mvn goals like 'mvn deploy' and 'mvn install' that do what you need.
I want to be set an archetype for a stable JavaFX (Java 8) Maven build that will produce an executable JAR that (always) runs from the command line. And preferable without needing to build an UberJar or similar.
When we use the Netbeans 'Maven JavaFX' archetype the resultant JAR file following a build runs. As a project grows we find that sometimes the JAR won't run from the command line. Some Maven POM edits have been needed to 'encourage' the program to run from the command line again. This applies to Linux and Windows.
This also happens directly with the ZenJava JavaFX archetype, e.g. a project artifactId=xx:
java -jar target\xx.jar
no main manifest attribute, in target\xx.jar
This is just from the mavan generate command. The details of the two archetypes in question are:
zenjava
archetypeArtifactId=javafx-basic-archetype
archetypeGroupId=com.zenjava
netbeans
archetypeArtifactId=javafx
archetypeGroupId=org.codehaus.mojo.archetypes
Comparing the resulting POM files shows these that the codehaus.mojo (netbeans) uses these plugins in the build:
maven-dependency-plugin
maven-compiler-plugin
exec-maven-plugin
Either project runs happily from within Netbeans IDE. The challenges occur when we want to test on command line. It isn't really the best look externally when the build looks unstable to outsiders like that.
The questions arising are about what are the requirements to make a JavaFX command-line executable JAR file? For JDK 8 and beyond.
Is there an alternative JavaFX archetype available that will build projects with dependent JAR-s and run from the command line?
What allows Netbeans (say) to execute JAR when the same the built JAR won't run on the command-line?
What 'magic' does Netbeans be add to the execute step?
What is needed for the zenjava archetype to run "Java -jar"?
The JAR resulting from the follow steps doesn't run on the console.
mvn archetype:generate -DarchetypeGroupId=com.zenjava -DarchetypeArtifactId=javafx-basic-archetype ... -DartifactId=xx
mvn install
java -jar target/xx-001.jar
What influences the: maven-dependency-plugin and maven-compiler-plugin when building the JAR for bigger projects?
In other words, what assumptions might be being broken a project grows and bind with other JAR files.
Needless to say, the Maven generate and build steps are using the JDK Java environment. The execution though, java -jar target/xx-001.jar, need to run under the simple JRE (without the JDK). I guess question #4 is a long stretch unless you are someone who has a biggish JavaFX project and solved this already. Suggestions welcome.
just to mention: I'm the maintainer of the javafx-maven-plugin (and the archetype).
To answer your question 3:
You have to call the GENERATED jar-file from the plugin, which is located at target/jfx/app/yourapp.jar
The generated jar-file will reference all required dependencies, which are noted inside the META-INF/MANIFEST.MF-file inside it. While creating that jar-file, the pom is scanned for runtime-dependencies, these will be placed at the target/jfx/app/lib-folder. When bundling your app into native bundle, the JRE is put aside of the generated launcher under the target/jfx/native/-folder.
What confuses me about your problem: mixing CLI- and GUI-application might result in problems, but i guess it's just your special requirement :)
EDIT:
Calling mvn install does NOT generate jfx-jar without special configuration, you have to call mvn jfx:jar or mvn jfx:native to call the MOJOs of the plugin. For easier configuration, please visit our configuration-website: http://javafx-maven-plugin.github.io/
Java newbie here. I'm trying to run the latest version of MWDumper, which is a command-line utility that imports wiki databases. The page said I should build it from its source. I've downloaded the source-code. They've got a makefile and a build.xml. How do I build this?
You need to install ANT and run ANT in the folder containing the build.xml.
If you're on linux or mac it's pretty easy - you just [package manager name here] install ant;
You then just cd to the appropriate folder and type in ant. It should build your app.
You also need to make sure that you have the Java Development Kit installed for the ANT to use. Ant doesn't actually do any compiling, it's just a tool that reads build instructions and calls various applications and compilers to output the end executable (or similar product).
You should be able to install 'jdk' from your package manager, or from their site (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
If you're on Windows, you can install the JDK from the same link, and you can follow the following link as a guide to install ant for windows: http://ant.apache.org/manual/install.html
Don't forget to add the path to ant to your environment 'PATH' variable! :) (more details in the link above)
Use Apache Ant.
cd <dir>
ant <target>
Also you can use Apache Maven.
cd <dir>
mvn install