How to compile mixed (Java and Groovy) project? - java

I have a project (Java Swing application), in which I want to mix Java and Groovy.
I can compile and run the project without problems inside IntelliJ Idea.
But I can't compile it with Maven:
In src/main/groovy I define a Groovy class GroovyClass.
In src/main/java there is a Java class, which uses GroovyClass.
When compiling the project with Maven, I get the message [ERROR] ...\JavaClass.java:[13,47] error: cannot find symbol.
How can I change the pom.xml file in order to be able to compile and package the application using Maven?

Add the groovy-eclipse compiler maven plugin to your pom.xml
Instructions are on the plugins page at https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin

Related

Is there any other way to create a JRE without using Jlink?

I'm getting following issues with Jlink -
Error: automatic module cannot be used with jlink
Error: Modules aws.java.sdk.s3 and aws.java.sdk.core export package com.amazonaws.auth to module listenablefuture
I have tried creating a module-info.java with jdeps or using plugins like moditect to generate module-info for the module and inject it in existing JAR. Didn't work.
Is there any other way to create a JRE that includes automatic modules.

Maven dependencies are downloaded but not recognized inside project

I want to build a project which has some external libraries. I included pom.xml file inside intellij and it downloaded all of required dependencies files from maven and put them as external libraries, but my project doesn't recognize them and gives compilation error. IDE screen attached below.
this is one of the compilation errors that I get:
Error:(29, 33) java: package com.google.common.collect does not exist
here is the my external libraries which I think are added correctly.
I don't have maven installed but I think IntelliJ handles it by it self.
Have you tried running mvn clean compile either using Intellij or command line ?

Tell intelliJ to compile module with scalac in a java project?

I have a java project in intelliJ and I've added a few modules, one of which has scala code in it.
I want to tell intelliJ to compile this module with scalac not javac, but I can't figure out where to configure it, and when I try to compile it gives me this error, "Cannot create instance of scalac"
Per https://intellij-support.jetbrains.com/hc/en-us/community/posts/206001829-Project-configuration-explained:
A module that requires compiling with Scalac should have a Scala facet attached.
And further down (what I think you want):
To add Scala support to existing module:
Right-click the module in Project View, choose "Add Framework Support..."
Check "Scala" in technologies list (unavailable if module has Scala facet attached)
Provide a path to Scala installation (if not detected)

Not able to get directory structure and Maven dependencies

I have checked out a Maven project from Subversion. It has Java with Spring framework and Groovy.
We are using Groovy Eclipse compiler plugin. On Maven install, code compiles perfectly with Groovy Eclipse compiler and a jar is created in target.
But there is no directory structure which is usually created in Maven. No classpath too.
I tried many things nothing worked. Finally I converted project to faceted form and then src/java was created as it was faceted to Java project. Still no Maven dependencies.
As there was no Maven dependencies, many jars were missing, so I added jars to build path manually. I also added src/groovy to build path and then it was not able to compile Groovy classes, so I configured project as Groovy project and DDSL was generated. Now after so many manual settings, it is not working fine when it has to create object using spring for Maven class.
I tried a project without Spring framework, and it worked fine.
For pom.xml: I have referred: http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html.

Compiling Groovy Code in my Java EE application

My web project includes Groovy class files.
How should I compile it for my project using Eclipse?
Rest of my team is using IntelliIDEA to use it but I want to set it up in Eclipse.
To start with I have installed a Groovy Plug-In for my Eclipse and installed Groovy on my Windows.
You should be able to right click on the project -> Configure -> Convert to Groovy project.
If your project is a maven project, then you should also install m2eclipse as well as the optional m2eclipse configurator for groovy-eclipse. This will automatically configure your project for Eclipse and groovy.
Hope this links helps you. It has step by step on how to import your existing Groovy Project into eclipse so you can work on it.
http://docs.codehaus.org/display/GROOVY/Create+Your+First+Groovy+Project
If the project is created using grails create project, I believe all of the .project and .setting files are there for eclipse.
If you have the groovy eclipse plugin installed you should be able to mix your groovy classes into the same packages as your java code. Are you using maven or ant to build your actual war file? If not you will have to make sure that you compile the groovy classes along with the java code. while in eclipse you will be fine. Both ant and maven have facilities for compiling the groovy and java code together for your actual war that you deploy.

Categories

Resources