error: package javax.servlet.annotation does not exist in Visual Studio Code - servlets

I am writing a java servlet in Visual Studio Code and I get the error: package javax.servlet.annotation does not exist. How can I fix it?
I have added the path of annotations-api.jar in the enviromental variables.

First: try to
(1) Copy annotations api. jar to src/main/webapp/WEB INF/lib
(2) Configure annotations api.jar into pom.xml
Or
WebServlet was added in servlet api version 3.0, so please ensure that you are using an updated version and have added it to the project's classpath.
Check servlet-api-2.5 classes, which should does not include WebServlet.class. It is part of servlet-api-3.x classes

Related

java.lang.module.FindException: Module test not foundIntellidea

I am have this Exception please help me!
"Error occurred during initialization of boot layer
java.lang.module.Find Exception: Module test not found"
But i write VM option "--module-path "D:\UT java\javafx-sdk-17.0.1\lib" --add-modules javafx.controls,javafx.fxml"
and i have module-info.java "
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.sql;
requires java.desktop;
requires jdk.jfr;"
i add my sdk. And if i create javafx demo project and execute him it work. and if i start change fxml file and change controller i have this exception.
I have IntellIJIdea 2021, javafx-sdk-17.0.1, jdbc jr 8,11,16
Steps to fix:
Delete the JavaFX sdk (you don’t need it).
Delete old Java versions (they are obsolete).
Update your IntelliJ IDE and IDE plugins to the most recent release, 2021.3.2+.
Create a new JavaFX project using JDK and JavaFX 17.0.2+.
Select Maven for the build system unless you know and prefer Gradle.
Do not set VM arguments, you don’t need them.
Adding modules via the --add-modules VM arguments is unnecessary when you have a valid module-info.java file.
The --module-path is still required so that the modules can be found, but Idea will provide the correct path for your modules automatically when it recognizes the modules through your Maven dependencies.
So you don't need to explicitly define the --module-path VM argument yourself for a Maven based build (that would be difficult to do anyway because the modules are all downloaded to different directories in your local maven repository).
Test it works following the Idea create new JavaFX project execution instructions.
Add additional modules one at a time by adding their maven dependency to pom.xml and the requires clause to module-info.java.
Ensure you synchronize the Maven and Idea projects between each
addition.
See, for example, this question on correctly adding the javafx.media module.
Adding other modules such as javafx.web, javafx.fxml or javafx.swing follows a similar pattern.
Test between each addition by building and running the project, to ensure you haven’t broken anything.
Copy your original source code into the appropriate package directories under the new project source directory:
src/main/java
Place resources in:
src/main/resources
following the Eden resource location guide.
Fix any errors, ensure everything compiles and runs, then test it.

.net core 2.1 can't reference automapper in startup.cs

In my nugent panel, I installed
AutoMapper v7.0.1
AutoMapper.extensions.microsoft.dependencyinjection v5.0.1
In my Startup.cs,
I added
Services.AddAutoMapper();
but the compiler gives
Severity Code Description Project File Line Suppression State
Error CS1061 'IServiceCollection' does not contain a definition for 'AddAutoMapper' and no accessible extension method 'AddAutoMapper' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) OPEApiService J:\Projects\OPEApiService\OPEApiService\Startup.cs 58 Active
I tried clean, rebuild, close and reopen VS.
Any help is appreciated.
Thanks
This could be a compatibility issue between the two packages.
If you have both the AutoMapper and AutoMapper.extensions.microsoft.dependencyinjection packages installed, remove them and add only the AutoMapper.extensions.microsoft.dependencyinjection. It has a dependency on the AutoMapper package.
I had this same issue and was able to resolve it.
You missed the restore step. From the root directory where the solution file exists, run following command:
dotnet clean
dotnet restore
dotnet build
Build error I received after including the services.AddAutoMapper();
Then after executing the series of command, got it running.
You need to add a reference to :
$ AutoMapper.Extensions.Microsoft.DependencyInjection
Search it using NuGet Packages Manager and install it.

opendaylight: using external jar file

I am developing an application on opendaylight Carbon (based on Karaf). I need to use a library (specifically dnsjava) in my bundle. How do I go about including this?
I tried the following which did not work:
In my features/pom.xml, I included a mvn dependency for my jar file.
In my features/src/main/features/features.xml, I added a bundle:
<bundle>wrap:mvn:dnsjava/dnsjava/${dnsjava.version}</bundle>
However, I still have an error when I go to start my feature:
Error executing command: Error executing command on bundles:
Unable to execute command on bundle 278: The bundle "gov.nist.sdnmud.impl_0.1.0.SNAPSHOT [278]" could not be resolved. Reason: Missing Constraint: Import-Package: org.xbill.DNS; version="[2.1.0,3.0.0)"
Thanks for any help.
I'm not an expert, but if the artifact doesn't have OSGi properties in the jar, which is likely why you've added the "wrap" prefix, then you have to manually set the required OSGi properties on the features.xml dependency line, in an odd microformat syntax.
In our environment, we have to do something like this:
wrap:mvn:<group>/<artifact>/<version>$Bundle-SymbolicName=<bundlename>&Bundle-Version=<version>
This issue doesn't have anything to do with opendaylight.

Robolectric 2.x - dependent jars are downloading while running the tests

How will I download all the robolectric dependent jars, to avoid runtime downloading and make it offline? I need to use Robolectric.buildActivity(), which is part of 2.x.x versions.
any idea on this ?
Starting with Robolectric 2.4 they added two system properties to allow you to tell the Robolectric test runner to use local copies of the dependencies. See the Configuring Robolectric page.
The settings are:
robolectric.offline - Set to true to disable runtime fetching of jars
robolectric.dependency.dir - When in offline mode, specifies a folder containing runtime dependencies
One way to figure out which files you need to copy to the dependencyDir, is to run gradlew testDebug -i (or maybe with -d) and watch the output to see which jars are being downloaded at runtime. Then copy them to a known location on your build machine. (Another way to see which files you need, is to look at SdkConfig.java and get the dependency jars mentioned there along with their dependencies.)
For the current Robolectric 3.0-rc2, these are the files it needs:
accessibility-test-framework-1.0.jar
android-all-5.0.0_r2-robolectric-1.jar
icu4j-53.1.jar
json-20080701.jar
robolectric-annotations-3.0-rc2.jar
robolectric-resources-3.0-rc2.jar
robolectric-utils-3.0-rc2.jar
shadows-core-3.0-rc2.jar
sqlite4java-0.282.jar
tagsoup-1.2.jar
vtd-xml-2.11.jar
Copy these files to a known location, like say /home/jenkins/robolectric-files/, and then edit your build.gradle with something like this:
afterEvaluate {
project.tasks.withType(Test) {
systemProperties.put('robolectric.offline', 'true')
systemProperties.put('robolectric.dependency.dir', '/home/jenkins/robolectric-files/')
}
}
Here is how I solved it for org.robolectric:robolectric:3.0
https://gist.github.com/kotucz/60ae91767dc71ab7b444
I downloads the runtime dependencies into the build folder and configures the tests to use it - see setting the system properties.
I had this issue too, and found the cause to be the org.robolectric.Testrunner creating a org.robolectric.MavenCentral object, which declares a Maven repository using an Internet-url (Robolectric 2.3-release). Offline builds will not be able to access that url.
In my case I'm required to use a Maven repository proxy, so I replaced the url pointing to http://oss.sonatype.org with my local Maven repository proxy. That meant subclassing RobolectricTestRunner to org.robolectric.MyRobolectricTestRunner, and creating a custom MavenCentral object for it to use, and overriding the methods where RobolectricTestRunner references its private MAVEN_CENTRAL object.
The source code for RobolectricTestRunner and MavenCentral are available on Robolectric's Github page.
I used Robolectric version 3.0, and the dependency jars were downloaded from my repository, instead of sonatype.

Why am I getting Could not load file or assembly error on a System.Configuration DLL when using framework 4.0?

Immediately after we upgraded to visual studio 2010 and the 4.0 framework our trunk build started breaking with the Could not load file or assembly error.
We determined that a 3.5 project couldn't reference a 4.0 project else we'd get this error because, as the error states, This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
We've since resolved this and the trunk has been building fine.
I recently did a branch and tag, however, and suddenly this error has resurfaced when I try to build the branch; except the error is regarding one of our own .net 4.0 project's reference to System.Configuration DLL.
Towps.Namespace.MyService.csproj in Core.Dev\Towps\Projetcs\Application\MyService:
RG0000: Could not load referenced assembly
"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll". Caught a BadImageFormatException saying "Could not load file or assembly 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.". in ResGen(0, 0)
I tried setting the specific version property on that system.Configuration DLL ref to true. I can see in it's properties that the runtime version is v4.0.30319 and the Version is 4.0.0.0. The path to the DLL ref is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll which to me looks fine.
The target framework for the csproj file that CrusieControl is using MSBuild to try to build is targeting framework 4.0. Again seems fine.
It builds in the IDE for both trunk & branch. Cruise Control build it in the trunk. The branch build fails when CrusieControl tries to build.
Any ideas what could be happening?
It could be an MSBuild mismatch but I've scanned the config files and msbuild proj files that CruiseControl is using and there are no references to older MSBuilds; which makes sense since all those were updated to get the trunk working.
The branch was simply a copy of the trunk so I'm having difficulty determining what could be the difference!
It turns out that after I branched, all the .proj files in my branch build directory that cc.net uses were back to using ToolVerison="3.5".
I thought I committed all the ToolsVersion="4.0" proj and config changes to the trunk from which I made the branch; evidentially not.
The difference could easily be hint paths no longer lining up on the new branch. However there's not a log to go on in your description. What are the command line options you are passing? In ccnet.config and also any others that may get in if ccnet.config is pointing at a build script that calls msbuild instead of directly to a .sln or .csproj file.
Turn on /v:d for the msbuild on BOTH and then compare the reference resolutions (or build order, etc..) for that assembly or other ones involved/near it.
Also are you providing the path to msbuild on both?
msbuild4="C:\WINNT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
<msbuild>
<executable>$(msbuild4)</executable>
in your ccnet.config?
I've seen it report the 2.0 build executable during a msbuild4 /tv:3.5:
<Message Text="MSBuildToolsPath:$(MSBuildToolsPath)" />
<Message Text="MSBuildToolsVersion:$(MSBuildToolsVersion)" />
MSBuildToolsPath:C:\WINNT\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion:2.0
so that didn't seem very useful.
I'd like to see the config blocks for both branch and trunk.
I know I had some paths in the buildscript that failed in my branch because there was a hardcoded path that would not be valid for the branch. I had to adjust the ccnet.config to pass in arguments for those items to override for the branch.
Please check .net framework version supported by your client. For example sharepoint2010 will not support dll built by 4.0 or higher .net framework. It will support only 3.5 or below.
A bit late I know, but if anybody else has this issue, try adding the RuntimeVersion into your .dna file if it does not already exist.
<DnaLibrary Name="PROJECTNAME" RuntimeVersion="v4.0">

Resources