Maven project giving error - java

After setting up the project in intellij as a maven project like so ..
I set up my pom.xml file with a basic structure ...
<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>com.yourcompany.test</groupId>
<artifactId>jreddit-testing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jreddit-testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.github.jreddit</groupId>
<artifactId>jreddit</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
when I run sudo mvn clean install it installs everything with no errors.
On running the project I get the Error ..
Error:java: directory not found:
/Users/stingRay/Documents/workspace/jreddit/target/generated-sources/annotations

Not sure if this will solve your issue but the comments have not enough space :)
I would argue the environment variables are simply not properly configured. I recommend not using sudo and maven. It is simply not necessary if everything is configured properly.
The download page of maven contains the instructions what to do: http://maven.apache.org/download.cgi (scrolling down)
In short:
Download the Java Development Kit (I don't use the packet manager from Linux for this, to prevent having root being able to execute Java commands or run servers accidentally). It looks you are working on MacOS? So Download the dmg file from oracle.
Download the Maven archive and extract it (it can also be in a shared dirctory so it is readable for every user on the system)
the important part: setting the environment variables. You must set JAVA_HOME, M2_HOME, optionally MVN_OPTS and the PATH for convenience - so "mvn" runs in your terminal without sudo.
There are tutorials on the web that guide you through this, like this one: http://bitbybitblog.com/environment-variables-mac/
If you work with IntelliJ or the terminal the .bash_profile file be enough. Editing the .plist file is for OSX internal tools only. In IntelliJ it will work once the M2_HOME variable is set (if I remember correctly) and IntelliJ is restarted.
Note you may need to clean up the files already around (to make sure your user can write them without sudo). Meaning:
/Users/stingRay/Documents/workspace/jreddit/target/
/Users/stingRay/.m2/repository (or where your local maven repo is located)
Hope that will work :)

Related

How to exclude locally installed dependency from remote sonar scan

My POM looks like this -->
<dependency>
<groupId>com.abc.xyz</groupId>
<artifactId>xyz</artifactId>
<version>1.0</version>
</dependency>
I have installed abc.xyz jar locally inside .m2 and is not available on mvn artifactory.
When I try to scan my code using sonar scanner installed on remote server, it tries to download abc-xyz.jar from maven artifactory & fails.
How do I make my remote sonar happy?
I tried giving scope as system but I see that it is deprecated.
Tried following
<scope>system</scope>
<systemPath>${project.basedir}/path/to/abc-xyz.jar</systemPath>
You can use sonar.exclusions in your pom.xml to exclude your jar-directory :
<properties>
<sonar.exclusions>${project.basedir}/path/to/abc-xyz.jar</sonar.exclusions>
<properties>
You might also try to define the property <sonar.skip>true</sonar.skip> in the pom.xml of the module you want to exclude.
Or try advanced reactor options like so: mvn sonar:sonar -pl !${project.basedir}/path/to/abc-xyz.jar.

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module

new user here!
I know there's similar questions with answers to this, but I don't know how to apply them to my case, so sorry if it's repetitive!
So... I'm trying to make my first bot for Telegram and I've decided to use Java. I'm following this tutorial and copypasted the code from the two example classes (EchoBot and Main). The only thing I changed is the token with the token I got from the BotGodfather on Telegram.
I'm using Eclipse on Ubuntu 18.04.1 as IDE so I started by making a Java project and then configured it as a Maven project. This is the code of my pom.xml:
`
<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>EchoBot</groupId>
<artifactId>EchoBot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>EchoBot</name>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
`
When I run the program I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module
at org.telegram.telegrambots.ApiContext.getInjector(ApiContext.java:46)
at org.telegram.telegrambots.ApiContext.getInstance(ApiContext.java:25)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.(TelegramLongPollingBot.java:17)
at pearlbot.EchoBot.(EchoBot.java:8)
at pearlbot.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
What could the problem be?
Keep in mind that I don't even know what Maven is, so if it's something related to it, you'll need to explain what's wrong as if you were talking to a child! ^^''
I got this error when i try to install testng for eclipse Version: 2019-12 (4.14.0) and run the program then i got this error. Finally i got fixed -
Eclipse IDE for Java Developers, Version: 2019-12 (4.14.0), Build id: 20191212-1212.
TestNG 7.1.0.r202001120626
Removing the TestNG library from the build path of the project containing the test and installing TestNG from menu Help / Install New Software did not work for me, I kept getting this error.
What worked for me was downloading guice-4.2.2.jar (from https://github.com/google/guice/wiki/Guice422), copying it into any folder, and adding it to the build path of the project as external JAR.
From Eclipse, Go to Help > Install software or You can install from market place as well (Help > Market Place). After installing TestNG from market place, it dint work, but installing the GUICE422.jar to the build path worked for me
So make sure after installing TestNG from market place, install the Guice422 Jar file as well link to install testng from eclipse market place
This worked for me --- Hope it helps

Seems that methods of maven repository can not be called from end-product

I am setting up a Craftbukkit Server with the editor IntelliJ and the programming language Java. For that I use firebase-admin. I want use it trough maven and everything works. But when I build the .jar and then let it run it returns following error in the console:
java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
at raycroud.mckaff_server_manager.ServerManager.onEnable(ServerManager.java:26) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:254) ~[craftbukkit-1.13.2.jar:git-Bukkit-a4c555b]
I am sitting at this problem for many days and tried many different solutions, but nothing worked.
Here you can see my project structure:
And here my Artifacts Settings under File->Project Structure->Artifacts:
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<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>company.lol_server_manager</groupId>
<artifactId>server_manager</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.6.0</version>
</dependency>
</dependencies>
</project>
Actual the Craftbukkit plugin gets disabled but I normally I expect that he works and I don't know why he can find methods or other elements from maven libraries.
There could be several reasons.It would help if you provide your run/debug configuration.You could try the following:
Activate [Include in project build].
Let me know if it helps.

Maven failed to execute goal (Could not resolve dependencies)

I haven't worked with Java in many years as I primarily work with PHP (Using Composer for dependency management). I've only just started looking at Maven and Gradle too.
I'm trying to have a play around using Maven and wanted to use Eclipse's JDT UI tools so I could have a go at a test project building a user interface using some of their components, just to try and bring myself up to speed.
I'm using Maven to try and bring in the JDT UI package as a dependency. This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.jonathon</groupId>
<artifactId>ui-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.12.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.ui</artifactId>
<version>3.12.2</version>
</dependency>
</dependencies>
</project>
I'm using IntelliJ IDEA as my IDE and it seems to be complaining in a tooltip about not being able to resolve dependencies. I tried running mvn compile to see if I could get a better error message and I got this:
[ERROR] Failed to execute goal on project ui+test: Could not resolve dependencies for project com.jonathon:ui-test:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.eclipse.jdt:org.eclipse.jdt.ui:jar:3.12.2 -> org.eclipse.platform:org.eclipse.search:jar:3.11.1 -> org.eclipse.platform:org.eclipse.ui:jar:3.108.1 -> org.eclipse.platform:org.eclipse.swt:jar:3.105.2 -> org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar:[3.105.2,3.105.2]: No versions available for org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar:[3.105.2,3.105.2] within specified range -> [Help 1]
Am I doing something wrong? I got the artifactId, groupId and version from here.
This library is the problem org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar it doesn't exist at all.
gtk.linux.aarch64 this part is resolved from your setup or java/system
propably you need to set osgi.platform=gtk.linux.x86_64 in your mvn pom or env .

by using maven Build projects and deploy it using jboss-maven-plugin

I have 2 (core, core-web) projects such a way that one is depending on another.
so the core-web's POM.xml contains the dependency of core.
core-web will be deployed on jBoss AS (5.1). Therefore want to use jboss-maven-plugin
I have to run install on both core and core-web after every change and have to deploy the file manually. Everything is seems to be working fine if I put the war file to the deploy.
Just want to ask that if there is a way that I can make a routine in core-web's POM that it automatically generates core.jar and core-web.war and deploy it to the running jboss server on localhost:8080 port.
Please let me know if there is more information you require.
Thanks in advance.
I think I have found the issue. I made another pom.xml and and added core and core-web in the module tag and now I have to install this new pom and it installs all the dependent poms in a sequential way.
<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>
<artifactId>build-all</artifactId>
<packaging>pom</packaging>
<name>build-all</name>
<parent>
.......
</parent>
<modules>
<module>..</module>
<module>../core</module>
<module>../model</module>
<module>../cas-server</module>
<module>../core-web</module>
<module>../other-projects</module>
</modules>
</project>

Categories

Resources