I'm really a beginner with ant, anyway I'm working with a java project built with ant.
There're, simplifying, two projects imported in Eclipse:
The project1 contains the class1 with the methods1, methods2 and methods3.
In project2 there's a class2 that call the class1.method3().
The ivy.xml on project2 contains:
<dependencies>
<dependency org="my.package"
name="project1"
rev="latest.${project.version.status}"
conf="default">
<exclude module="servlet-api"/>
</dependency>
</dependencies>
The issue is:
The method method3() is undefined for the type class1
(line 53 class2.java)
I've tried several combinations, my "favourite" is:
With terminal in project1 folder:
ant clean-lib lib
ant publish-local
And in project2 folder:
ant clean-lib lib
Refresh, clean and build all projects in Eclipse
But it doesn't works, so... how can I update the project1.jar referred by project2? What am I doing wrong?
Thanks
The subtleties of latest.[version] are lost on me, but if you're always going to be picking the newest, then you might as well do latest.integration.
(Also according to here, it looks like what you were doing is syntactically correct, so maybe project.version.status wasn't a proper value)
Related
I am trying to modify WEKA source code.
I tried the link on modify weka source code in netbeans but is no longer working. I am trying to run the WEKA java source code in Intellij and I get 100 errors (literally) coming from the weka, like
Error:(23, 44) java: package com.googlecode.jfilechooserbookmarks does not exist
Error:(28, 1) java: package no.uib.cipr.matrix does not exist
and it goes on.
I tried to import it as a Maven project because of the pom.xml dependencies. It compiles and builds without any problem, but when I try to run a Java class, ex. Main.java, it gives all the errors above.
My project structure is:
Project
-scr
--main
---java (Source Folder)
----Main.java
-weka-src
--src
---main
----java (Source Folder)
------weka
Does anyone have an idea of how it can compile without errors?
Thank you in advance!
Thanks Jens for the comment!
Indeed, there were some dependencies I needed to add to pom.xml. Now it's working. This is what I added:
<dependency>
<groupId>com.googlecode.jfilechooser-bookmarks</groupId>
<artifactId>jfilechooser-bookmarks</artifactId>
<version>0.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.vbmacher/java-cup-runtime -->
<dependency>
<groupId>com.github.vbmacher</groupId>
<artifactId>java-cup-runtime</artifactId>
<version>11b</version>
</dependency>
I am trying to understand what I am doing wrong with junit-tests in Maven with eclipse. Mainly I have been just following this "getting started guide" for Maven:
https://spring.io/guides/gs/maven/
But for me it is not completely working like that when it comes to junit.
To follow the exact folder-structure from the example I have named my packages under src in eclipse:
main.java.hello
test.java.hello
My test class GreeterTest.java is in the package test.java.hello and has this content:
package test.java.hello;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;
import org.junit.Test;
import main.java.hello.Greeter;
public class GreeterTest {
private Greeter greeter = new Greeter();
#Test
public void greeterSaysHello() {
assertThat(greeter.sayHello(), containsString("Hello"));
}
}
In my pom.xml you find the dependency:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
Unfortunately eclipse sais "the import org.junit cannot be resolved."
If change the scope of the dependency from test to compile I do not get this error message, but that would be not the way how the scope is intended to be used, is it?
What do I need to change that also eclipse understands, that this class is a test-class and therefore all dependencies are actually available?
Best,Nils
The issue appears to be related to where Eclipse thinks your source tree starts. You have put your code in src/main/java/hello and src/main/test/hello but Eclipse thinks the source tree starts at src. So it thinks the other folders are packages and has given your classes package names like main.java.hello.Greeter.
The quickest way to fix this is to run on the command line:
mvn eclipse:eclipse
which uses maven to fix your eclipse projects. It will automatically set the source root to be the correct values. When it completes, right click on the project and select Refresh to see the updated project.
To fix this manually, you can right click on the project and choose Build Path > Configure Build Path and, in the Source tab on the right, ensure that the entire src/main/java (right up to java!) is included as the source folder. Do this by clicking Add Folder and selecting java in the tree under src - main. Do the same for src/main/test. Usually maven projects include src/main/resources as a source folder too.
I got some weird issue regarding class generation in Maven.
Somehow some of my class is not generated by Maven.
I got an abstract class "A" -> Generated
I got another abstract class "B" extends "A" -> Not generated
I got another class extends "B" -> Not generated
Is it possible because there is no usage then maven not creating the class?
How to make maven create the class in build?
Anyone know the reason of this? I already tried using mvn package and mvn install.
Note : There is no exclusion for the class in my pom
Class files are generated from all Java files in src/main/java. If some of the Java Files are not compiled,
the Java files are not in src/main/java.
or the source directory was changed.
or there is some weird configuration in the pom.
Okay found the issue... caused by my stupid mistake of not putting the packages name correctly in includes section of my pom.
I keep checking excludes section instead of includes section. But this is good info for me since I just know if I have includes section and I didn't put it in there then mvn won't build it, but mvn will build it if I used the class somewhere.
Thank you for the help that make me keep checking the pom.
I'm creating a pom.xml for a project that is a library.
Is <main.class> POM XML element under <properties> required for this?
(the library has a small test Main.java which I didn't really intend to include in the library JAR file in the first place, so I'd rather not use that test file as main.class unless required).
Is “main.class” XML element required in Maven's pom.xml if the artefact is a library?
No.
At the most basic level, maven creates jars from projects of a certain structure, it does not care if you have a main class or not. Using mvn clean install:
This command tells Maven to build all the modules, and to install it in the local repository. The local repository is created in your home directory (or alternative location that you created it)... (which other projects can declare as a dependency)
The only time maven cares about having a main class, is when you want to make the jar executable
What do you mean by "main.class"? A class Main? No, it's not required.
If you meant a method main, an entrypoint to execution like below, it's not required either. Unless you want to execute the code directly.
public static void main(String[] args) {
}
For some reason my Intellij IDEA IDE started highlighting the use of anything from outside the local class as an error. It only does it for items in the packages I wrote - for example, packages like java.* do not show as errors. Even the joda-time dependency has no error highlights, it's just from my own packages. The problem only started occuring after I wrote a pom.xml for the project, so I'm assuming it has something to do with maven.
For example, the main of the following line is red with the error cannot resolve symbol 'main':
import main.java.com.jamobox.jamchatserver.clients.ClientReader;
Then in instances where a class is given as a parameter, e.g.
public void doSomething(Client c) { .. }
and I put something like
doSomething(new Client());
It will highlight the value in the parameters in red saying
doSomething(Client) cannot be applied to doSomething(main.java.com.jamobox.jamchatserver.clients.Client)
As I said the code compiles and runs absolutely fine, its just the IDE that thinks something is wrong. I have tried pretty much all of the answers given in this similar question, but nothing seems to have worked.
Anyone have any ideas on how to fix this?
In case it helps anyone figure this out, here is my current 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>com.jamobox.jamchatserver</groupId>
<artifactId>JamChatServer</artifactId>
<name>JamChat Server</name>
<version>0.2.1</version>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
<type>jar</type>
<optional>false</optional>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When you say "it compiles fine", you do not indicate how you are compiling? Based on what you are describing, and what I suspect the issue is, I'm assuming you are compiling via maven.
It appears as if there is some mismatch in the declared source directory and the package names. When you create a (bare-bones) java project through IDEA, it makes the source directory {project.basedir}/src. Notice in the project view, the src directory is blue indicating it is a main (i.e. production) source directory:
This is also shown in the project structure dialog:
For a maven project, the default main (i.e.production) source directory is java in the path {project.basedir}/src/main/java. There is then a corresponding test source directory {project.basedir}/src/test/java. IDEA marks test source directories as green folders. Finally, there are both main and test resources directories that are used for things like configuration files, images, etc. In IDEA 12.x resources directories were marked as source and test-source directories with the same color as the corresponding java directory. In IDEA 13 (currently in beta and to be released in December) they are marked as distinct resource directories.
It sounds like when you converted to maven, the main\java directory was added to the src directory and the com root package directory was moved to java, but when this happened, the package declarations where changed from com.jamobox... to main.java.com.janbobox.... This likely happened because when you made the move, src was still configured as the source directory. So IDEA saw the package name change from com.jamobox... to main.java.com.janbobox... and change import statements (and likely package statements) to match.
To fix, you need to do the following:
Force import the maven pom using the "Reimport All Maven Projects" button in the Maven tool window (on the right side by default)
If the POM is not yet showing, click the add button , navigate to the pom.xml file and add it. Then run the reimport.
Verify the java directory (and not the src directory) is marked as the project source as shown in the above screenshot (showing both IDEA 12.x and 13.x project trees)
If the proper directories are not marked, try a reimport 2 or 3 more times. If that does not fix it (it should), go into File > Project Structure > [Modules] > [Sources Tab] and manually configure the proper sources. Remove any extraneous ones.
Verify that the com root package directory is in src\main\java and not src
Search and replace any package main.java.com strings with package com
Search and replace any import main.java.com strings with import com
That should fix the issues. If there is still red, run File > Invalidate Caches and restart IDEA. If after that there are still issues, please edit your original question and add screenshots of your project tree and the File > Project Structure > [Modules] > [Sources Tab] dialog window.