Hot questions for Using Ubuntu in maven

Question:

I'm trying to run my .jar in Ubuntu, and it's failing every time with a ClassNotFoundException. I thought that my problem was with my Jar file, but after digging into it some more I am thinking that the problem is with my Maven implementation. When I run Maven it builds successfully, however there are errors in my code. I've run this same code using the same method on several different computers, and this has never happened. Maven always throws an error when appropriate, so the fact that it's allowing it to successfully build after there are clear errors makes me think that this might be the cause of my .jar problems.

I was looking in my target folder and I noticed that I'm missing the "classes", "maven-status" and "generated-sources" folders that are usually in there. My CLASSPATH variable is set to

"/media/client-script/java-consumer-client" 

which should allow Maven to find my classes, since in the pom.xml it has the line

<start-class>com.java.consumer.client.Application</start-class>

which is the package for my main class. I'm not sure why but it seems like Maven is unable to find the classes in order to run.

Here's a screenshot of my file structure.

Does anyone have any idea why maven would not be looking in the right place for my classes? Is there an error with my Classpath setup?

Here's my pom.xml file for reference:

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.java.consumer</groupId>
    <artifactId>java-consumer-client</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Consumer Client</name>
    <description>Sample Client for pulling streams from the Consumer Service API.</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.1.RELEASE</version>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.version}</version>
                <!--
                <configuration>
                    <jvmArguments>
                        -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
                    </jvmArguments>
                </configuration>
                    -->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.websocket</groupId>
            <artifactId>javax.websocket-api</artifactId>
            <scope>compile</scope>
            <version>1.1</version>
        </dependency>
        <dependency>
             <groupId>org.glassfish.tyrus</groupId>
             <artifactId>tyrus-client</artifactId>
             <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.tyrus</groupId>
            <artifactId>tyrus-container-grizzly-client</artifactId>
            <version>1.9</version>
        </dependency>
    </dependencies>

    <properties>
        <start-class>com.java.consumer.client.Application</start-class>
         <spring.boot.version>1.2.1.RELEASE</spring.boot.version>
        <spring.boot.websocket.version>1.2.1.RELEASE</spring.boot.websocket.version>        
    </properties>

</project>

Answer:

By default, you must store your java classes in src/main/java folder. Not in src/com/java folder.

Question:

I'm trying to build a new virtual machine with R and the follow packages below running as a R server to my calculations.

    #this is how I install my R-packages
    function install_packages(){
        folder='dir.create(Sys.getenv("R_LIBS_USER"), showWarnings = FALSE, recursive = TRUE)'
        packages='install.packages(c("Rserve","fArma","fGarch","tseries","MASS","lattice","gtools","gmodels","gplots","HiddenMarkov", "xts", "PerformanceAnalytics"), Sys.getenv("R_LIBS_USER"), repos = "http://cran.rstudio.com")'

        echo "$folder" >> ./install_packages.R
        echo "$packages" >> ./install_packages.R

        sudo /usr/bin/R CMD BATCH install_packages.R
        rm -f ./install_packages.R
    }

If I make a call (using mvn clean package) from my host machine to this new virtual machine, it gives me a strange error in my calculations:

Running com.company.documentengine.statistics.JensensAlphaTest
Oct 28, 2015 2:17:45 PM com.company.documentengine.toolbox.util.DatabaseConnection connectToDB
INFO: PostgreSQL JDBC Driver Registered
Oct 28, 2015 2:17:45 PM com.company.documentengine.toolbox.util.DatabaseConnection connectToDB
INFO: test Database connection confirmed for user postgres
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 17.971 sec <<< FAILURE! - in com.company.documentengine.statistics.JensensAlphaTest
testCalculate(com.company.documentengine.statistics.JensensAlphaTest)  Time elapsed: 8.821 sec  <<< FAILURE!
java.lang.AssertionError: Calculation wrong. expected:<0.039801296645998546> but was:<NaN>
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.failNotEquals(Assert.java:834)
    at org.junit.Assert.assertEquals(Assert.java:553)
    at com.company.documentengine.statistics.JensensAlphaTest.testCalculate(JensensAlphaTest.java:40)

Now, if I make the same call but from new virtual machine to my host machine (which also has all these packages installed), everything works.

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.company.documentengine.statistics.JensensAlphaTest
Oct 28, 2015 1:23:13 PM com.company.documentengine.toolbox.util.DatabaseConnection connectToDB
INFO: PostgreSQL JDBC Driver Registered
Oct 28, 2015 1:23:13 PM com.company.documentengine.toolbox.util.DatabaseConnection connectToDB
INFO: test Database connection confirmed for user postgres
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 17.465 sec - in com.company.documentengine.statistics.JensensAlphaTest

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.423s
[INFO] Finished at: Wed Oct 28 13:23:20 UTC 2015
[INFO] Final Memory: 18M/362M
[INFO] ------------------------------------------------------------------------

I'm really confuse about this, can anyone please give me some suggestion/idea, please!

EDIT

I tried to debug my test to see where I'm making the mistake, but still no clue. Now I know at least that my problem is with ... look my debug comparison please. And this is the comparison to all my packages used in both cases.

Java Code

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestContext.class})
@ActiveProfiles(profiles = {"test"})
public class JensensAlphaTest {

    @Autowired
    private TestSeriesManager testSeriesManager;

    @Test
    public void testCalculate() throws Exception {
        PriceSeries<PriceSeriesDatum> dax = testSeriesManager.getDax();
        PriceSeries<PriceSeriesDatum> sDax = testSeriesManager.getSDax();
        InterestRateSeries<InterestRateDatum> euribor = testSeriesManager.getEuribor();

        LocalDate asOfDate = LocalDate.of(2014, 10, 1);
        JensensAlpha jensensAlpha = new JensensAlpha(dax, sDax, euribor, asOfDate);

        double eps = 1e-15;
        /* here is the inconsistent part */
        double actualValue = jensensAlpha.calculate(Period.SINCE_INCEPTION, ReturnsType.DAILY_DISCRETE);
        double expectedValue = 0.039801296645998546;
        assertEquals("Calculation wrong.", expectedValue, actualValue, eps);
    }

}

This is the method called:

public double calculate(Period period, ReturnsType returnsType) {

NavigableMap<LocalDate, Double> returnSeries = returnsType.getReturnSeries(series);
NavigableMap<LocalDate, Double> returnBenchmark = returnsType.getReturnSeries(benchmark);
NavigableMap<LocalDate, Double> returnRiskFree = returnsType.getReturnSeries(riskFree);

LocalDate startDate = period.getStartDate(returnSeries);

NavigableMap<LocalDate, Double> cutReturnSeries = StatisticsUtils.getMapSince(startDate, returnSeries);

NavigableMap<LocalDate, Double> cutBenchmarkReturnSeries;
NavigableMap<LocalDate, Double> cutRiskFreeReturnSeries;
try {
    cutBenchmarkReturnSeries = StatisticsUtils.getMapSince(startDate, returnBenchmark);
    cutRiskFreeReturnSeries = StatisticsUtils.getMapSince(startDate, returnRiskFree);
} catch (IllegalArgumentException e) {
    throw new NotEnoughDataException(
            "This error can occur when the price series is short (only a few returns), so the benchmark is not"
                    + " updated for the taken first date of the series.", e);
}

REXPS4[] inputClasses =
        {RexpParser.createREXPS4Class(cutReturnSeries), RexpParser.createREXPS4Class(cutBenchmarkReturnSeries),
                RexpParser.createREXPS4Class(cutRiskFreeReturnSeries)};
RScript script = RScript.fromFileName("JensensAlpha.R");
REXPS4 resultClass = script.execute(inputClasses);

try {
    return resultClass.getAttribute("value").asDouble();
} catch (REXPMismatchException e) {
    throw new RScriptException("Exception while getting results from the R script.", e);
}

}

And the execute method:

@Override
    public REXPS4 execute(REXPS4[] inputClasses) {

        RConnection c = RConnectionSingleton.INSTANCE.getRConnection();

        try {

            int inputClassNumber = 1;
            for (REXPS4 inputClass : inputClasses) {

                c.assign("inputClass" + inputClassNumber, inputClass);
                inputClassNumber++;

            }

            c.eval(code);
            /* the resultClass is wrong only when I connect to my vm */ 
            return (REXPS4) c.get("resultClass", null, true);

        } catch (REngineException e) {
            throw new ScriptExecutionException("Exception while trying to execute the RScript.", e);
        }

    }

Answer:

Just to let you know what happened with my issue. The problem was the TIMEZONE. I don't know exactly why, but R or some of the packages that we use for our calculations requires the timezone to be the same.

I'm located in Germany (timezone CET which is +1 UTC) and I was setting my virtual machine to use UTC and thus the problem. Oh man, I'm really glad to solve this issue (3 days straight working on this!) but now everything is fine! A huge thank you to my colleague @Ralf for the tip!

Other issue related:1, 2, 3. I hope this helps someone! :)

Question:

Error is

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /172.17.1.XX:9160 (com.datastax.driver.core.TransportException: [/172.17.1.XX:9160] Cannot connect))
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:80)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1145)
    at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:313)
    at com.example.cassandra.Client.connect(Client.java:18)
    at com.example.cassandra.Client.main(Client.java:74)

Version of datastax is dse 4.5.2

Line where error occurs is connect(node)

   cluster = Cluster.builder().addContactPoint(node).withPort(9160).build();
   Metadata metadata = cluster.getMetadata(); //Error at this line

Call to the function is

     public static void main(String a[])
     {
       System.out.println("I am in");
       Client client = new Client();
       client.connect("172.17.1.XX");
       client.close();
     }

pom.xml is

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.cassandra</groupId>
<artifactId>simple-client</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>

<dependencies>
  <dependency>
   <groupId>com.datastax.cassandra</groupId>
   <artifactId>cassandra-driver-core</artifactId>
   <version>2.1.0</version>
  </dependency>
<dependency>
  <groupId>org.apache-extras.cassandra-jdbc</groupId>
  <artifactId>cassandra-jdbc</artifactId>
  <version>1.2.5</version>
  </dependency>
</dependencies>

<build>
   <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.3.2</version>
      <configuration>
        <mainClass>com.example.cassandra.Client</mainClass>
      </configuration>
    </plugin>
     <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
     </plugins>
   </build>
  </project>

I reffered this link

Then i tried

 telnet 172.17.1.XX 9160

 Trying 172.17.1.XX...
 Connected to 172.17.1.XX.
 Escape character is '^]'.

If i type something, it says connection closed by foreign agent

 netstat -plten 

on 172.17.1.XX

shows 

 tcp        0      0 127.0.0.1:8984          0.0.0.0:*               LISTEN      0          73148094    19145/java
 tcp        0      0 127.0.0.1:7000          0.0.0.0:*               LISTEN      0          73148635    19145/java
 tcp        0      0 0.0.0.0:7199            0.0.0.0:*               LISTEN      0          73148631    19145/java
 tcp        0      0 0.0.0.0:50370           0.0.0.0:*               LISTEN      0          73148632    19145/java
 tcp        0      0 0.0.0.0:9160            0.0.0.0:*               LISTEN      0          73148104    19145/java
 tcp        0      0 0.0.0.0:33935           0.0.0.0:*               LISTEN      0          73148630    19145/java
 tcp        0      0 0.0.0.0:9042            0.0.0.0:*               LISTEN      0          73148103    19145/java
 tcp        0      0 0.0.0.0:8983            0.0.0.0:*               LISTEN      0          73148083    19145/java

So how do i solve this issue? Any solutions?


Answer:

You're connecting to the wrong port: Java Driver connects to the Native Port (usually 9042) and not the Thrift Port (usually 9160). Change this line

cluster = Cluster.builder().addContactPoint(node).withPort(9042).build();

Question:

Whenever I try to build any maven project or generate some archetype, I get this error:

[ERROR] Error executing Maven.
[ERROR] java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException
[ERROR] Caused by: com/google/inject/internal/cglib/core/$CodeGenerationException
[ERROR] Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException

Maven used to work ok just yesterday, and don't remember changing anything in its' configurations lately. I use jdk8 oracle and jdk7 openjdk on Ubuntu 14.04 (I switch between 2 javas from time to time using Ubuntu's update-alternative --config javac).

If I run

mvn -B archetype:generate   -DarchetypeGroupId=org.apache.maven.archetypes   -DgroupId=com.mycompany.app   -DartifactId=my-app -X

I get this output:

username@pcname:~/Desktop/projects/mvn_simple$ mvn -B archetype:generate   -DarchetypeGroupId=org.apache.maven.archetypes   -DgroupId=com.mycompany.app   -DartifactId=my-app -X
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-40-generic", arch: "amd64", family: "unix"
[ERROR] Error executing Maven.
com.google.common.collect.ComputationException: java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException
    at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:890)
    at com.google.inject.internal.FailableCache.get(FailableCache.java:49)
    at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
    at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:127)
    at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:530)
    at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run(AbstractBindingProcessor.java:179)
    at com.google.inject.internal.ProcessedBindingData.initializeBindings(ProcessedBindingData.java:44)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:123)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
    at com.google.inject.Guice.createInjector(Guice.java:96)
    at com.google.inject.Guice.createInjector(Guice.java:73)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
    at org.apache.maven.cli.MavenCli.container(MavenCli.java:375)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:191)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException
    at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:156)
    at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
    at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
    at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:38)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:356)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:182)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:151)
    at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:67)
    at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:886)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.internal.cglib.core.$CodeGenerationException
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
    ... 36 more

Answer:

Restarting PC solved the problem :)

Question:

I am using Ubuntu Linux 15.10. A few days ago I cloned a small git project which is using Maven (I use version 3.3.3). After cloning I wanted to use the

mvn install

command to download all dependencies but an error occurred. Using the same command with the -X parameter shows the problem in detail:

[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.3: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.3 from/to central (https://repo.maven.apache.org/maven2): java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext): Invalid keystore format -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.maven.plugins:maven-resources-plugin:2.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.3
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:117)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(DefaultMavenPluginManager.java:179)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor(DefaultMavenPluginManager.java:298)
at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor(DefaultBuildPluginManager.java:241)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.setupMojoExecution(DefaultLifecycleExecutionPlanCalculator.java:169)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.setupMojoExecutions(DefaultLifecycleExecutionPlanCalculator.java:155)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.calculateExecutionPlan(DefaultLifecycleExecutionPlanCalculator.java:131)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.calculateExecutionPlan(DefaultLifecycleExecutionPlanCalculator.java:145)
at org.apache.maven.lifecycle.internal.builder.BuilderCommon.resolveBuildPlan(BuilderCommon.java:96)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:109)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.3
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:302)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:218)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:287)
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:103)
... 26 more
....
...
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:658)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:56)
at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:225)
at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:70)
at java.security.KeyStore.load(KeyStore.java:1445)
at sun.security.ssl.TrustManagerFactoryImpl.getCacertsKeyStore(TrustManagerFactoryImpl.java:226)
at sun.security.ssl.SSLContextImpl$DefaultSSLContext.getDefaultTrustManager(SSLContextImpl.java:767)
at sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:733)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.security.Provider$Service.newInstance(Provider.java:1595)
... 83 more

I checked if my JAVA_HOME (/usr/lib/jvm/java-8-openjdk-amd64/) is set correctly and deleted my ~/.keystore file. I generated a new one with the keytool -genkey command. Afterwards I reinstalled ca-certificates-java and ca-certificates. But nothing helps.

If I use the command

sudo update-ca-certificates

I get the following error:

org.debian.security.InvalidKeystorePasswordException: Cannot open Java keystore. Is the password correct?
at org.debian.security.KeyStoreHandler.load(KeyStoreHandler.java:68)
at org.debian.security.KeyStoreHandler.<init>(KeyStoreHandler.java:52)
at org.debian.security.UpdateCertificates.<init>(UpdateCertificates.java:65)
at org.debian.security.UpdateCertificates.main(UpdateCertificates.java:51)
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:650)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
at java.security.KeyStore.load(KeyStore.java:1226)
at org.debian.security.KeyStoreHandler.load(KeyStoreHandler.java:66)
... 3 more

It seems that there is an general problem with the keystore on my linux system. Maven install for this projects works on others systems.

Could anybody help me fixing this problem?

Many thanks.


Answer:

I fixed the issue with by purging and reinstalling ca-certificates-java using the following commands:

sudo dpkg --purge --force-depends ca-certificates-java
sudo apt-get install ca-certificates-java

Maybe this could help anybody in a similar situation.

Question:

I am trying to build my java application and getting compilation error as below :

[ERROR] /media/disk2/myapp/assignment/src/main/java/helper/HelperFunctions.java:[29,16] error: generics are not supported in -source 1.3

But java i am using is 1.7 version, I am using ubuntu14.04 on my mechine. Any idea how to solve this.

java -version
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

Answer:

Add the below tag in your pom.xml

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <!-- or whatever version you use -->
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

Question:

As someone who has been programming in node.js for a while, finding a specific class has been tough and documentation online has been confusing for someone like me who hasn't had much experience with package dependency in Java.

First off, this is the command I am trying to run

mvn exec:java -Dexec.mainClass="gifClass"

I put a file called gifClass.java (with the class name being gifClass) in both the highest part of the project directory and the src folder. Nevertheless, I get a classNotFoundException: gifClass

Can anyone help me coming from node.js? Thanks!


Answer:

Put your java source files into src/main/java directory (this is the root directory for Java sources, use subdirectories for Java packages).

See https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

Question:

Apologies if my question is a duplicate of any other items previously mentioned here .

I have the following configuration :

Ubuntu 14.04 64 bit JDK 1.8u45 Maven v3.3

I am trying to package my code into a deployable war.

The war gets created succesfully , but on accessing it on my browser , I am running into Unsupported major.minor version 52.0 errors.

On Googling around I saw that this is due to a mismatch in installed JDK and the maven-compiler level.

But in my case , both are the same. -> JDK 1.8 and maven-compiler version 3.3 with source and target 1.8.

What can I do to get my build to compile successfully ?

Outputs of some helpful commands :

mvn -v

root@labuser-OptiPlex-3010:/# mvn -v 
Maven home: /usr/local/apache-maven-3.3.3 
Java version: 1.8.0_45, vendor: Oracle Corporation 
Java home: /usr/local/jdk1.8.0_45/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "linux", version: "3.16.0-43-generic", arch: "amd64", family: "unix" 

Answer:

Since you mentioned you can successfully create the war with maven, it sounds like JDK 8 is being used as expected during the build. The problem is your server is apparently running using an older version of Java. Although you only installed JDK 8 yourself, you must have already had an older version of Java on your computer. Make sure JAVA_HOME is set to JDK 8 and that your server sees that version properly. See if you have a JRE_HOME env variable set as well, and point it to JDK 8 as well.