Make eclipse copy groovy spring files rather than compile into class files - java

I am writing my first Spring application with Spring 4 groovy configuration. I am using Eclipse IDE. As usual I have all my Java files (actual domain/services etc.) in src/main/java and all my Spring Groovy configs in src/config/groovy.
Both are added as source to the classpath in Eclipse. As a result Eclipse compiles my groovy files into .class files and copies into target folder. But the problem is I am trying to load my Spring groovy classes from classpath as below, but it doesn't work as JVM can't find .groovy files as Eclipse compiled them into .class files.
def ctx = new GenericGroovyApplicationContext()
ctx.load("classpath:spring/SpringConfig.groovy")
Is there any way to force Eclipse not to compile my Spring groovy files but copy them to the output folder like xml files? For a test application I can probably use the file system path like "file:..." but I don't think I want to use it in PROD, so I am trying to write something that works both in IDE and PROD. Any suggestions? Thanks.

Ok, I should have looked around a bit hard! Resolved it myself.
In Eclipse, Go to Window->Preferences->Groovy->Compiler
Just check the option "Enable script folder support" and the pattern to cover the path where your groovy scripts are, then eclipse just copies them to the output folder like any other scripts.

Related

Configure VS Code to use .jar files when doing live syntax checking

How do I configure VS Code to use the .jar files in my lib directory when doing live syntax checking? I can compile and run my code without any problems using the "Debug" menu in VS Code; but the editor is marking every reference to JUnit classes/methods as a syntax error.
I have a very simple standalone Java "project": One source file, one JUnit source file, and a lib directory containing the JUnit and Hamcrest .jar files. As suggested by this document: https://code.visualstudio.com/docs/java/java-project, simply placing the .jar files in a lib directory should be sufficient. It is when it comes to compiling and running the code; but, my editor is full of red squiggly lines.
Update: I tried refreshing the workspace cache, and now it won't even compile and run. Am I misunderstanding the directions; or, so I have a setting messed up somewhere?

Create Java projects without eclipse?

Is there any way I can create Java projects using a simple text editor? Not an IDE like eclipse?
I want to be able to create .jar files without the assistance of an IDE, I have all the JDK commands installed already on my computer (such as javac)
I'd like to know what file structure I need, how I need to arrange my class files, what compilation steps I need to go through etc. to be able to create jar files.
Yes, completely doable (just not much fun once the project gets bigger).
I suggest if it's not a throwaway project, use a build tool like Maven or Gradle to manage your build process, so that you don't need to assemble classpaths and resources yourself, but still retain full control of the build and test lifecycle, without IDEs. This comes at a complexity cost, of course, but once it's set up life becomes easier.
See also How can I create an executable JAR with dependencies using Maven? or the Gradle docs about creating JARs
I'd highly recommend the standard Maven source directory layout too (src/main, src/test etc) as it's both commonplace and makes for easy integration with the above tools.
Follow the below steps to create a jar file
Compile the java source using javac
Create a manifest file (if main exists) to identify main class
Use the below command to create a jar file
jar -cvfm *.class
Yeah. You can create your project structure without an IDE. But it's time consuming and you have to do everything.
To talk about creating JAR, you don't want any extra software. You can use jar utility, which comes with JDK.
Here are steps to create jar:
Compile classes which you want to in jar
Create manifest file (.mf). It's needed if you want to make jar as executable. If you want to bundle classes only together, then no need. (eg. Dependency jar)
Go to command prompt and execute following command "jar cvf MyJarName.jar *.class". Make sure java is set in environment path and you're inside the directory of classes.
cvf means "create a jar; show verbose output; specify the output jar file name.
That's all. If you want to include any folders inside jar then you can use folder name in above command after classes and it must be separated by space.
Example: jar cvf TicTacToe.jar TicTacToe.class audio images

Eclipse Classpath with Play Framework

I'm trying to run a small Play application (well, the tests really) in Eclipse and I've come up against a frustrating problem. When I run the command from the command line all the tests are successful, but from Eclipse I've found that it is unable to load some of our required properties files. Looking at the target directory I see two compiled class folders, classes and classes_managed. The properties files are in the classes directory, as I'd expect, but when I look to the class that's attempting to load the properties file the classpath appears to only have the classes_managed directory, which doesn't contain the properties files that are required.
For reference I am running these as JUnit tests so that I can debug them. I've run play eclipse on the command line and imported the project to Eclipse as suggested in the documentation. I'm using Eclipse Kepler and Play 2.2.3.
Any help would be appreciated.
If those files are not getting added to the classpath properly, you can ensure they're accessible by specifically telling sbt that they need to be on the classpath with:
unmanagedClasspath in Test <+= baseDirectory map { bd => Attributed.blank(bd / "conf") }
put this line somewhere in your build.sbt file

Maven "breaks" Groovy files

I'm working on a groovy project that runs as java application in Eclipse.
Normally there are normal class files under the groovy files, but when I make a clean install of the project with maven, it deletes those java classes, so i can't run it in eclipse anymore.
Why is that so? I have another project that has the same structure without this problem.
Greetings
edit:
I made a screenshot to clear what I mean.
The PDFConverter is how I want/know it the other is what I get and can't run in Eclipse anymore
I would look at your_project/target/classes/ directory, that's where Maven puts .class files.
Although it's not entirely clear what are you asking about.

Where is the debug class path in netbeans / where does the spring config XML file go?

I have a java desktop app (main project) and another project with a series of packages in NetBeans. Some of the packages use spring for JDBC and IOC.
I am getting the following error when running in debug:
Caused by: java.io.FileNotFoundException: class path resource [config.xml] cannot be opened because it does not exist
Where is the config file supposed to go? Where exactly is the class path? Is it in dist, build, in the root of the project that calls spring, or the main project (the desktop app)?
confused ..
Your classpath is defined when you run your app using the java command. You can specify it using:
java -cp $path my.Main
where $path is your classpath. It is a :-separated (; on windows) list of JAR files and/or directories containing compiled .class files.
If you run your program like:
java -cp configdir my.Main
And put your spring config in configdir (the fully-qualified path) then that should be discovered.
NetBeans: whilst I'm not a netbeans user, it probably offers a number of ways for you to complete the task you want:
In your run configuration (i.e. where you define what class is being run, what the command-line parameters are etc), you will probably be able to add items to the classpath. These might be directories or individual files
In your compiler settings, you can probably tell NetBeans to automatically copy files of a certain type (like properties files, XML config files) from your source locations to where NetBeans puts your class files.
If you put your config.xml file in the directory where NetBeans is compiling your .class files to
Put it in the root folder of you application
if you created your application in a folder called Spring then you should put your file in that folder
Disregard the answer by oxbow_lakes. NetBeans modifies CLASSPATH, so what it is outside the IDE is no measure of what it is inside the IDE.

Categories

Resources