Add scala capabilities into an existing EJB eclipse project - java

I have an existing EJB project set up in Eclipse Helios, and would like to slowly introduce Scala into the project. The Scala IDE has been installed successfully, and I'm able to create standalone scala project. The issue however comes when trying to use my existing project with scala additions. I've went as far as manually editing the .project, .classpath, and related files under .settings of the project's home directory for eclipse.
However I still have the issue where the Java compiler tries to compiles .scala classes, which results in errors and ultimately not being able to build the project.
Has anyone faced a similar scenario or are there any workarounds?
Thanks in advance.

You should be able to right-click the project, go to "Scala" and click on "add scala nature". Then .scala files should be recognized as such. You might also have to add the scala library to your dependencies. Depending on whether this is a "simple" Eclipse project or you're using Maven there might be other steps required.

Right click on project, and choose Configure/Add Scala Nature.

Related

After importing from a git in eclipse I get the error "source folder is not java project"

I know other people have had this problem, but I can't get it to work.
I imported a project from a git and I get an error saying "Project is not a Java project" when adding a class and it doesn't show up in the run config. Project here if it is something wrong with the project and not eclipse. I've heard answers to this with project facet and maven, but I don't have either.
I am running the latest version of eclipse and clean installed it today
The error should be "“Source folder is not a Java project”".
Check the content of your .project and .classpath.
You can modify the .project to add the org.eclipse.jdt.core.javanature manually.
(But adding the java facet should be the recommended way)
regarding the lack of Java facet, make sure your Eclipse has the right Java version support, as described here.
a .project and .classpath can be manually generated or copied from another simple Java Eclispe project.

Converting an Eclipse Java project into an SVN project?

So I am trying to do something slightly unusual.
I checked out a project using Tortoise SVN, and then I imported that project into Eclipse as a Java project, and I can build the project fine.
But I would much rather use Eclipse's Subversion plugin than Tortoise SVN to check in files, update, compare diff's etc.
So is there any way I hook that Java project back into SVN in Eclipse, and then be able to check in files etc through Eclipse.
Note that checking out the project again using Eclipse is not an option for a few different reasons.
Thanks.
Right click on the Project and select 'Team > Share Project...' to set up SVN on the project.

Problem loading resources while running in Eclipse

I'm working on a swing project, using maven2 (from command-line) and eclipse (without maven integration). So, I generate the eclipse project through maven eclipse plugin (mvn eclipse:eclipse), import it inside eclipse, and do all my work.
My problem is: when I run my app in eclipse (as a Java Application), I can't find none of the resources that are in my src directory. Digging for information on my problem, I get into this answer from another question. So, I compared the output from the following instructions:
MyClass.class.getResource("/").getPath();
MyClass.class.getProtectionDomain().getCodeSource().getLocation().toString();
Those gave me the following outputs, respectively:
${workspace_loc}/${my_project}/target/test-classes/
file:/${workspace_loc}/${my_project}/target/classes/
Checking the above locations, I could see that the former is empty, while the other one contained all my compiled classes and resources. So, I came to the conclusion that the classloader is looking for my resources in the wrong place. So, I think I have three questions:
Is my understanding correct?
If so, how it does to find the classes it is loading?
How do I solve this?
UPDATE: I've changed my code, so instead of invoking MyClass.class.getResource(...) or MyClass.class.getResourceAsStream(...), I'm now using ClassLoader.getSystemResource(...) and ClassLoader.getSystemResourceAsStream(...). In this way, everything is working fine in eclipse. I just don't know exactly why. Any hint on this?
Two possibles cases for me :
You are using eclipse to compile your project. Then eclipse is configured to exclude (or not include) resources in the src folder. You can set it in Project/Properties/Java Build Path/Source. Then you expend your src folder, and ensure you have something like "Included All", "Excluded None".
You run your maven application using maven to compile and not eclipse, even though you are using eclipse as your IDE. Then by default maven will not copy resources from the source folder to the output folder... Because it is not the standard maven way of doing things. Thus the resource are missing from the classpath and you don't find them. Just change your maven configuration to also include resources from your source folder.
I think you have to add src/main/resources to the build path. This is done in Project Properties > Build Path > Source. Here is how the standard maven project looks:
In future when using Eclipse I suggest to use m2eclipse plugin and create project using it. This will automatically make sure that all these folders are in the build path.
Try this:
Run configurations... -> Classpath -> User Entries -> Advanced... -> Add Folders
Can you try loading the resources using below?
this.getClass().getClassLoader().getResourceAsStream(propertyFileName)
This might be useful information
Eclipse Maven plugin has its own Classpath Container that conflicts with generated class paths when enabled.
What I would suggest is stop using eclipse:eclipse (sorry - harsh I know). I used it for about 8 months, cant believe it took me that long, and used M2Eclipse. M2Eclipse is an eclipse plugin in which you do the following.
Enable Dependency Management.
Update Project Configuration
(In Eclipse) Project -> Build Project
(In Eclipse) Run Application
It may not seem it, but its a much easier and less frustrating way of doing it.
Before, with eclipse:eclipse. You would have to run it then hit refresh and hope that everything is configured - if you have a multi-module pom things can really go wrong.
For me the Files within the WEB-INF were not getting included. Hence I added them to Buildpath (Project -> Build Path -> Configure Build Path -> Add folder (project/src/main/webapp). This resolved the issue.

can eclipse plugin project depend on java project

I have an eclipse plugin project which dependes on java project in my eclipse. usually what I did is export the project as jar and use it as-is in the plugin. but this requires manual work. can I have a reference from my plugin projct to a java project that will be both compile-time and run-time dependency ?
I saw a similar question, but not exactly the same.
I think, the closest thing to this is to create a jar file from the referenced project, and import it to the projects repository. But thats quite hard to manage for a currently developed project.
On the other hand, isn't it possible to simply convert the Java project into a plug-in permanently? If the other user does not use OSGi/Eclipse, he/she will see only a manifest/manifest.mf file (and possibly a plugin.xml) next to the java project specific stuff, so this would not disturb them, but would help you.

Introducing scala into existing netbeans java project

I have an existing java project in Netbeans. I would like to start coding parts of it in Scala. I can add ".scala" files to the project but apparently they aren't compiled.
Can I somehow modify the existing Netbeans project settings in order to build java and scala sources together or do I need to create a new project and import the existing (java) sources?
Thanks
Martin
EDIT Sorry, I forgot to mention: I've installed the Scala-Plugin for netbeans, so compiling scala code is feasible.
I can create a new (Scala) project and add both scala and java sources to it and it compiles perfectly. My question was if (and how) it's possible to migrate an existing "java-only" project towards such a "mixed" project.
I don't think this is possible in the way you want it. You could however write an Ant build-script and let Netbeans execute it when building you application.
Otherwise I suggest to just create a new scala project and import it as *.jar library into your Java application. This keeps your project clean and nicely modularized.
You will need to migrate to use something like Maven to do this for you, as Netbeans doesn't know how to compile Scala code. Maven can be configured to compile the .scala files first then the .java, resulting in your final compiled source.
Have a look here for the maven config.
I would recommend doing a new maven project, Project form Archetype, and use the following.
http://mvnrepository.com/artifact/org.scala-tools.archetypes/scala-archetype-simple/1.3
This basically auto imports you a project all set up to get started running scala in a Java project.

Categories

Resources