IntelliJ can't find custom library [Maven] - java

When i was writing my first "real" java project (a todo app in console), I realised i use a lot of methods that could be easily made into my very own library (simple Maven project). I added the root folder to my main procejt with File>Project Structure>Modules>Dependencies>Java and selected the root folder - Toolbox. But when i type
import org.toolbox.Tools.*;
it is all good and the usages are fine but it fails to compile.
First the error message:
Error:(5, 19) java: package org.toolbox does not exist
Error:(6, 25) java: package org.toolbox.Tools does not exist
Error:(10, 69) java: package Tools does not exist
Error:(13, 9) java: cannot find symbol
symbol: class Tools
location: class org.todo.ToDo
Error:(13, 27) java: cannot find symbol
symbol: class Tools
location: class org.todo.ToDo
Error:(16, 9) java: cannot find symbol
symbol: class STATE
location: class org.todo.ToDo
Error:(18, 23) java: cannot find symbol
symbol: variable STATE
location: class org.todo.ToDo
Now a screenshot of my dependencies
IntelliJ Idea Ultimate 2019.3.1
JDK 11.0.1
Manjaro Linux
Any help would be greatly appreciated
As requested, the pom.xml of todo:
<?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>org.todo</groupId>
<artifactId>TO-DO</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
and the pom.xml of my library:
<?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>org.toolbox</groupId>
<artifactId>Toolbox</artifactId>
<version>1.0-SNAPSHOT</version>
// because i was getting an error with maven compiler defaulting to 1.5
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
</project>

Make the library project too a maven project (with it's own group, artifact id and version).
Than add to the dependancy of other maven projects.
(This would wourk both inside and outside the IDE)
Once you start with maven, keep going with maven, try to add dependancies :
You must install the dependancy with maven (either from command line or from the IDE) running 'mvn clean install' (this is basic for packaging system like maven).
<?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>org.todo</groupId>
<artifactId>TO-DO</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- try to add dependancies -->
<dependencies>
<dependency>
<groupId>org.toolbox</groupId>
<artifactId>Toolbox</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>

Related

Unexpected element "{http://maven.apache.org/POM/4.0.0}project" {antlib:org.apache.tools.ant}project

This is the first time I have tried to make a minecraft plugin, and I get this error:
I am not a programmer, so can some one say why I had this error when I go in build.xml?
Eclipse version : 4.20.0
build.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>test.plugin.test</groupId>
<artifactId>test</artifactId>
<version>1.0-Complete</version>
<packaging>jar</packaging>
<name>main test</name>
<description>test</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</project>
The error message suggests that the software reading the file is expecting Ant stuff but found something else, which it could not interpret. Indeed build.xml is a typical name for a build file used by Ant, but the contents shown appear to be meant to be saved as a pom.xml file to be used by Maven. A good first step might be to correct the filename; perhaps then the program would read it in the right frame of mind.

Maven project compile error: cannot find symbol (which is java.lang.String)

It's a very simple web scraping program that I built in intellij idea with the maven build system. It worked fine before today but when I tried to build it today it gave me object not found errors for base java objects like String and List. When I tried to reload the maven project I got another error below. Idea also highlights the basic java object in red and gives no advice. The only thing I did was slightly modify the java source code. So, I tested with the stock hello world code. It did compile and run, but Intellij still highlights String and System in red and the maven reload produces the same error. Help is greatly appreciated as I need to get some data for a research project.
Error with web scraping source code compilation error
Error:(24, 13) java: cannot find symbol
symbol: class List
location: class Main
Maven reload error
Cannot resolve plugin org.apache.maven.plugins:maven-compiler-plugin:${maven.compiler.version}
This is the 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>org.example</groupId>
<artifactId>htmlunittest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Update:
After resolving the maven errors, since you are facing IDE related problems, I would suggest you to do this:
Go to File > Project Structure
Add the JDK in Project SDK (If it is not there, under Platform Settings > SDKs, you need to add the JDK)
Also ensure that maven home is set correctly in Preferences > build tools > maven:
Then do a maven rebuild from the side panel:
You have forgot to define the property ${maven.compiler.version} in your POM.
Define a properties section in your POM like this:
<properties>
<java.version>1.11</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
</properties>

"Could not find or load main class" when running a jar file from a msf4j project

I'm working on a Java project which uses the msf4j library. In IntelliJ IDEA I'm able to run the project, everything works as expected. However, If I build a jar file from this project (aplying the first part of this answer), the jar file cannot run (using java -jar my_jar.jar). It says:
Error: Could not find or load main class Main
I've cleaned the project several times, restarted everything, even tried to use older versions of the msf4j, nothing has helped.
If I replace the msf4j with something else (e.g. javalin), the built jar file is runnable, the problem goes away.
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>my.group.id</groupId>
<artifactId>my_artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-core</artifactId>
<version>2.5.2</version>
</dependency>
</dependencies>
<properties>
<microservice.mainClass>src.main.java.Main</microservice.mainClass>
</properties>
</project>
MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: Main
I think the problem is somewhere in the msf4j artifacts. Any idea how to fix this problem?
from the top of my head I thing you need to set in maven a project parent and remove the dependency.
<parent>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-service</artifactId>
<version>2.5.2</version>
</parent>
HTH,
Gal

"gs" scheme missing from installed FileSystemProviders

I want to read a file from Google Cloud Storage using NIO as described in the SDK Javadoc and the package README. I think I'm missing something about triggering the installation of a new FileSystemProvider in the Maven configuration.
I created a simple-as-possible project to demonstrate. The highlights follow.
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>gcs-nio</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<name>playground</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-nio -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-nio</artifactId>
<version>0.22.0-alpha</version>
</dependency>
</dependencies>
</project>
App.java:
public class App {
public static void main(String[] args) {
System.out.println("FileSystemProvider schemes:");
List<FileSystemProvider> fileSystemProviders = FileSystemProvider.installedProviders();
for (FileSystemProvider provider : fileSystemProviders) {
System.out.println(provider.getScheme());
}
// This fails; I want it to succeed.
Paths.get(URI.create("gs://dataflow-samples/shakespeare/kinglear.txt"));
}
}
Output:
$ mvn compile -q exec:java -Dexec.mainClass=com.example.App
FileSystemProvider schemes:
file
jar
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project gcs-nio: An exception occured while executing the Java class. Provider "gs" not installed -> [Help 1]

Unresolveable error occured in org.mule.tools.maven

I am getting the following Error in Maven
Project build error: Unresolveable build extension: Plugin org.mule.tools.maven:mule-app-maven-plugin:1.1 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:
1.5.0 at specified path C:\Program Files\Java\jre7/../lib/tools.jar
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jaggedpeak</groupId>
<artifactId>amazon-integration</artifactId>
<version>1.0.0</version>
<packaging>mule</packaging>
<name>Mule amazon-integration Application</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8
</project.reporting.outputEncoding>
<mule.version>3.7.0</mule.version>
<mule.tools.version>1.1</mule.tools.version>
<munit.version>1.1.0</munit.version>
<mule.munit.support.version>3.7.1</mule.munit.support.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-app-maven-plugin</artifactId>
<version>${mule.tools.version}</version>
<extensions>true</extensions>
<configuration>
<copyToAppsDirectory>true</copyToAppsDirectory>
<inclusions>
<inclusion>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-extensions-support</artifactId>
</inclusion>
<inclusion>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-extensions-spring-support</artifactId>
</inclusion>
</inclusions>
</configuration>
</plugin>
<plugins>
</build>
Note:
The following are my findings ,My build is pointing to JDK,There is no restriction in downloading.
point your project to jdk instead of jre.

Categories

Resources