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.
Related
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.
I am using Eclipse ,Spring,tomcat server,maven.
I need to pass some parameters when i build the project with maven.Everything works fine when i do that using command line or when i right click on POM.xml and run it making run configuration changes in eclipse.
But as soon as i start my tomcat it is not able to find the value i want to pass in the parameter and it gives an exception
: Could not open ServletContext resource [/WEB-INF/classes/properties/application-${spring.profiles.active}.properties]
here ${spring.profiles.active} should be replaced the the argument value.
So eclipse is not using maven with argument to build and deploy on the server automatically.
Insert the required maven plugins (especially maven-eclipse-plugin) in the pom.xml for compiling the code and use the command mvn eclipse:eclipse in the project's base directory. This will do the required stuff to create a maven project in eclipse.
This is a very complicated subject where many things can go wrong. You need to be very explicit of how you are running tomcat. Are you using wtp? WTP would be the panel that says "Servers". Is this spring boot? Do have the m2eclipse wtp plugin installed (its very hidden and not easy to find)?
One easier way to get this right is just use springs version of eclipse.
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/
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.
I'm trying to use Google protocol buffer for Java(I'm a newbie about Java, just trying).
First of all, I'm using OSX and I've installed protocol buffer with brew install protobuf command.
protoc command works okay.
I've generated MyProtocol.java by protoc.
I've installed protocol buffer for Java as its instruction(README.txt).
mvn install command created .m2 directory and I can find protobuf-java-2.4.1.jar file somewhere in the directory.
I wrote simple test Java code just importing MyProtocol.java and it complains could not find package com.google.protobuf.
So, I've just make jar file mvn package and add its directory as CLASSPATH and it compiled well.
javac -classpath <protobuf-dir>/jara/target/classes Test.java ./com/example/tutorial/AddressBookProtos.java
If I use maven's repository directory (~/.m2/repository), it complains again.
Doesn't maven make CLASSPATH for me if I install the package?
If not, how can I use installed package by maven to compile my code?
The Maven Dependency Plugin has a goal called build-classpath which does what you need. You can get usage hints on the Usage page
Maven doesn't change your setup, so it's up to you to set your CLASSPATH according to your need.
However there are at least two ways in which Maven can halp you:
You can use the Maven Assembly plugin to collect all your dependencies in a directory or an archive, so that you only need to add a single directory to your CLASSPATH in order to run your program;
You can use the Exec Maven plugin to add the running of your program as a goal in your POM and then run it with Maven.