Using Groovy project together with Java Web project on Tomcat
If you want to use some Groovy script on Tomcat you have to setup Eclipse like this: Assumption: You have a Groovy project with some scripts you want to use in a web application in Tomcat.
- You have a web project (e.g. Vaadin) referencing to a Groovy project. Your Java code where you bind the Groovy code may look like this:
GroovyClassLoader gcl = new GroovyClassLoader(); Class<Script> scriptClass = (Class<Script>) gcl.loadClass("ch.peterfuerholz.vaadin1stproject.GroovyTestclass"); Script script = scriptClass.newInstance(); Binding binding = new Binding(); script.setBinding(binding); script.run();
- Menu 'Run', 'Debug configurations...', select the Tomcat server then the 'Classpath'-tab, 'User Entries.
- 'Add Projects' and add your Groovy project. Then remove the 2 entries 'GROOVY_SUPPORT' and 'GROOVY_DSL_SUPPORT'.
- 'Advanced', 'Add Classpath Variables', 'Configure Variables', 'New', Enter 'Name':"GROOVY_LIB" and 'File': select groovy_all_xyz.jar-library under /opt/eclipse/plugins/org.codehaus.groovy.xyz
- 'Apply', 'Close'
Block Select Mode
See Switch to Block Select Mode.
Just press Alt-Shift-A to switch to/from block-select-mode.
You can run a Web application project on Tomcat by right-clicking on the project and selecting 'Run on server...'.
It can happen that this works the first time but updating can become an issue. Try to fix this in following ways:
- Validate the web project
- Remove project from Tomcat server; go to project and do 'run on server' again.
- Just delete the server (open JEE perspective) and create a new one.
Typically this problem occurs when you add (or remove) additional dependencies in your Web projects (even though you add them to 'Properties', 'Deployment Assembly'): In this case go to 'Run', 'Run Configurations', 'Classpath', 'User entries' and check if entries are missing. More tips:
- Lately worked for me: Clean project (via Project, Clean...), right mouse click, Run on server etc.
- Clean project, publish server, clean temporary files (right-click on the server)
- If you use Ivy:
- Check if 'ivy.xml [default]' appears in web project and the same config is selected under the project settings, Deployment Assembly. If not, select 'Add...', 'Java Build Path Entries'. Remove and reselect.
Working with GitHub
Setting up GitHub-account:
- Register yourself with email etc.
- Register your SSH public key (If you haven't yet any you can create one in Eclipse, see YouTube video above.
Update an existing GitHub project
If you are working with a library hosted on GitHub (or another remote GIT repository) you can go on like this:
- Fork a repository ('Fork'-button!)
- Copy URL to forked GitHub-project, e.g. https://github.com/<username>/morphia.git
- In Eclipse open the GIT perspective and click icon 'Clone a GIT repository...', enter the copied URL, enter your GitHub credentials and clone to e.g. ~/git/morphia. (Additionally I had to enter my password for the local GIT repository.? (PW same as for my computer))
- If repository does not contain Eclipse project files: Open command shell in ~/git/morphia and execute mvn eclipse:eclipse to create them. (See Maven plugin for Eclipse.)
- Open Java Perspective in Eclipse and import existing projects under ~/git/morphia.
- Apply your changes, maybe add a JUnit test.
- Commit your changes to your local repository. (Right click on project, Team, Commit...)
- Push up your local repository to your fork: Open GIT perspective, select your repo, right-click, Push... Click next, then select left combo 'HEAD' and right combo 'master[branch]', click 'Add Spec', 'Next' etc. (Furthermore I had to enter my computer's password.)
- Go to the GitHub project and click 'Pull Request' where you can enter a pull request so that your changes get taken over into the code mainline.
To use GIT you need to know following terms:
- fork repository
- On GitHub it is often the case that you cannot push your changes into the main development code. Therefore you have to fork the code which merely creates a copy of the main development.
- clone repository
- This means you copy a remote repository locally.
- After you have done your changes on the local repository you commit these changes. This means your changes get saved in the local .git directory structure(s). With a commit you reach a reproducible code state but it does not mean that other people can see your changes.
- With a push you can update the remote repository with your commited changes.
- Most often different people work on a remote repository concurrently. By means of a pull you can update your local repository with the latest pushes.
- pull request
- Mainly only used for GitHub: If you pushed your changes into your fork you should create a pull request to notify the library maintainer to pull in your changes into the main code stream.