Maven: package does not exist - java

I was developing an application like ordinary Java Web application, but because I want to deploy it to Heroku, I needed it to become Maven project, so I created an empty Maven project with Eclipse and copied all of libraries I was using and all of my source code.
When I do mvn compile on my local machine, it goes well, but app isn't really working.
When I do git push heroku master I get error like
package com.mysite.java.classes does not exist
Locally I have maven-compiler-plugin ver 3.1 and source and target set to 1.7, although I'm using 1.8 jdk. I changed it to 1.7 since I saw here Pushing my repository to heroku fails that it has issues with Heroku.
Here is a project structure
I'm not really experienced with Maven, so I hope somebody can help. I guess imports aren't working as intended because I get whole list of errors like this
symbol: class Connection
location: class com.vukstankovic.professionalorientation.Personalities
[ERROR] /tmp/build_0bc5a80c-dc14-4126-b15b-69390f18dc9f/src/main/java/com/vukstankovic/professionalorientation/Personalities.java:[48,19] cannot find symbol
Class Connection in this example is mysql class from com.mysql.jdbc.Connection

Related

Eclipse module problems jdk 10

I'm having a new problem this morning with my project (it worked fine on Friday). Eclipse seems to be having trouble figuring out it's module / class path, and nothing I'm trying seems to affect it. I'm using the following Eclipse configuration:
Version: 2019-03 M1 (4.11.0 M1)
Build id: 20190117-2133
Oracle JDK 10.0.2
My project is a Java Maven multi-module (those are maven modules, not java modules) project, but does not define any java modules itself (we haven't converted it yet). When attempting to compile it, eclipse throws up its hands and sends the message
"The package java.sql is accessible from more than one module: <unnamed>, java.sql".
While, on the surface, this seems helpful, I cannot find another module that defines the java.sql package, and the only instance of a class from the package (e.g.: java.sql.ResultSet) exists within the JDK system supplied library. This also happens with the javax.xml package with the same error.
I've attempted closing and re-opening eclipse, performing a clean, and a maven update project for everything, to no avail. I've inspected the eclipse .log file, and there's nothing useful in there. Is there anyway to figure out what other module Eclipse thinks it's pulling that package from?
My next step is to delete the entire project and re-import it.
UPDATE: I think I may have found the offender... there's a dependency that declares a couple of classes into the java.sql package, and that's probably borking things up. The specific JAR is net.sourceforge.hatbox:hatbox:1.0.b8, and is a transitive dependency of the com.h2database:h2:1.4.197 jar. Is there any way to tell eclipse to ignore the package from that JAR?
Update 2: Build Path:
I'm not sure I count this as a true solution, but I was able to find a workaround to my problem. I downgraded eclipse from the installed version listed in the question (4.11.0) to the base photon install (4.8.0), and I can now compile and work again.

JUnit and other dependencies not recognized by CI build

Background:
So my team is using Microsoft's git services and we've set up some CI tests. We are not using Maven, and the project is connected to the remote server through the Eclipse Microsoft Team services plugin, but I try to interact with the remote repo mostly through the command line.
Current Strategy:
I'm not too familiar with how to deal with dependencies on a remote repo for Java projects but I've tried simply pushing the .jar dependencies in our build path with the rest of the source code (I know they're big and there's probably a better way to do this).
Problem:
When I push the .jar files, the CI tests still fail with the following errors:
src\JBLASTests.java(1):src\JBLASTests.java(1,): error : [javac] d:\a\1\s\
src\JBLASTests.java:1: error: package org.junit does not exist
src\JBLASTests.java(5):src\JBLASTests.java(5,): error : [javac] d:\a\1\s\
src\JBLASTests.java:5: error: package org.jblas does not exist
And then more error reports related to the missing symbols due to the packages not being found.
Questions:
1) What else needs to be on the repo to make the build work?
2) Is there a better way, besides Maven, to link the libraries to the repo?
(I'm not averse to using Maven I just want to find a simpler solution for the interim).
Apologies if this is a duplicate. I searched but couldn't find any other posts regarding this situation.
It looks like the dev who set up the CI tests set them up with an Ant build task despite that not being how we currently handle dependencies. Thank you howgler for pointing out that the CI might be building differently than I do locally. I'll post this answer in case anyone else runs into this issue and doesn't think to check the CI build settings (and also update the title appropriately).
Lesson
Make sure that the CI build task is the same as how you're building locally. Until you add dependencies and try to push them, your builds might be succeeding, so it can be misleading that your CI settings are incorrect.

How do I get IntelliJ to recognise resource bundle when compiling?

Ok, first up I am almost completely unfamiliar with Java and Java tooling.
I am attempting to contribute a bugfix to a Jenkins plugin. Code-wise the fix is simple, my problem is in trying to compile the project and run the tests locally.
I have installed IntelliJ IDEA 15CE and started a new project, pointing it to my local clone of the plugin repo.
It has gone away and 'downloaded the internet' in terms of Maven dependencies. Mostly everything looks ok. What I want to do is to run the tests...
If I right-click at the root of the project and select 'Run All Tests' I get the error:
Error:(115, 29) java: cannot find symbol
symbol: variable Messages
location: class hudson.plugins.copyartifact.BuildSelector
The source of this error is a line:
console.println(Messages.CopyArtifact_MissingSrcArtifacts(srcDir));
https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/java/hudson/plugins/copyartifact/BuildSelector.java#L115
As far as I can tell the Messages symbol should resolve to this properties file:
https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/resources/hudson/plugins/copyartifact/Messages.properties
...which IDEA recognises as a 'Resource Bundle' in the project tree view.
But it doesn't seem to recognise it when compiling the project.
I have no idea where to start fixing this. The tests run fine if I push a commit to a pull request on GitHub and let the cloudbees.com Jenkins server run them, but I'd like to be able to test stuff locally first.
Run the maven compile command from Intelli-J Maven tool. After compiling error will vanish.
When you compile it will generate a Messages.java file in generated sources automatically.

Building IntelliJ project in TeamCity

I'm new to IntelliJ and Java but I have a fair bit of TeamCity experience, mostly building .Net projects.
I have created a very simple Android Library project in IntelliJ with basically a single class that uses RxJava (Reactive Extensions for Java). I have added the Rx library in IntelliJ using Project Structure -> Libraries -> From Maven. The actual library I have added is com.netflix.rxjava:rxjava-android:0.19.6 which pulls in com.netflix.rxjava:rxjava-core:0.19.6.
This works brilliantly and my project compiles within IntelliJ without even having to install Maven. Nice job, JetBrains.
However, when I try to build the project in TeamCity using the IntelliJ-IDEA runner, the project doesn't compile. Bad JetBrains!
I get errors on all the references to rx.*, which as I said all worked perfectly on my workstation. The errors from TeamCity look like this:
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:3: package rx does not exist
import rx.Observable;
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:4: package rx.subjects does not exist
import rx.subjects.BehaviorSubject;
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:18: cannot find symbol
symbol: class BehaviorSubject
location: class com.example.TigraAndroidUtilities.ObservableModel
private BehaviorSubject modelStream;
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:63: cannot find symbol
symbol: class Observable
location: class com.example.TigraAndroidUtilities.ObservableModel
public Observable toObservable()
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:28: cannot find symbol
symbol: variable BehaviorSubject
location: class com.example.TigraAndroidUtilities.ObservableModel
modelStream = BehaviorSubject.create(modelData);
^
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:65: cannot find symbol
symbol: variable Observable
location: class com.example.TigraAndroidUtilities.ObservableModel
if (completed) { return Observable.empty(); }
^
Here's what I've tried:
Considered using the Maven build runner instead; but the project doesn't have a POM file so it's not a Maven build.
I've tried installing Maven on the build agent, that doesn't seem to make any difference and I didn't need to install it for IntelliJ to work locally so I can't see why it would be needed.
There is a path macro called MAVEN_REPOSITORY in the IntelliJ build runner settings and I've tried setting that to various different values, no luck.
I've looked at JetBrains' documentation for the IntelliJ runner and as far as I can tell, I've configured my build step correctly. Clearly I'm missing something though.
This is all a bit frustrating, I've been tinkering with it hours but nothing seems to work and basically I have no clue what I'm doing wrong. I must have missed something somewhere. How can I get this build working properly in TeamCity?
As of TeamCity 9.1, its IDEA runner can't build Maven modules any longer, nor can it auto-download external artifacts from Maven Central.
Basically, what you need is:
Download external artifacts, one by one, using TeamCity Maven runner and maven-dependency-plugin, as described in this answer., e. g.:
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get com.netflix.rxjava:rxjava-android:0.19.6
You'll need as many Maven build steps as the number of dependencies in your IDEA project, and these steps must precede the IDEA runner build step.
At the build configuration level, set the system.path.macro.MAVEN.REPOSITORY system property to %env.HOME%/.m2/repository.
That's it.
Happy building!

springframework source in Idea Intellij

I'm having hard time to setup springframework code in Intellij.
I git-cloned springframework project from github, and ran ant task to get all the libraries into ivy-cache directory.
I found "spring-framework.ipr" file for intellij project, and opened it.
Unfortunately, some of the libraries are not correctly mapped to the jar files or missing. So I cannot compile the codebase in IDE.
I also tried importing as eclipse project into intellij. Jar file reference seems ok.
But there are compilation errors in OXM module. Some test classes have reference to auto generated classes such as "~.samples.flight.FlightDocument", "~.jaxb.test.FlightType", and they don't exist(ant test goal generates them in target dir).
It seems same problem happens in STS.
I referenced this blog post:
http://blog.springsource.org/2009/03/03/building-spring-3/
Any good idea to setup spring code in intellij?
I use intellij v11.
git branch: 3.1.x
git commit: e8fc90ce3e4554f14eaa86ce05591249d3fe62fa
Compilation error example:
.../org.springframework.oxm/src/test/java/org/springframework/oxm/xmlbeans/XmlBeansMarshaller Tests.java
Error:(29,42) package org.springframework.samples.flight does not exist
Error:(30,42) package org.springframework.samples.flight does not exist
Error:(44,9) cannot find symbol class FlightsDocument
Error:(44,58) package FlightsDocument does not exist
....
Thanks,
problem solved.
"spring-framework.ipr" is the one for intellij.
lesson learned:
simply wrong version of junit was referenced in spring-framework.ipr file.
when ant build failed middle of the test, subsequent module won't be built. so, required libraries won't be downloaded into ivy-cache/repository.
"ant jar" goal will not download test related libraries since the goal doesn't run tests
After all the tests passed and manually fixed junit reference, intellij finally has no errors.

Categories