I have a class that I coded in a standard java project in eclipse on OSX (Java 1.6). The class uses classes and interfaces from another library.
I select the class, then do Run As > Java Application and all works well.
After that I try to run my project as a Maven project and things start to get a little frustrating.. I summarise all the steps here hoping that someone will tell me what I am doing wrong:
- From the standard java project I right click and did Configure > Convert to Maven project and clicked Finnish. All good so far.
Then Build Path > Configure Build Path > and add the folder that contains my project. Still good
THEN I remove all the #Override annotations since I read somewhere on SO that Maven uses JDK 1.5 instead of 1.6. Whatever, I remove them and my red flags go away. At this point my class looks exactly like in the original java project (except for the #override that I removed)
THEN I do Maven > clean. I get build success
THEN Maven > Install. I get a build success
THEN I select my class and do Run As > Java Application and I get this ugly looking trace:
Exception in thread "main" java.lang.NoClassDefFoundError: LMAXTrading/algos/HeartbeatClient
Caused by: java.lang.ClassNotFoundException: LMAXTrading.algos.HeartbeatClient
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I don't know where to go from here. You can imagine that I went through a lot of trials and errors and searched on SO and elsewhere to find a way to get this to work. But I just cannot figure out what is wrong. So if someone has an idea I am so ready to listen.
I am pasting below my directory layout from the Navigator View as well as from the Package explorer view
And here is the POM.xml where I have added the JRE config
<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>
<groupId>someproject</groupId>
<artifactId>someproject</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The project directory structure does not match with the default Maven directory structure. Maven expects the source to be in src/main/java directory under the root folder (the folder containing pom.xml). The source here is in the src folder hence the No sources to compile error.
You can either move your sources to use the default Maven directory structure or change the pom.xml to explicitly specify your source directory by adding the following to the build section of the pom:
<sourceDirectory>${basedir}/src</sourceDirectory>
More info on Maven's standard directory layouts can be found here.
Related
I am using Eclipse Mars to run my Java project. I am making use of Maven in it. But while trying to compile my package I am getting the following error.
Failed to execute goal on project apex-check: Could not resolve dependencies for project org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0: Failed to collect dependencies at org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Failed to read artifact descriptor for org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Could not transfer artifact org.fundacionjala.enforce.sonarqube:apex-squid:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): Failed to authenticate with proxy -> [Help 1].
I am able to find that my pom.xml has a bug in its dependency. But don't know how to resolve it. I have given below my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) Fundacion Jala. All rights reserved. ~ Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fundacionjala.enforce.sonarqube</groupId>
<artifactId>apex</artifactId>
<version>1.0b${build.number}</version>
</parent>
<artifactId>apex-check</artifactId>
<name>Apex :: Checks</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apex-squid</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
I have written 'apex-check' and 'apex-squid' as two separate projects.
Can anyone explain how to correct my pom.xml?
You need to have:
org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0
org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0
jar files available in your local .m2/repository folder. If they are not present maven will try to download from central repository and as an expected result it will fail on firewall or it will not find the artifact. i.e. if:
apex-check requires apex-squid project as dependency first you need to install squid project files by using mvn install on squid project folder.
But it seems more like you want to create a multi module maven project, take a look at this question. Create a parent project similar to this project, add check and squid as module and run mvn clean install on parent.
**edit: I just see you already have parent, so make sure parent has your projects as modules, which helps reactive build order and eclipse imports
I am using Tycho and Maven to build an eclipse update site containing several plugins. Everything worked happily when I packaged it as an eclipse-update-site, but I'm getting errors now that I've switched to eclipse-repository.
My projects looks like
com.mycompany.plugin/
src/things.java
pom.xml
com.mycompany.plugin.feature/
feature.xml
pom.xml
com.mycompany.updatesite/
category.xml (formerly site.xml)
pom.xml
This page indicates that the maven packaging "eclipse-update-site" is deprecated in favor of "eclipse-repository". Accordingly, I updated my update site's pom.xml to look like (approximately):
<project>
<tycho.version>0.26.0</tycho.version>
<groupId>mygroup</groupId>
<artifactId>artifactId</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho.version}</version>
</plugin>
</plugins>
</build>
<packaging>eclipse-repository</packaging>
</project>
I also renamed my site.xml file to category.xml as suggested by this post and this post. I did not make any other changes to category.xml (formerly site.xml), so it looks like:
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/com.mycompany.plugin.feature_0.1.0.qualifier.jar" id="com.mycompany.plugin.feature" version="0.1.0.qualifier">
<category name="com.mycompany"/>
</feature>
<category-def name="com.mycompany" label="MyPlugin"/>
</site>
The maven build marches along happily, building all of my plugins and features. When it tries to build the repository, it fails, saying:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-repository-plugin:0.26.0:assemble-repository
(default-assemble-repository) on project com.mycompany.updatesite: Could not assemble p2 repository:
Mirroring failed: No repository found at file:/mypath/com.mycompany.updatesite/target/. -> [Help 1]
Clearly I'm missing something, but I can't figure out what.
Which phases of maven are you running?
I encountered the same problem when switching from eclipse-update-site to eclipse-repository and using just the package phase. However, it worked with install.
Or more specifically instead of
mvn clean package
I used
mvn clean install
I hope this helps you too.
I have parent [project] pom which have the
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.4.0</version>
....
</plugin>
In subproject [childpom], I am getting this error on the first line
<?xml version="1.0" encoding="UTF-8"?>
Incompatible lifecycle mapping plugin version 1.4.0
jump to definition in parent pom.
Further env details:
IDE : Jboss jeveloper studio v9.0.0
JDK : java 8 64 bit.
MAVEN : apache-maven-3.3.3
I am new to maven, pls suggest me where I went wrong?
different eclipse depends different lots of locale jar files. so try use the relation version of the eclipse version.
you can find the version number from the installation folder. they should in features or plugins.
maybe is 1.6.2. you can try!
I am currently trying to set a path that is different from my artifactId of the maven-project. Unfortunately, my attempts do not work.
I tried setting it by
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/AWV</path>
</configuration>
</plugin>
</plugins>
<finalName>AWV</finalName>
</build>
but when calling mvn tomcat7:run-war none of them works (but the war is corretly named AWV.war).
All documentation I could find (http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html, http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/run-war-mojo.html) says I could do this by setting the path this way.
Alternatively, I tried running tomcat with mvn tomcat7:run-war -Dmaven.tomcat.path=/AWV which didn't work either. Additional hints, like executing clean before (Eclipse maven run configuration using 'run' goal from tomcat7 maven plugin doesn't respect default context path) did not work either.
Has anyone an idea how to solve this?
Edit: This also happens when using 2.3-SNAPSHOT of the tomcat-maven-plugin.
After searching for some time, I found out the mistake: in src/main/webapps/META-INF/context.xml there was the text:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/awv-seite"/>
I have no clue how this file got there, probably eclipse or NetBeans created it. This prevented all my other tries from beeing successfull, after setting the path there, everything works.
I am using the maven-jspc-plugin in my pom.xml.
When i try to execute the jsp-compile goal (which executes the plugin) I get:
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.juli.logging.Slf4jLog.<init>(Slf4jLog.java:29)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:54)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:35)
at org.apache.sling.scripting.jsp.jasper.compiler.OriginalTldLocationsCache.<init>(OriginalTldLocationsCache.java:81)
at org.apache.sling.maven.jspc.JspcMojo.initServletContext(JspcMojo.java:426)
I've tried downloading the (open) source for the maven-jspc-plugin and i am able to easily "mvn install" -- I don't get any build issues, however when i use that build in my project pom it still crashes and tells me it can't find LoggerFactory.
I've logged an issue with the Apache Sling project but am not making much headway.
https://issues.apache.org/jira/browse/SLING-2350
This link includes some more troubleshooting info as well as a simple maven project that uses the maven plugin. downloading the jspc-test.zip and "mvn install"ing will result in the error I've mentioned.
Also, i took a peak at the org.apache.juli pom.xml and it doesnt appear to list any dependencies at all.
Any thoughts on how to resolve would be appreciated.
Thanks!
Plugin dependencies are supplied in a different part of the POM:
<project>
<dependencies>
<!-- dependencies defined here don't get included for plugins -->
...
</dependencies>
<build>
<plugins>
<plugin>
.... jspc plugin section ....
<dependencies>
<dependency>
<!-- Try adding slf4j here --->
Though it does sounds like their POM is invalid if it doesn't already specify slf4j.