I want to add a custom classpath when I'm running my maven project from within netbeans. So far I've tried adding the following to the Run Project action in the project properties:
exec.args=-classpath %classpath;c:/QUASR/duplicateRemoval.jar;c:/QUASR/lib/QUASR.jar ${packageClassName}
exec.args=-cp %classpath;c:/QUASR/duplicateRemoval.jar;c:/QUASR/lib/QUASR.jar ${packageClassName}
exec.args=-cp c:/QUASR/duplicateRemoval.jar;c:/QUASR/lib/QUASR.jar ${packageClassName}
but no luck, the custom runtime classpath is not set.
You should add a new profile run-with-netbeans in your pom that declares the additional dependencies (use the provided scope to not include them in the release).
Then you'll have to add the new profile to your IDE to run the pom with the -P run-with-netbeans option in the command line.
<properties>
<!-- provided by default -->
<my-dynamic-scope>provided</my-dynamic-scope>
</properties>
<profiles>
<profile>
<id>run-with-netbeans</id>
<properties>
<!-- compile when running in IDE -->
<my-dynamic-scope>compile</my-dynamic-scope>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
<scope>${my-dynamic-scope}</scope>
</dependency>
</dependencies>
The snippet above add log4j only when running with the run-with-netbeans profile. It also sets a property my-dynamic-scope that can be used in your dependency block to change the scope.
HIH
M.
Related
I am trying to download files of versions within range start.version and end.version in parent pom.
And, choosing specific version in child pom.
Parent POM
<properties>
<start.version>1.1.0</start.version>
<end.version>2.1.0</end.version>
</properties>
<profiles>
<profile>
<id>release</id>
<properties>
<model.version>[${start.version},${end.version}) </model.version>
</properties>
</profile>
</profiles>
EDIT: In parent POM I have also added model dependency
<dependencies>
<dependency>
<groupId>com.sample.project</groupId>
<artifactId>model</artifactId>
<version>${model.version}</version>
</dependency>
</dependencies>
Child POM
<dependency>
<groupId>com.sample.project</groupId>
<artifactId>model</artifactId>
<version>${model.version}</version>
</dependency>
All versions within range are downloaded but failing to collect dependencies.
When pass these arguments in goals -Dstart.version=1.1.0 -Dend.version=2.1.0. It is working fine.
But, not collecting when I give in properties.
I tried adding plugins in parent POM
<argLine>${start.version}<argLine>
<compilerArgs>
<arg>${start.version}</arg>
<arg>${end.version}</arg>
</compilerArgs>
And, copied these in CHILD POM. But, not working.
Have to give dependency inside dependency management in Parent.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sample.project</groupId>
<artifactId>model</artifactId>
<version>${model.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
By giving so, child POM Built successfully.
Can anyone explain pls!
A recent upgrade of groovy which brought with it JUnit5 has resulting in Eclipse wanting to run every test under JUnit5. I can sort of work around this by going to run configurations and tell Eclipse to use JUnit4, however this gets tedious.
Is it possible to tell Eclipse to always use JUnit4 for a particular project, including new tests?
You can specify a profile and activate it in Eclipse only.
Example (assuming your problem arose by having a dependency to groovy-all):
<profiles>
<profile>
<id>eclipse-groovy-no-junit5</id>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${groovy.groupId}</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>${groovy.groupId}</groupId>
<artifactId>groovy-test-junit5</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
</profiles>
Then go to
Project -> Properties -> Maven -> Active Maven Profiles
and specify the profile name eclipse-groovy-no-junit5.
Remark: groovy.groupId is set to org.codehaus.groovy (it's a variable, because it will be replaced by org.apache.groovy in 4.x) and groovy.version is set to 3.0.8.
If you want to be a bit more verbose, you can add...
<activation>
<activeByDefault>false</activeByDefault>
</activation>
...but it's the default anyway.
currently I'm working on a project in my company that imports XML data to our database. While doing this I rely on some basic configuration projects which have been already created and used in other Projects, i.e. an EntityManagerBuilder or other utility classes that are used in order to create a connection to our oracle database. And it seems to me that those dependencies are creating some problems for me.
My project runs perfectly fine if I start it within eclipse. And when I create the project with mvn clean install -DskipTests it builds all fine.
But when I want to run it from the command line the application starts and after a few lines of code just stops, without throwing any errors or exceptions.
The reason why I think that it has something to do with some dependencies is that by logging I managed to find the point where the application stops. Since it stopped at a point I could investigate, I just did that. I downloaded the sources an only added some logging and suddenly my application had no problems at all with that class, instead it just stopped with the next static call to an other class.
I have no idea at all where to search for the error. Since this is an application that has to run by it self as a monthly task, executing it from eclipse is not an option.
Hopefully someone can give me a hint how to solve this.
Here is my POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company.infrastructure.foo</groupId>
<artifactId>foo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>foo-import</artifactId>
<packaging>jar</packaging>
<name>FooImport</name>
<properties>
<company.consoleapp.main.class>com.company.infrastructure.foo.import.FooImporter</company.consoleapp.main.class>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.company.maven</groupId>
<artifactId>company-standalone-dm</artifactId>
<version>${company.parent.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<!-- Utilities -->
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<!-- Using foo-dataaccess -->
<dependency>
<groupId>com.company.infrastructure.marken</groupId>
<artifactId>foo-dataaccess</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>foo-import</finalName>
<plugins>
<!-- Consoleapp-Mixin -->
<plugin>
<groupId>com.github.odavid.maven.plugins</groupId>
<artifactId>mixin-maven-plugin</artifactId>
<configuration>
<mixins>
<mixin>
<groupId>com.company.maven</groupId>
<artifactId>company-consoleapp-mixin</artifactId>
<version>${company.parent.version}</version>
</mixin>
</mixins>
</configuration>
</plugin>
</plugins>
</build>
I think this might be something to do with your dependency management in maven, since you haven't specified the versions and maven figures out those versions automatically.
However when you run the application, you need those jars to be in your classpath otherwise you might end up getting a ClassNotFoundException because the jars are not available. So unless you figure out what your dependencies are like you mentioned and add them to your classpath you would end up seeing the error.
It might be worth enabling a further level of logging in your application to give you some indication of where the error is. You could also try and see if at the point of failure is referenced to an external library, which is the one that is not available in your classpath.
Could you also please share how your running your application through CLI.
In the pom.xml, i include logback & SLF4J like below, this works perfectly fine using maven build. It will give compilation error if i import directly from logback.
<dependencyManagement>
<dependencies>
<!-- We want to have slf4j with scope compile -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- logback we only want runtime, compiletime we want SLF4J -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
But how can I make eclipse honor the runtime scope of logback dependency and prevent import-suggestions from there?
Unfortunately it seems not to be possible on Eclipse with a normal build, as mentioned by #A4L, it is a known bug, check Bug 414645 and Bug 376616. Eclipse (m2e) can't properly manage Maven dependencies scope.
However, if you place the runtime dependencies on a profile, then Eclipse will not add them to the classpath (the profile shouldn't be active by default, though). I just tested it on Eclipse Mars and it works perfectly.
Hence, in your case you could add to your POM:
<profiles>
<profile>
<id>runtime</id>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
As such, it can't be used to compile on Eclipse. However, your build would then need to use it at runtime, running with -Pruntime in this case.
Although adapting your POM and build to an issue of an IDE might not be ideal, it could be a good compromise to achieve your goal.
Im trying to follow this tutorial:
https://docs.jboss.org/author/display/AS7/Helloworld+quickstart
But getting build error when following the simple instructions to clean + build package:
gert#gert-VirtualBox:~/workspace/jboss-eap-6.1.0.GA-quickstarts/helloworld$
mvn clean package [INFO] Scanning for projects... [ERROR] The build
could not read 1 project -> [Help 1] [ERROR] [ERROR] The project
org.jboss.as.quickstarts:jboss-as-helloworld:7.1.2-SNAPSHOT
(/home/gert/workspace/jboss-eap-6.1.0.GA-quickstarts/helloworld/pom.xml)
has 4 errors [ERROR] Non-resolvable import POM: Failure to find
org.jboss.spec:jboss-javaee-6.0:pom:3.0.2.Final-redhat-3 in
http://repo.maven.apache.org/maven2 was cached in the local
repository, resolution will not be reattempted until the update
interval of central has elapsed or updates are forced # line 68,
column 25 -> [Help 2]
I haven't edited the pom.xml file at all - shouldn't this just work?
I've googled it and came across this: https://community.jboss.org/message/762371#762371
But I don't seem to have a settings file anywhere?
Please, any help would be appreciated!
gvanto
POM FILE:
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<groupId>org.jboss.as.quickstarts</groupId>
<artifactId>jboss-as-helloworld</artifactId>
<version>7.1.2-SNAPSHOT</version>
<packaging>war</packaging>
<name>JBoss AS Quickstarts: Helloworld</name>
<description>JBoss AS Quickstarts: Helloworld</description>
<url>http://jboss.org/jbossas</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>
<!-- <version.org.jboss.spec.jboss.javaee.6.0>3.0.2.Final</version.org.jboss.spec.jboss.javaee.6.0>
-->
3.0.2.Final-redhat-3
<!-- other plugin versions -->
<version.compiler.plugin>2.3.1</version.compiler.plugin>
<version.war.plugin>2.1.1</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
<!-- JBoss distributes a complete set of Java EE 6 APIs including
a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
a collection) of artifacts. We use this here so that we always get the correct
versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can
read this as the JBoss stack of the Java EE 6 APIs). You can actually
use this stack with any version of JBoss AS that implements Java EE 6, not
just JBoss AS 7! -->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Import the CDI API, we use provided scope as the API is included in JBoss AS 7 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Servlet API, we use provided scope as the API is included in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- Set the name of the war, used as the context root when the app
is deployed -->
<finalName>jboss-as-helloworld</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- JBoss AS plugin to deploy war -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.org.jboss.as.plugins.maven.plugin}</version>
</plugin>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates
annotation processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
OK, here's what fixed it:
Commented out this line in the pom.xml: (I thought this is a type of variable that gets automatically inserted/replaced by eclipse/something, turns out NO IT IS NOT):
<!-- <version>${version.org.jboss.spec.jboss.javaee.6.0}</version> -->
Replace with:
<version>3.0.2.Final</version>
It now builds and I can deploy it fine, thanks for the help Nishant!
If you clone the quickstarts from the github repository, e.g.
git clone --recursive git://github.com/jboss-jdf/jboss-as-quickstart.git --branch jdf-2.1.9.Final
See: http://www.jboss.org/jdf/quickstarts/get-started/
then you will find a maven settings.xml file in the root directory (./jboss-as-quickstart/settings.xml)
For each example, run maven with that settings file:
cd jboss-as-quickstart
cd helloworld
mvn -s ..\settings.xml compile
See: http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/#configure-maven
You might have to create one (see this page for more details):
There are two locations where a settings.xml file may live:
The Maven install: $M2_HOME/conf/settings.xml
A user's install: ${user.home}/.m2/settings.xml
But I feel the issue is with the version string of the dependency. Hardcode the version and try again:
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.2.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Uncommenting the following line might work too:
<version.org.jboss.spec.jboss.javaee.6.0>3.0.2.Final
</version.org.jboss.spec.jboss.javaee.6.0>
Removing of redHat "postfix" resolved the problem, just have actual jar name, instead of having redHat postfix.
Have below dependencies in your pom.xml, then it will build successfully.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.2.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<version>1.0.1.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<version>1.0.2.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>