Access configuration resources in Scala IDE - eclipse

Some of my colleagues use Eclipse 3.7.2 and Scala IDE 2.1 for development. I want to use typesafe's config module for applicaton configuration. I want to use the convention based default configuration location. According to the examples and documentation, the default config can be found at the following path relative to project root
/src/main/resources/application.conf
But when I run my project using Scala IDE's Scala Application loader, the SimpleConfig type is unable to load any configuration values set in this file. An alternative is to pass in a config-file system property via sbt, but I don't want to have to explicitly set this path somewhere. Can anyone point out what I'm doing wrong?
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.foo.dataservices.MyServer.main(MyServer.scala)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'bar'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:115)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:138)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:150)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:155)
at com.typesafe.config.impl.SimpleConfig.getConfigNumber(SimpleConfig.java:170)
at com.typesafe.config.impl.SimpleConfig.getInt(SimpleConfig.java:181)

You need to add your resources folder to your java build path:
Right Click on your project in the Project Explorer
properties -> click Java Build Path -> select "Source" tab
click "Add Folder..." and add your src/main/resources folder
update: if you are using the sbt eclipse plugin you can configure it to automatically add the resources folder to the classpath :
(from: sbteclipse docs)
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

Related

sbt Project name must be valid Scala identifier error while creating new project

I wanted to create a new project in scala in intellij. I have chosen Lightbend Project Starter and then Akka Quickstart Scala. On finish I got this error:
sbt Project name must be valid Scala identifier
The name of my project is "akka-demo" but "akkademo" and default "untitled" don't work either. Empty catalog is created. Same with other templates. How can I overcome this?
Env:
Intellij idea ultimate 18.3.4
sbt 1.2.6
As mentioned, akkademo should indeed work.
It sounds like an IntelliJ problem.
If a project directory was created, you can try to remove the .idea directory and reimport the project.
Furthermore, you can download the Akka Quickstart Scala project from Lightbend's website, and start the sbt shell in this directory.
Try to run and compile to make sure your environment is set up correctly.
If everything works with the sbt shell but not in IntelliJ, then open:
IntelliJ -> Preferences -> Build, Execution, Deployment -> Build Tools -> sbt and check the Use sbt shell for imports and for builds.
Then go to the sbt tab in IntelliJ and refresh.

Error: Could not find or load main class while trying to run spark from eclipse(scala ide 4.3)

i have build the project using sbt and imported into eclipse . while trying to execute from run configuration i cannot find my main class and on running the application its prompted with the following error : could not find the main class.i have installed spark-hadoop version 1.4 and scala version 2.10.6 in the local machine also changed the scala compiler version to 2.10.6 in scala ide . The same error is produced while trying build spark from eclipse using maven . Please advice..
Check if Your main class in on build path.
Project -> Properties -> Java Build Path -> Source tab
If not add appropriate folder(s).
Add the folder where classes are generated to build path -> configure build path -> java build path -> source -> "Default Output Folder" text box.
Check if you have .scala files included in compilation path.
Even if you have the source folder included, it may be possible that .scala files are not being picked up.
The following might help, I was facing the same issue and it solved the problem for me:
build path -> configure build path -> java build path -> source -> add **/*.scala in the Included section.

build paths eclipse java j2ee

I have imported a project (I am very new at this) and I get the following errors:
Project cannot be built until build path errors are resolved
Project FST is missing required library: 'C:program Files/Apache Group/Tomcat 4.1/common/lib/servlet.jar'
Project FST is missing required library: 'C:program Files/Apache Group/Tomcat 4.1/common/lib/struts.jar'
The project cannot be built until build path errors are resolved
Unbound classpath variable: 'TOMCAT_HOME/common/lib/jasper-runtime.jar' in project
Unbound classpath variable: 'TOMCAT_HOME' in project FST
I create a variable called TOMCAT_HOME and give it the proper directory ,but Also, we should change the project classpath to use TOMCAT_HOME rather than the absolute path.
i dont know how to do it (change the project classpath and the absolute path)
thanks !
To answer somewhat indirectly, if you configure your project build with something like Maven or Gradle, so that you can successfully build the project using the corresponding command-line tool, then it should be quite straightforward to import the project into eclipse using the Maven or Gradle eclipse plugin. I think doing so will be worth whatever trouble it causes you in the short run--just take care to make your project structure conform to the usual project structure that Maven expects or you'll be asking for trouble (it should be no problem to do so for greenfield work).

NoClassDefFoundError in Eclipse when adding project in build path

I am receiving an NoClassDefFoundError in Eclipse when I try to run my project.
My Project looks like this:
JavaProject: BulkAdmin
- src
- com.mycompany.bulkadmin.SDK.util
- Login.java
Dynamic Web Project: JSPTesting
- src
- com.mycompany.bulkadmin.jspController
- Controller.java
- WebContent
- index.html
- execute.jsp
This is the control flow:
index.html loads
index.html has a form that redirects to execute.jsp
execute.jsp takes the info returned in the form and makes a static call to Login.java
execute.jsp prints the results of the call
Controller.java uses Login.java. I was receiving compilation errors. To resolve them I did this:
Right click on JSPTesting -> properties
Choose java build path on the left bar
Choose projects tab
Click add
Choose BulkAdmin (Project)
I am not sure why but now when I am getting a NoClassDefFoundError. I have done some googling. I think that this means that I have messed up my classpath somehow but I am not sure how to resolve this.
java.lang.NoClassDefFoundError: com/myCompany/bulkadmin/SDK/util/Login
at com.myCompany.bulkadmin.jspController.Controller.process(Controller.java:44)
at org.apache.jsp.execute_jsp._jspService(execute_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
Other information:
I am using tomcat (in Eclipse) as my server
The exception shows up in the browser and the eclipse console
execute.jsp is a JSP
It seems like there are many similar questions to this on SO. I have read about 15 of them and tried various things however I think that my question has a different solution. I can provide more information.
Rightclick your dynamic web project, go to Properties > Deployment Assembly and add the dependent projects there. This way they will end up as JAR in /WEB-INF/lib, exactly there where you want it to be.
In Eclipse versions older than 3.5 you need to go to Properties > Java EE Module Dependencies.
See also:
ClassNotFoundException when using User Libraries in Eclipse build path
Difference between Deployment Assembly and J2EE Module Dependencies in Eclipse
The NoClassDefFoundError indicates that a class that was available during compilation is no longer available at runtime. Your problem is that the com/myCompany/bulkadmin/cSDK/util/Login class is available in the compilation classpath (in Eclipse via the Project reference you added to the build path) but not in the runtime classpath (Tomcat, which has no idea how to find this class).
You need to add the BulkAdmin project to the web-app class path when deployed on Tomcat as well.
One way to do this would be to export the BulkAdmin project as a JAR and put it into the WEB-INF/lib directory of your JSPTesting project.

How do you ensure a Utility Projects library dependency gets packaged in the final EAR in Eclipse Galileo?

I have a 'Utilty Project', and an 'EAR Project' that includes that 'Utility Project'. All the classes from the 'Utility Project' end up being packaged as a JAR and placed within the 'lib' directory of the exported EAR, for example:
EAR.ear
META-INF
MANIFEST.MF
lib
utility.jar (which expands to):
META-INF
MANIFEST.MF
com
acme
Foo.class
Bar.class
However, the 'Utility Project' relies on a library (freemarker.jar) that has been added to the build path using 'Properties > Java Build Path > Libraries'. All I want to do is to get freemarker.jar added to the EAR as follows:
EAR.ear
META-INF
MANIFEST.MF
lib
**freemarker.jar**
utility.jar (which expands to):
META-INF
MANIFEST.MF
com
acme
Foo.class
Bar.class
By searching around within Eclipse I've found 4 potential avenues for achieving this, none of which have worked. If someone can just cut to the chase and tell me what I should actually do, that would be great. But just in case, I'll iterate them here:
From the 'Utility Project' Properties:
If I click 'Java Build Path > Order and Export' and select 'freemarker.jar' for export, the jar does not end up in the EAR file at all.
If I click 'Java EE Module Dependencies' and select the 'freemarker.jar' library as a dependency, it says:
This JAR is a bundled library of an
EAR project and is supposed to be
packed in the EAR's library directory.
It conflicts with the manifest class
path dependency you are trying to
create. If you create this dependency,
the JAR will be packed in the root
(not library) directory of the EAR.
Are you sure you want to proceed?
From the 'EAR Project' Properties:
If I click 'Java EE Module Dependencies > Add JARs...' and navigate to the 'freemarker.jar', and make it a dependency, it gets added to the root of the EAR:
/freemarker.jar
If I do the same as above, but check the 'In Lib Dir' checkbox, it gets added into the lib folder, but contained within another lib folder:
/lib/lib/freemarker.jar
Thanks.
I've managed to solve this problem. In the Problems window I was getting the following warning:
Classpath entry /utility-project/lib/freemarker.jar will not be exported or published.
Runtime ClassNotFoundExceptions may result.
What I tried, at a whim, was to use the Ctrl-1 key combination I've been using to get quick fix solutions for my source code. It turns out this also provides quick-fix solutions for for the given errors and warnings. I chose the first of the two options:
Mark the associated raw classpath entry as a publish/export dependency.
and my problem disappeared!
Bizarrely, all this seems to have done is to cause the 'freemarker.jar' lib to be selected in the 'Java EE Module Dependencies' properties dialog, which I was doing myself anyway. This may be an Eclispe bug!
#MonoThreaded: After using the quick fix > Mark the associated raw classpath entry as published/export dependency, if you right-click on the project > properties > depolyment assembly you will notice that eclipse has added a new entry, something like source: /freemaker.jar, deploy path: ../lib. You can do that too, by selecting Add > Java Build Path Entry.